Ticket #2820: 2820.patch

File 2820.patch, 31.2 KB (added by Artur Formella, 15 years ago)
  • button.js

     
    44*/
    55CKEDITOR.dialog.add( 'button', function( editor )
    66{
    7         var addChange = function( name, input ){
    8                 var dialog = input.getDialog();
    9                 if ( input.isChanged() || ( dialog.editMode == false && input.getValue() != '' ))
    10                 {
    11                         dialog.changedAttibutes[ name ] = input.getValue();
    12                         return true;
    13                 }
    14                 return false;
    15         };
    16 
    17         // Function called in onShow to load selected element.
    18         var loadSelection = function( editor, selection, ranges, element ){
    19                 // Read attributes.
    20                 var type = element.getAttribute( 'type' );
    21                 var name = element.getAttribute( 'name' );
    22                 var value = element.getAttribute( 'value' );
    23 
    24                 // Fill out all fields.
    25                 this.setValueOf( 'info', 'txtName', name );
    26                 this.setValueOf( 'info', 'txtValue', value );
    27                 this.setValueOf( 'info', 'txtType', type );
    28 
    29                 this.saveSelection();
    30                 this.editMode = true;
    31                 this.editObj = element;
    32 
    33                 return false;
    34         };
    35 
    367        return {
    378                title : editor.lang.button.title,
    38                 resizable : CKEDITOR.DIALOG_RESIZE_NONE,
    399                minWidth : 400,
    4010                minHeight : 230,
    4111                onShow : function()
    4212                {
    43                         // Default: create a new element.
    44                         this.editMode = false;
    45 
    46                         // IE BUG: Selection must be in the editor for getSelection() to work.
     13                        // IE BUG: Selection must be in the editor for getSelectedElement()
     14                        // to work.
    4715                        this.restoreSelection();
    4816
    49                         var editor = this.getParentEditor(),
    50                                 selection = editor.getSelection(),
    51                                 ranges = selection.getRanges();
    52 
    53                         // Check selection. Fill in all the relevant fields if there's already one link selected.
    54                         if ( ranges.length == 1 )
     17                        var element = this.getParentEditor().getSelection().getSelectedElement();
     18                        if ( element && element.getName() == "input" )
    5519                        {
    56                                 ranges[0].enlarge( CKEDITOR.ENLARGE_ELEMENT );
    57 
    58                                 var rangeRoot = ranges[0].getCommonAncestor( true );
    59                                 var element = rangeRoot.getAscendant( 'input', true );
    60                                 if ( element && element.getAttribute( 'type' ) )
     20                                var type = element.getAttribute( 'type' );
     21                                if ( type == "button" || type == "reset" || type == "submit" )
    6122                                {
    62                                         var type = element.getAttribute( 'type' );
    63                                         if ( type == "button" || type == "reset" || type == "submit" )
    64                                         {
    65                                                 loadSelection.apply( this, [ editor, selection, ranges, element ] );
    66                                                 selection.selectElement( element );
    67                                         }
     23                                        this._element = element;
     24                                        this.setupContent( element );
    6825                                }
    6926                        }
    7027
    71                         if ( this.editMode == false )   //New object.
    72                                 this.editObj = editor.document.createElement( 'input' );
    7328                        this.getContentElement( 'info', 'txtName' ).focus();
    74 
    75                         this.changedAttibutes = new Array();
    7629                },
    7730                onOk : function()
    7831                {
    79                         this.editObj.setAttributes( this.changedAttibutes );
     32                        var editor,
     33                                element = this._element,
     34                                isInsertMode = !element;
    8035
    81                         if ( this.editMode == false )
     36                        if ( isInsertMode )
    8237                        {
     38                                editor = this.getParentEditor();
     39                                element = editor.document.createElement( 'input' );
     40                        }
     41                        this.commitContent( element );
     42
     43                        if ( isInsertMode )
     44                        {
    8345                                this.restoreSelection();
    8446                                this.clearSavedSelection();
    85                                 editor.insertElement( this.editObj );
     47                                editor.insertElement( element );
    8648                        }
    87                         return true;
    8849                },
    8950                contents : [
    9051                        {
     
    9859                                                type : 'text',
    9960                                                label : editor.lang.common.name,
    10061                                                'default' : '',
    101                                                 validate: function()
     62                                                setup : function( element )
    10263                                                {
    103                                                         addChange( 'name', this );
    104                                                         return true;
     64                                                        this.setValue( element.getAttribute( 'name' ) );
     65                                                },
     66                                                commit : function( element )
     67                                                {
     68                                                        element.setAttribute( 'name', this.getValue() );
    10569                                                }
    10670                                        },
    10771                                        {
     
    11074                                                label : editor.lang.button.text,
    11175                                                accessKey : 'V',
    11276                                                'default' : '',
    113                                                 validate: function()
     77                                                setup : function( element )
    11478                                                {
    115                                                         addChange( 'value', this );
    116                                                         return true;
     79                                                        this.setValue( element.getAttribute( 'value' ) );
     80                                                },
     81                                                commit : function( element )
     82                                                {
     83                                                        element.setAttribute( 'value', this.getValue() );
    11784                                                }
    11885                                        },
    11986                                        {
     
    12895                                                        [ editor.lang.button.typeSbm, 'submit' ],
    12996                                                        [ editor.lang.button.typeRst, 'reset' ]
    13097                                                ],
    131                                                 validate: function()
     98                                                setup : function( element )
    13299                                                {
    133                                                         addChange( 'type', this );
    134                                                         return true;
     100                                                        this.setValue( element.getAttribute( 'type' ) );
     101                                                },
     102                                                commit : function( element )
     103                                                {
     104                                                        element.setAttribute( 'type', this.getValue() );
    135105                                                }
    136106                                        }
    137107                                ]
  • form.js

     
    44*/
    55CKEDITOR.dialog.add( 'form', function( editor )
    66{
    7         var addChange = function( name, input ){
    8                 var dialog = input.getDialog();
    9                 if ( input.isChanged() || ( dialog.editMode == false && input.getValue() != '' ))
    10                 {
    11                         dialog.changedAttibutes[ name ] = input.getValue();
    12                         return true;
    13                 }
    14                 return false;
    15         };
    16 
    17         // Function called in onShow to load selected element.
    18         var loadSelection = function( editor, selection, ranges, element )
    19         {
    20                 this.saveSelection();
    21                 this.editObj = element;
    22                 this.editMode = true;
    23 
    24                 // Fill out all fields.
    25                 readAttribute.apply( this, [ this.editObj, 'info', 'name', 'txtName', true ] );
    26                 readAttribute.apply( this, [ this.editObj, 'info', 'action', 'txtAction', true ] );
    27                 readAttribute.apply( this, [ this.editObj, 'info', 'method', 'cmbMethod', true ] );
    28                 readAttribute.apply( this, [ this.editObj, 'info', 'encoding', 'cmbEncoding', true ] );
    29                 readAttribute.apply( this, [ this.editObj, 'info', 'target', 'cmbTarget', true ] );
    30                 readAttribute.apply( this, [ this.editObj, 'info', 'id', 'txtId', true ] );
    31 
    32                 return false;
    33         };
    34 
    35         var readAttribute = function( object, page, attribute, input, setIfNull )
    36         {
    37                 var attributeValue = object.getAttribute( attribute );
    38                 if ( attributeValue == null )
    39                         if ( setIfNull )
    40                                 this.setValueOf( page, input, "" );
    41                 else
    42                         this.setValueOf( page, input, attributeValue );
    43                 return attributeValue;
    44         }
    45 
    467        return {
    478                title : editor.lang.form.title,
    48                 resizable : CKEDITOR.DIALOG_RESIZE_NONE,
    499                minWidth : 400,
    5010                minHeight : 270,
    51                 onOk : function()
     11                onShow : function()
    5212                {
    53                         this.editObj.setAttributes( this.changedAttibutes );
     13                        // IE BUG: Selection must be in the editor for getSelectedElement()
     14                        // to work.
     15                        this.restoreSelection();
    5416
    55                         if ( this.editMode == false )
     17                        var element = this.getParentEditor().getSelection().getSelectedElement();
     18                        if ( element && element.getName() == "form" )
    5619                        {
    57                                 this.restoreSelection();
    58                                 this.clearSavedSelection();
    59                                 editor.insertElement( this.editObj );
     20                                this._element = element;
     21                                this.setupContent( element );
    6022                        }
    61                         return true;
     23
     24                        this.getContentElement( 'info', 'txtName' ).focus();
    6225                },
    63                 onShow : function()
     26                onOk : function()
    6427                {
    65                         // Default: create a new element.
    66                         this.editMode = false;
    67                         this.changedAttibutes = new Array();
     28                        var editor,
     29                                element = this._element,
     30                                isInsertMode = !element;
    6831
    69                         // IE BUG: Selection must be in the editor for getSelection() to work.
    70                         this.restoreSelection();
    71 
    72                         var editor = this.getParentEditor(),
    73                                 selection = editor.getSelection(),
    74                                 ranges = selection.getRanges();
    75 
    76                         // Check selection. Fill in all the relevant fields if there's already one link selected.
    77                         if ( ranges.length == 1 )
     32                        if ( isInsertMode )
    7833                        {
    79                                 ranges[0].enlarge( CKEDITOR.ENLARGE_ELEMENT );
    80 
    81                                 var rangeRoot = ranges[0].getCommonAncestor( true );
    82                                 var element = rangeRoot.getAscendant( 'form', true );
    83                                 if ( element )
    84                                 {
    85                                         loadSelection.apply( this, [ editor, selection, ranges, element ] );
    86                                         selection.selectElement( element );
    87                                 }
     34                                editor = this.getParentEditor();
     35                                element = editor.document.createElement( 'form' );
    8836                        }
     37                        this.commitContent( element );
    8938
    90                         if( this.editMode == false )
    91                                 this.editObj = editor.document.createElement( 'form' );
    92 
    93                         this.getContentElement( 'info', 'txtName' ).focus();
     39                        if ( isInsertMode )
     40                        {
     41                                this.restoreSelection();
     42                                this.clearSavedSelection();
     43                                editor.insertElement( element );
     44                        }
    9445                },
    9546                contents : [
    9647                        {
     
    10556                                                label : editor.lang.common.name,
    10657                                                'default' : '',
    10758                                                accessKey : 'N',
    108                                                 validate: function()
     59                                                setup : function( element )
    10960                                                {
    110                                                         addChange( 'name', this );
    111                                                         return true;
     61                                                        this.setValue( element.getAttribute( 'name' ) );
     62                                                },
     63                                                commit : function( element )
     64                                                {
     65                                                        element.setAttribute( 'name', this.getValue() );
    11266                                                }
    11367                                        },
    11468                                        {
     
    11771                                                label : editor.lang.form.action,
    11872                                                'default' : editor.config.forms.defaultValues.formAction,
    11973                                                accessKey : 'A',
    120                                                 validate: function()
     74                                                setup : function( element )
    12175                                                {
    122                                                         addChange( 'action', this );
    123                                                         return true;
     76                                                        this.setValue( element.getAttribute( 'action' ) );
     77                                                },
     78                                                commit : function( element )
     79                                                {
     80                                                        element.setAttribute( 'action', this.getValue() );
    12481                                                }
    12582                                        },
    12683                                        {
     
    13491                                                                label : editor.lang.common.id,
    13592                                                                'default' : '',
    13693                                                                accessKey : 'I',
    137                                                                 validate: function()
     94                                                                setup : function( element )
    13895                                                                {
    139                                                                         addChange( 'id', this );
    140                                                                         return true;
     96                                                                        this.setValue( element.getAttribute( 'id' ) );
     97                                                                },
     98                                                                commit : function( element )
     99                                                                {
     100                                                                        element.setAttribute( 'id', this.getValue() );
    141101                                                                }
    142102                                                        },
    143103                                                        {
     
    153113                                                                        [ 'multipart/form-data' ],
    154114                                                                        [ 'application/x-www-form-urlencoded' ]
    155115                                                                ],
    156                                                                 validate: function()
     116                                                                setup : function( element )
    157117                                                                {
    158                                                                         addChange( 'encoding', this );
    159                                                                         return true;
     118                                                                        this.setValue( element.getAttribute( 'encoding' ) );
     119                                                                },
     120                                                                commit : function( element )
     121                                                                {
     122                                                                        element.setAttribute( 'encoding', this.getValue() );
    160123                                                                }
    161124                                                        }
    162125                                                ]
     
    181144                                                                        [ editor.lang.form.targetSelf, '_self' ],
    182145                                                                        [ editor.lang.form.targetParent, '_parent' ]
    183146                                                                ],
    184                                                                 validate: function()
     147                                                                setup : function( element )
    185148                                                                {
    186                                                                         addChange( 'target', this );
    187                                                                         return true;
     149                                                                        this.setValue( element.getAttribute( 'target' ) );
     150                                                                },
     151                                                                commit : function( element )
     152                                                                {
     153                                                                        element.setAttribute( 'target', this.getValue() );
    188154                                                                }
    189155                                                        },
    190156                                                        {
     
    198164                                                                        [ 'GET', 'get' ],
    199165                                                                        [ 'POST', 'post' ]
    200166                                                                ],
    201                                                                 validate: function()
     167                                                                setup : function( element )
    202168                                                                {
    203                                                                         addChange( 'method', this );
    204                                                                         return true;
     169                                                                        this.setValue( element.getAttribute( 'method' ) );
     170                                                                },
     171                                                                commit : function( element )
     172                                                                {
     173                                                                        element.setAttribute( 'method', this.getValue() );
    205174                                                                }
    206175                                                        }
    207176                                                ]
  • hiddenfield.js

     
    44*/
    55CKEDITOR.dialog.add( 'hiddenfield', function( editor )
    66{
    7         var addChange = function( name, input ){
    8                 var dialog = input.getDialog();
    9                 if ( input.isChanged() || ( dialog.editMode == false && input.getValue() != '' ))
    10                 {
    11                         dialog.changedAttibutes[ name ] = input.getValue();
    12                         return true;
    13                 }
    14                 return false;
    15         };
    16 
    17         // Function called in onShow to load selected element.
    18         var loadSelection = function( editor, selection, ranges, element )
    19         {
    20                 this.saveSelection();
    21                 this.editObj = element;
    22                 this.editMode = true;
    23 
    24                 // Fill out all fields.
    25                 var name = element.getAttribute( 'name' );
    26                 var value = element.getAttribute( 'value' );
    27 
    28                 this.setValueOf( 'info', 'txtName', name );
    29                 this.setValueOf( 'info', 'txtValue', value );
    30 
    31                 return false;
    32         };
    337        return {
    348                title : editor.lang.hidden.title,
    35                 resizable : CKEDITOR.DIALOG_RESIZE_NONE,
    369                minWidth : 400,
    3710                minHeight : 200,
    3811                onShow : function()
    3912                {
    40                         // Default: create a new element.
    41                         this.editMode = false;
    42                         this.changedAttibutes = new Array();
    43 
    44                         // IE BUG: Selection must be in the editor for getSelection() to work.
     13                        // IE BUG: Selection must be in the editor for getSelectedElement()
     14                        // to work.
    4515                        this.restoreSelection();
    4616
    47                         var editor = this.getParentEditor(),
    48                                 selection = editor.getSelection(),
    49                                 ranges = selection.getRanges();
    50 
    51                         // Check selection. Fill in all the relevant fields if there's already one link selected.
    52                         if ( ranges.length == 1 )
     17                        var element = this.getParentEditor().getSelection().getSelectedElement();
     18                        if ( element && element.getName() == "input" && element.getAttribute( 'type' ) == "checkbox" )
    5319                        {
    54                                 ranges[0].enlarge( CKEDITOR.ENLARGE_ELEMENT );
    55 
    56                                 var rangeRoot = ranges[0].getCommonAncestor( true );
    57                                 var element = rangeRoot.getAscendant( 'input', true );
    58                                 if ( element && element.getAttribute( 'type' ) == "hidden" )
    59                                 {
    60                                         loadSelection.apply( this, [ editor, selection, ranges, element ] );
    61                                         selection.selectElement( element );
    62                                 }
     20                                this._element = element;
     21                                this.setupContent( element );
    6322                        }
    6423
    65                         if( this.editMode == false )    //New object.
    66                                 this.editObj = editor.document.createElement( 'input' );
    67 
    6824                        this.getContentElement( 'info', 'txtName' ).focus();
    6925                },
    7026                onOk : function()
    7127                {
    72                         this.changedAttibutes[ 'type' ] = 'hidden';
    73                         this.editObj.setAttributes( this.changedAttibutes );
     28                        var editor,
     29                                element = this._element,
     30                                isInsertMode = !element;
    7431
    75                         if ( this.editMode == false )
     32                        if ( isInsertMode )
    7633                        {
     34                                editor = this.getParentEditor();
     35                                element = editor.document.createElement( 'input' );
     36                                element.setAttribute( 'type', 'hidden' );
     37                        }
     38                        this.commitContent( element );
     39
     40                        if ( isInsertMode )
     41                        {
    7742                                this.restoreSelection();
    7843                                this.clearSavedSelection();
    79                                 editor.insertElement( this.editObj );
     44                                editor.insertElement( element );
    8045                        }
    81                         return true;
    8246                },
    8347                contents : [
    8448                        {
     
    9357                                                label : editor.lang.hidden.name,
    9458                                                'default' : '',
    9559                                                accessKey : 'N',
    96                                                 validate: function()
     60                                                setup : function( element )
    9761                                                {
    98                                                         addChange( 'name', this );
    99                                                         return true;
     62                                                        this.setValue( element.getAttribute( 'name' ) );
     63                                                },
     64                                                commit : function( element )
     65                                                {
     66                                                        element.setAttribute( 'name', this.getValue() );
    10067                                                }
    10168                                        },
    10269                                        {
     
    10572                                                label : editor.lang.hidden.value,
    10673                                                'default' : '',
    10774                                                accessKey : 'V',
    108                                                 validate: function()
     75                                                setup : function( element )
    10976                                                {
    110                                                         addChange( 'value', this );
    111                                                         return true;
     77                                                        this.setValue( element.getAttribute( 'value' ) );
     78                                                },
     79                                                commit : function( element )
     80                                                {
     81                                                        element.setAttribute( 'value', this.getValue() );
    11282                                                }
    11383                                        }
    11484                                ]
  • radio.js

     
    44*/
    55CKEDITOR.dialog.add( 'radio', function( editor )
    66{
    7         var addChange = function( name, input ){
    8                 var dialog = input.getDialog();
    9                 if ( input.isChanged() || ( dialog.editMode == false && input.getValue() != '' ))
    10                 {
    11                         dialog.changedAttibutes[ name ] = input.getValue();
    12                         return true;
    13                 }
    14                 return false;
    15         };
    16 
    17         // Function called in onShow to load selected element.
    18         var loadSelection = function( editor, selection, ranges, element )
    19         {
    20                 this.saveSelection();
    21                 this.editObj = element;
    22                 this.editMode = true;
    23 
    24                 // Read attributes.
    25                 var checked = element.getAttribute( 'checked' );
    26                 var name = element.getAttribute( 'name' );
    27                 var value = element.getAttribute( 'value' );
    28 
    29                 // Fill out all fields.
    30                 this.setValueOf( 'info', 'txtName', name );
    31                 this.setValueOf( 'info', 'txtValue', value );
    32                 this.setValueOf( 'info', 'cmbSelected', checked );
    33 
    34                 return false;
    35         };
    367        return {
    378                title : editor.lang.checkboxAndRadio.radioTitle,
    38                 resizable : CKEDITOR.DIALOG_RESIZE_NONE,
    399                minWidth : 400,
    4010                minHeight : 200,
    4111                onShow : function()
    4212                {
    43                         // Default: create a new element.
    44                         this.editMode = false;
    45                         this.changedAttibutes = new Array();
    46 
    47                         // IE BUG: Selection must be in the editor for getSelection() to work.
     13                        // IE BUG: Selection must be in the editor for getSelectedElement()
     14                        // to work.
    4815                        this.restoreSelection();
    4916
    50                         var editor = this.getParentEditor(),
    51                                 selection = editor.getSelection(),
    52                                 ranges = selection.getRanges();
    53 
    54                         // Check selection. Fill in all the relevant fields if there's already one link selected.
    55                         if ( ranges.length == 1 )
     17                        var element = this.getParentEditor().getSelection().getSelectedElement();
     18                        if ( element && element.getName() == "input" && element.getAttribute( 'type' ) == "radio" )
    5619                        {
    57                                 ranges[0].enlarge( CKEDITOR.ENLARGE_ELEMENT );
    58 
    59                                 var rangeRoot = ranges[0].getCommonAncestor( true );
    60                                 var element = rangeRoot.getAscendant( 'input', true );
    61                                 if ( element && element.getAttribute( 'type' ) == "radio" )
    62                                 {
    63                                         loadSelection.apply( this, [ editor, selection, ranges, element ] );
    64                                         selection.selectElement( element );
    65                                 }
     20                                this._element = element;
     21                                this.setupContent( element );
    6622                        }
    6723
    68                         if( this.editMode == false )    //New object.
    69                                 this.editObj = editor.document.createElement( 'input' );
    70 
    7124                        this.getContentElement( 'info', 'txtName' ).focus();
    7225                },
    7326                onOk : function()
    7427                {
    75                         this.changedAttibutes[ 'type' ] = 'radio';
     28                        var editor,
     29                                element = this._element,
     30                                isInsertMode = !element;
    7631
    77                         this.editObj.setAttributes( this.changedAttibutes );
     32                        if ( isInsertMode )
     33                        {
     34                                editor = this.getParentEditor();
     35                                element = editor.document.createElement( 'input' );
     36                                element.setAttribute( 'type', 'radio' );
     37                        }
     38                        this.commitContent( element );
    7839
    79                         if ( this.editMode == false )
     40                        if ( isInsertMode )
    8041                        {
    81                                 // It doesn't work with IE.
    8242                                this.restoreSelection();
    8343                                this.clearSavedSelection();
    84                                 editor.insertElement( this.editObj );
     44                                editor.insertElement( element );
    8545                        }
    86                         return true;
    8746                },
    8847                contents : [
    8948                        {
     
    9857                                                label : editor.lang.common.name,
    9958                                                'default' : '',
    10059                                                accessKey : 'N',
    101                                                 validate: function()
     60                                                setup : function( element )
    10261                                                {
    103                                                         addChange( 'name', this );
    104                                                         return true;
     62                                                        this.setValue( element.getAttribute( 'name' ) );
     63                                                },
     64                                                commit : function( element )
     65                                                {
     66                                                        element.setAttribute( 'name', this.getValue() );
    10567                                                }
    10668                                        },
    10769                                        {
     
    11072                                                label : editor.lang.checkboxAndRadio.value,
    11173                                                'default' : '',
    11274                                                accessKey : 'V',
    113                                                 validate: function()
     75                                                setup : function( element )
    11476                                                {
    115                                                         addChange( 'value', this );
    116                                                         return true;
     77                                                        this.setValue( element.getAttribute( 'value' ) );
     78                                                },
     79                                                commit : function( element )
     80                                                {
     81                                                        element.setAttribute( 'value', this.getValue() );
    11782                                                }
    11883                                        },
    11984                                        {
     
    12186                                                type : 'checkbox',
    12287                                                label : editor.lang.checkboxAndRadio.selected,
    12388                                                'default' : '',
    124                                                 accessKey : 'S',
     89                                                accessKey : 'S',
    12590                                                value : "checked",
    126                                                 validate: function()
     91                                                setup : function( element )
    12792                                                {
    128                                                         addChange( 'checked', this );
    129                                                         return true;
    130                                                 }
     93                                                        this.setValue( element.getAttribute( 'checked' ) );
     94                                                },
     95                                                commit : function( element )
     96                                                {
     97                                                        element.setAttribute( 'checked', this.getValue() );
     98                                                }
     99
    131100                                        }
    132101                                ]
    133102                        }
  • textarea.js

     
    44*/
    55CKEDITOR.dialog.add( 'textarea', function( editor )
    66{
    7         var addChange = function( name, input ){
    8                 var dialog = input.getDialog();
    9                 if ( input.isChanged() || ( dialog.editMode == false && input.getValue() != '' ))
    10                 {
    11                         dialog.changedAttibutes[ name ] = input.getValue();
    12                         return true;
    13                 }
    14                 return false;
    15         };
    16 
    17         // Function called in onShow to load selected element.
    18         var loadSelection = function( editor, selection, ranges, element )
    19         {
    20                 this.saveSelection();
    21                 this.editObj = element;
    22                 this.editMode = true;
    23 
    24                 // Fill out all fields.
    25                 readAttribute.apply( this, [ 'info', 'name', 'txtName' ] );
    26                 readAttribute.apply( this, [ 'info', 'cols', 'txtColumns' ] );
    27                 readAttribute.apply( this, [ 'info', 'rows', 'txtRows' ] );
    28 
    29                 return false;
    30         };
    31 
    32         var readAttribute = function( page, attribute, input )
    33         {
    34                 var attributeValue = this.editObj.getAttribute( attribute );
    35                 this.setValueOf( page, input, attributeValue );
    36 
    37                 return attributeValue;
    38         }
    39 
    407        return {
    418                title : editor.lang.textarea.title,
    42                 resizable : CKEDITOR.DIALOG_RESIZE_NONE,
    439                minWidth : 400,
    4410                minHeight : 230,
    4511                onShow : function()
    4612                {
    47                         // Default: create a new element.
    48                         this.editMode = false;
    49 
    50                         // IE BUG: Selection must be in the editor for getSelection() to work.
     13                        // IE BUG: Selection must be in the editor for getSelectedElement()
     14                        // to work.
    5115                        this.restoreSelection();
    5216
    53                         var editor = this.getParentEditor(),
    54                                 selection = editor.getSelection(),
    55                                 ranges = selection.getRanges();
    56 
    57                         // Check selection. Fill in all the relevant fields if there's already one link selected.
    58                         if ( ranges.length == 1 )
     17                        var element = this.getParentEditor().getSelection().getSelectedElement();
     18                        if ( element && element.getName() == "textarea" )
    5919                        {
    60                                 ranges[0].enlarge( CKEDITOR.ENLARGE_ELEMENT );
    61 
    62                                 var rangeRoot = ranges[0].getCommonAncestor( true );
    63                                 var element = rangeRoot.getAscendant( 'textarea', true );
    64                                 if ( element )
    65                                 {
    66                                         loadSelection.apply( this, [ editor, selection, ranges, element ] );
    67                                         selection.selectElement( element );
    68                                 }
     20                                this._element = element;
     21                                this.setupContent( element );
    6922                        }
    7023
    71                         if ( this.editMode == false )   //New object.
    72                                 this.editObj = editor.document.createElement( 'textarea' );
    73 
    7424                        this.getContentElement( 'info', 'txtName' ).focus();
    75                         this.changedAttibutes = new Array();
    7625                },
    7726                onOk : function()
    7827                {
    79                         this.editObj.setAttributes( this.changedAttibutes );
     28                        var editor,
     29                                element = this._element,
     30                                isInsertMode = !element;
    8031
    81                         if ( this.editMode == false )
     32                        if ( isInsertMode )
    8233                        {
     34                                editor = this.getParentEditor();
     35                                element = editor.document.createElement( 'textarea' );
     36                        }
     37                        this.commitContent( element );
     38
     39                        if ( isInsertMode )
     40                        {
    8341                                this.restoreSelection();
    8442                                this.clearSavedSelection();
    85                                 editor.insertElement( this.editObj );
     43                                editor.insertElement( element );
    8644                        }
    87                         return true;
    8845                },
    8946                contents : [
    9047                        {
     
    9956                                                label : editor.lang.common.name,
    10057                                                'default' : '',
    10158                                                accessKey : 'N',
    102                                                 validate: function()
     59                                                setup : function( element )
    10360                                                {
    104                                                         addChange( 'name', this );
    105                                                         return true;
     61                                                        this.setValue( element.getAttribute( 'name' ) );
     62                                                },
     63                                                commit : function( element )
     64                                                {
     65                                                        element.setAttribute( 'name', this.getValue() );
    10666                                                }
    10767                                        },
    10868                                        {
     
    11575                                                validate: function()
    11676                                                {
    11777                                                        var func = CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed );
    118                                                         var isValid = func.apply( this );
    119                                                         if ( isValid )
    120                                                                 addChange( 'cols', this );
    121                                                         return isValid;
     78                                                        return func.apply( this );
     79                                                },
     80                                                setup : function( element )
     81                                                {
     82                                                        this.setValue( element.getAttribute( 'cols' ) );
     83                                                },
     84                                                commit : function( element )
     85                                                {
     86                                                        element.setAttribute( 'cols', this.getValue() );
    12287                                                }
    12388                                        },
    12489                                        {
     
    13196                                                validate: function()
    13297                                                {
    13398                                                        var func = CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed );
    134                                                         var isValid = func.apply( this );
    135                                                         if ( isValid )
    136                                                                 addChange( 'rows', this );
    137                                                         return isValid;
     99                                                        return func.apply( this );
     100                                                },
     101                                                setup : function( element )
     102                                                {
     103                                                        this.setValue( element.getAttribute( 'rows' ) );
     104                                                },
     105                                                commit : function( element )
     106                                                {
     107                                                        element.setAttribute( 'rows', this.getValue() );
    138108                                                }
    139109                                        }
    140110                                ]
  • textfield.js

     
    44*/
    55CKEDITOR.dialog.add( 'textfield', function( editor )
    66{
    7         var addChange = function( name, input ){
    8                 var dialog = input.getDialog();
    9                 if ( input.isChanged() || ( dialog.editMode == false && input.getValue() != '' ))
    10                 {
    11                         dialog.changedAttibutes[ name ] = input.getValue();
    12                         return true;
    13                 }
    14                 return false;
    15         };
    16 
    17         // Function called in onShow to load selected element.
    18         var loadSelection = function( editor, selection, ranges, element )
    19         {
    20                 this.saveSelection();
    21                 this.editObj = element;
    22                 this.editMode = true;
    23 
    24                 // Fill out all fields.
    25                 readAttribute.apply( this, [ 'info', 'name', 'txtName' ] );
    26                 readAttribute.apply( this, [ 'info', 'value', 'txtValue' ] );
    27                 readAttribute.apply( this, [ 'info', 'type', 'cmbType' ] );
    28                 readAttribute.apply( this, [ 'info', 'width', 'txtTextCharWidth' ] );
    29                 readAttribute.apply( this, [ 'info', 'maxlength', 'txtMaxChars' ] );
    30 
    31                 return false;
    32         };
    33 
    34         var readAttribute = function( page, attribute, input )
    35         {
    36                 var attributeValue = this.editObj.getAttribute( attribute );
    37                 this.setValueOf( page, input, attributeValue );
    38 
    39                 return attributeValue;
    40         }
    417        return {
    428                title : editor.lang.textfield.title,
    43                 resizable : CKEDITOR.DIALOG_RESIZE_NONE,
    449                minWidth : 400,
    4510                minHeight : 230,
    46 
    4711                onShow : function()
    4812                {
    49                         // Default: create a new element.
    50                         this.editMode = false;
    51 
    52                         // IE BUG: Selection must be in the editor for getSelection() to work.
     13                        // IE BUG: Selection must be in the editor for getSelectedElement()
     14                        // to work.
    5315                        this.restoreSelection();
    5416
    55                         var editor = this.getParentEditor(),
    56                                 selection = editor.getSelection(),
    57                                 ranges = selection.getRanges();
    58 
    59                         // Check selection. Fill in all the relevant fields if there's already one link selected.
    60                         if ( ranges.length == 1 )
     17                        var element = this.getParentEditor().getSelection().getSelectedElement();
     18                        if ( element && element.getName() == "input" && ( element.getAttribute( 'type' ) == "text" && !element.getAttribute( 'type' ) ) )
    6119                        {
    62                                 ranges[0].enlarge( CKEDITOR.ENLARGE_ELEMENT );
    63 
    64                                 var rangeRoot = ranges[0].getCommonAncestor( true );
    65                                 var element = rangeRoot.getAscendant( 'input', true );
    66                                 if ( element )
    67                                 {
    68                                         var type = element.getAttribute( 'type' );
    69                                         if ( type == "text" || type == null )
    70                                         {
    71                                                 loadSelection.apply( this, [ editor, selection, ranges, element ] );
    72                                                 selection.selectElement( element );
    73                                         }
    74                                 }
     20                                this._element = element;
     21                                this.setupContent( element );
    7522                        }
    7623
    77                         if ( this.editMode == false )   //New object.
    78                                 this.editObj = editor.document.createElement( 'input' );
    79 
    8024                        this.getContentElement( 'info', 'txtName' ).focus();
    81                         this.changedAttibutes = new Array();
    8225                },
    8326                onOk : function()
    8427                {
    85                         this.editObj.setAttributes( this.changedAttibutes );
     28                        var editor,
     29                                element = this._element,
     30                                isInsertMode = !element;
    8631
    87                         if ( this.editMode == false )
     32                        if ( isInsertMode )
    8833                        {
     34                                editor = this.getParentEditor();
     35                                element = editor.document.createElement( 'textarea' );
     36                                element.setAttribute( 'type', 'text' );
     37                        }
     38                        this.commitContent( element );
     39
     40                        if ( isInsertMode )
     41                        {
    8942                                this.restoreSelection();
    9043                                this.clearSavedSelection();
    91                                 editor.insertElement( this.editObj );
     44                                editor.insertElement( element );
    9245                        }
    93                         return true;
    9446                },
    9547                contents : [
    9648                        {
     
    11062                                                                label : editor.lang.textfield.name,
    11163                                                                'default' : '',
    11264                                                                accessKey : 'N',
    113                                                                 validate: function()
     65                                                                setup : function( element )
    11466                                                                {
    115                                                                         addChange( 'name', this );
    116                                                                         return true;
     67                                                                        this.setValue( element.getAttribute( 'name' ) );
     68                                                                },
     69                                                                commit : function( element )
     70                                                                {
     71                                                                        element.setAttribute( 'name', this.getValue() );
    11772                                                                }
    11873                                                        },
    11974                                                        {
     
    12277                                                                label : editor.lang.textfield.value,
    12378                                                                'default' : '',
    12479                                                                accessKey : 'V',
    125                                                                 validate: function()
     80                                                                setup : function( element )
    12681                                                                {
    127                                                                         addChange( 'value', this );
    128                                                                         return true;
     82                                                                        this.setValue( element.getAttribute( 'value' ) );
     83                                                                },
     84                                                                commit : function( element )
     85                                                                {
     86                                                                        element.setAttribute( 'value', this.getValue() );
    12987                                                                }
    13088                                                        }
    13189                                                ]
     
    145103                                                                validate: function()
    146104                                                                {
    147105                                                                        var func = CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed );
    148                                                                         var isValid = func.apply( this );
    149                                                                         if ( isValid )
    150                                                                                 addChange( 'width', this );
    151                                                                         return isValid;
     106                                                                        return isValid = func.apply( this );
     107                                                                },
     108                                                                setup : function( element )
     109                                                                {
     110                                                                        this.setValue( element.getAttribute( 'value' ) );
     111                                                                },
     112                                                                commit : function( element )
     113                                                                {
     114                                                                        element.setAttribute( 'value', this.getValue() );
    152115                                                                }
    153116                                                        },
    154117                                                        {
     
    161124                                                                validate: function()
    162125                                                                {
    163126                                                                        var func = CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed );
    164                                                                         var isValid = func.apply( this );
    165                                                                         if ( isValid )
    166                                                                                 addChange( 'maxlength', this );
    167                                                                         return isValid;
     127                                                                        return isValid = func.apply( this );
     128                                                                },
     129                                                                setup : function( element )
     130                                                                {
     131                                                                        this.setValue( element.getAttribute( 'maxlength' ) );
     132                                                                },
     133                                                                commit : function( element )
     134                                                                {
     135                                                                        element.setAttribute( 'maxlength', this.getValue() );
    168136                                                                }
    169137                                                        }
    170138                                                ]
     
    180148                                                        [ editor.lang.textfield.typeText, 'text' ],
    181149                                                        [ editor.lang.textfield.typePass, 'pass' ],
    182150                                                ],
    183                                                 validate: function()
     151                                                setup : function( element )
    184152                                                {
    185                                                         addChange( 'type', this );
    186                                                         return true;
     153                                                        this.setValue( element.getAttribute( 'type' ) );
     154                                                },
     155                                                commit : function( element )
     156                                                {
     157                                                        element.setAttribute( 'type', this.getValue() );
    187158                                                }
    188159                                        }
    189160                                ]
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy