Ticket #4056: 4056_3.patch

File 4056_3.patch, 4.5 KB (added by Minh Nguyen, 14 years ago)

For hiddenfield

  • _source/plugins/forms/dialogs/hiddenfield.js

     
    66{
    77        return {
    88                title : editor.lang.hidden.title,
     9                hiddenField : null,
    910                minWidth : 350,
    1011                minHeight : 110,
    1112                onShow : function()
    1213                {
    1314                        delete this.hiddenField;
    1415
    15                         var element = this.getParentEditor().getSelection().getSelectedElement();
    16                         if ( element && element.getName() == "input" && element.getAttribute( 'type' ) == "checkbox" )
    17                         {
    18                                 this.hiddenField = element;
     16                        var editor = this.getParentEditor(),
     17                        selection = editor.getSelection(),
     18                        element = selection.getSelectedElement();
     19                                 
     20                if ( element && element.getAttribute( '_cke_real_element_type' ) && element.getAttribute( '_cke_real_element_type' ) == 'hiddenfield' )
     21            {
     22                                this.hiddenField = element;
     23                                element = editor.restoreRealElement( this.hiddenField );
    1924                                this.setupContent( element );
    20                         }
     25                                selection.selectElement( this.hiddenField );
     26                }
    2127                },
    2228                onOk : function()
    2329                {
    24                         var editor,
    25                                 element = this.hiddenField,
    26                                 isInsertMode = !element;
     30                        var name = this.getValueOf( 'info', '_cke_saved_name' ),
     31                                value = this.getValueOf( 'info', 'value' ),
     32                                editor = this.getParentEditor(),
     33                                element = CKEDITOR.env.ie ?
     34                                        editor.document.createElement( '<input name="' + CKEDITOR.tools.htmlEncode( name ) + '">' ) :
     35                                                editor.document.createElement( 'input' );
    2736
    28                         if ( isInsertMode )
    29                         {
    30                                 editor = this.getParentEditor();
    31                                 element = editor.document.createElement( 'input' );
    32                                 element.setAttribute( 'type', 'hidden' );
    33                         }
    34 
    35                         if ( isInsertMode )
    36                                 editor.insertElement( element );
     37                        element.setAttribute( 'type', 'hidden' );
    3738                        this.commitContent( element );
     39                        var fakeElement = editor.createFakeElement( element, 'cke_hidden', 'hiddenfield' );
     40                       
     41                        if ( !this.hiddenField )
     42                                editor.insertElement( fakeElement );
     43                        else
     44                        {
     45                                fakeElement.replace( this.hiddenField );
     46                                editor.getSelection().selectElement( fakeElement );
     47            }
     48                       
     49                        return true;
    3850                },
    3951                contents : [
    4052                        {
     
    5062                                                accessKey : 'N',
    5163                                                setup : function( element )
    5264                                                {
     65                                                       
    5366                                                        this.setValue(
    5467                                                                        element.getAttribute( '_cke_saved_name' ) ||
    5568                                                                        element.getAttribute( 'name' ) ||
     
    5871                                                commit : function( element )
    5972                                                {
    6073                                                        if ( this.getValue() )
    61                                                                 element.setAttribute( '_cke_saved_name', this.getValue() );
     74                                                                element.setAttribute( 'name', this.getValue() );
    6275                                                        else
    6376                                                        {
    64                                                                 element.removeAttribute( '_cke_saved_name' );
    6577                                                                element.removeAttribute( 'name' );
    6678                                                        }
    6779                                                }
  • _source/plugins/forms/plugin.js

     
    1818                        '{' +
    1919                                'border: 1px dotted #FF0000;' +
    2020                                'padding: 2px;' +
    21                         '}' );
     21                        '}\n' );
     22                       
     23                editor.addCss(
     24                        'img.cke_hidden' +
     25                        '{' +
     26                                'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/hiddenfield.gif' ) + ');' +
     27                                'background-position: center center;' +
     28                                'background-repeat: no-repeat;' +
     29                                'border: 1px solid #a9a9a9;' +
     30                                'width: 16px;' +
     31                                'height: 16px;' +
     32                        '}' ); 
    2233
    2334                // All buttons use the same code to register. So, to avoid
    2435                // duplications, let's use this tool function.
     
    165176
    166177        afterInit : function( editor )
    167178        {
     179                var dataProcessor = editor.dataProcessor,
     180                                htmlFilter = dataProcessor && dataProcessor.htmlFilter,
     181                                dataFilter = dataProcessor && dataProcessor.dataFilter;
     182                               
    168183                // Cleanup certain IE form elements default values.
    169184                if ( CKEDITOR.env.ie )
    170185                {
     
    185200                                }
    186201                        } );
    187202                }
     203               
     204                if ( dataFilter )
     205                {
     206                        dataFilter.addRules(
     207                        {
     208                                elements :
     209                                {
     210                                        input : function( element )
     211                                        {
     212                                                if ( element.attributes.type == 'hidden' ) {
     213                                                                return editor.createFakeParserElement( element, 'cke_hidden', 'hiddenfield' );
     214                                                }
     215                                        }
     216                                }
     217                        } );
     218                }
    188219        },
    189         requires : [ 'image' ]
     220       
     221        requires : [ 'image', 'fakeobjects' ]
    190222} );
    191223
    192224if ( CKEDITOR.env.ie )
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy