[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/libraries/ckeditor/_source/plugins/forms/dialogs/ -> checkbox.js (source)

   1  /*

   2  Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.

   3  For licensing, see LICENSE.html or http://ckeditor.com/license

   4  */
   5  CKEDITOR.dialog.add( 'checkbox', function( editor )
   6  {
   7      return {
   8          title : editor.lang.checkboxAndRadio.checkboxTitle,
   9          minWidth : 350,
  10          minHeight : 140,
  11          onShow : function()
  12          {
  13              delete this.checkbox;
  14  
  15              var element = this.getParentEditor().getSelection().getSelectedElement();
  16  
  17              if ( element && element.getAttribute( 'type' ) == "checkbox" )
  18              {
  19                  this.checkbox = element;
  20                  this.setupContent( element );
  21              }
  22          },
  23          onOk : function()
  24          {
  25              var editor,
  26                  element = this.checkbox,
  27                  isInsertMode = !element;
  28  
  29              if ( isInsertMode )
  30              {
  31                  editor = this.getParentEditor();
  32                  element = editor.document.createElement( 'input' );
  33                  element.setAttribute( 'type', 'checkbox' );
  34              }
  35  
  36              if ( isInsertMode )
  37                  editor.insertElement( element );
  38              this.commitContent( { element : element } );
  39          },
  40          contents : [
  41              {
  42                  id : 'info',
  43                  label : editor.lang.checkboxAndRadio.checkboxTitle,
  44                  title : editor.lang.checkboxAndRadio.checkboxTitle,
  45                  startupFocus : 'txtName',
  46                  elements : [
  47                      {
  48                          id : 'txtName',
  49                          type : 'text',
  50                          label : editor.lang.common.name,
  51                          'default' : '',
  52                          accessKey : 'N',
  53                          setup : function( element )
  54                          {
  55                              this.setValue(
  56                                      element.getAttribute( '_cke_saved_name' ) ||
  57                                      element.getAttribute( 'name' ) ||
  58                                      '' );
  59                          },
  60                          commit : function( data )
  61                          {
  62                              var element = data.element;
  63  
  64                              // IE failed to update 'name' property on input elements, protect it now.

  65                              if ( this.getValue() )
  66                                  element.setAttribute( '_cke_saved_name', this.getValue() );
  67                              else
  68                              {
  69                                  element.removeAttribute( '_cke_saved_name' );
  70                                  element.removeAttribute( 'name' );
  71                              }
  72                          }
  73                      },
  74                      {
  75                          id : 'txtValue',
  76                          type : 'text',
  77                          label : editor.lang.checkboxAndRadio.value,
  78                          'default' : '',
  79                          accessKey : 'V',
  80                          setup : function( element )
  81                          {
  82                              var value = element.getAttribute( 'value' );
  83                              // IE Return 'on' as default attr value.

  84                              this.setValue(  CKEDITOR.env.ie && value == 'on' ? '' : value  );
  85                          },
  86                          commit : function( data )
  87                          {
  88                              var element = data.element,
  89                                  value = this.getValue();
  90  
  91                              if ( value && !( CKEDITOR.env.ie && value == 'on' ) )
  92                                  element.setAttribute( 'value', value );
  93                              else
  94                              {
  95                                  if ( CKEDITOR.env.ie )
  96                                  {
  97                                      // Remove attribute 'value' of checkbox #4721.

  98                                      var checkbox = new CKEDITOR.dom.element( 'input', element.getDocument() );
  99                                      element.copyAttributes( checkbox, { value: 1 } );
 100                                      checkbox.replace( element );
 101                                      editor.getSelection().selectElement( checkbox );
 102                                      data.element = checkbox;
 103                                  }
 104                                  else
 105                                      element.removeAttribute( 'value' );
 106                              }
 107                          }
 108                      },
 109                      {
 110                          id : 'cmbSelected',
 111                          type : 'checkbox',
 112                          label : editor.lang.checkboxAndRadio.selected,
 113                          'default' : '',
 114                          accessKey : 'S',
 115                          value : "checked",
 116                          setup : function( element )
 117                          {
 118                              this.setValue( element.getAttribute( 'checked' ) );
 119                          },
 120                          commit : function( data )
 121                          {
 122                              var element = data.element;
 123  
 124                              if ( CKEDITOR.env.ie )
 125                              {
 126                                  var isElementChecked = !!element.getAttribute( 'checked' );
 127                                  var isChecked = !!this.getValue();
 128  
 129                                  if ( isElementChecked != isChecked )
 130                                  {
 131                                      var replace = CKEDITOR.dom.element.createFromHtml( '<input type="checkbox"'
 132                                             + ( isChecked ? ' checked="checked"' : '' )
 133                                             + '/>', editor.document );
 134  
 135                                      element.copyAttributes( replace, { type : 1, checked : 1 } );
 136                                      replace.replace( element );
 137                                      editor.getSelection().selectElement( replace );
 138                                      data.element = replace;
 139                                  }
 140                              }
 141                              else
 142                              {
 143                                  var value = this.getValue();
 144                                  if ( value )
 145                                      element.setAttribute( 'checked', 'checked' );
 146                                  else
 147                                      element.removeAttribute( 'checked' );
 148                              }
 149                          }
 150                      }
 151                  ]
 152              }
 153          ]
 154      };
 155  });


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7