Ticket #5418: 5418_4.patch

File 5418_4.patch, 8.5 KB (added by Tobiasz Cudnik, 14 years ago)
  • _source/plugins/table/dialogs/table.js

     
    2020        {
    2121                var makeElement = function( name ){ return new CKEDITOR.dom.element( name, editor.document ); };
    2222
     23                var commitInternally = editor.plugins.dialogadvtab.commitInternally;
     24
    2325                return {
    2426                        title : editor.lang.table.title,
    2527                        minWidth : 310,
     
    392394                                                                                                                inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) );
    393395                                                                                                        },
    394396
     397                                                                                                        onChange : function()
     398                                                                                                        {
     399                                                                                                                commitInternally.call( this, [ 'advanced:advStyles' ] );
     400                                                                                                        },
     401
    395402                                                                                                        setup : function( selectedTable )
    396403                                                                                                        {
    397404                                                                                                                var widthMatch = widthPattern.exec( selectedTable.$.style.width );
     
    447454                                                                                                                inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) );
    448455                                                                                                        },
    449456
     457                                                                                                        onChange : function()
     458                                                                                                        {
     459                                                                                                                commitInternally.call( this, [ 'advanced:advStyles' ] );
     460                                                                                                        },
     461
    450462                                                                                                        setup : function( selectedTable )
    451463                                                                                                        {
    452464                                                                                                                var heightMatch = heightPattern.exec( selectedTable.$.style.height );
     
    580592                                                        ]
    581593                                                }
    582594                                        ]
    583                                 }
     595                                },
     596                                editor.plugins.dialogadvtab.createAdvancedTab( editor )
    584597                        ]
    585598                };
    586599        }
  • _source/lang/en.js

     
    105105                targetTop               : 'Topmost Window (_top)',
    106106                targetSelf              : 'Same Window (_self)',
    107107                targetParent    : 'Parent Window (_parent)',
     108                advanced        : 'Advanced',
     109                langDirLTR              : 'Left to Right (LTR)',
     110                langDirRTL              : 'Right to Left (RTL)',
     111                styles                  : 'Style',
     112                cssClasses              : 'Stylesheet Classes',
    108113
    109114                // Put the voice-only part of the label in the span.
    110115                unavailable             : '%1<span class="cke_accessibility">, unavailable</span>'
  • _source/plugins/dialogadvtab/plugin.js

     
     1/*
     2Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
     3For licensing, see LICENSE.html or http://ckeditor.com/license
     4*/
     5(function()
     6{
     7       
     8var advParamsMap = {
     9        'advLangDir' : 'dir',
     10        'advCSSClasses' : 'class',
     11        'advStyles' : 'style',
     12        'advId' : 'id'
     13};
     14
     15var setupAdvParams = function( element )
     16{
     17        var attrName = advParamsMap[ this.id ];
     18
     19        // Try to get existing value first in case of inChange commit.
     20        var value = this.getValue() || element && element.hasAttribute( attrName ) && element.getAttribute( attrName ) || '';
     21
     22        // Compatibility with showborders plugin.
     23        if ( attrName == 'class' )
     24                value = value.replace( /cke_show_border/g, '' );
     25        else if ( attrName == 'style' )
     26        {
     27                // Inherit width value from width field.
     28                var widthField = this.getDialog().getContentElement( 'info', 'txtWidth');
     29                var widthFieldValue = widthField.getValue();
     30
     31                if ( widthFieldValue )
     32                {
     33                        var widthUnit = this.getDialog().getContentElement( 'info', 'cmbWidthType').getValue();
     34                        widthUnit = widthUnit == 'percents' ? '%' : 'px';
     35
     36                        widthFieldValue = 'width: ' + widthFieldValue + widthUnit + ';';
     37                        if ( value )
     38                                value = value.replace( /\s*width: .+?;\s*/, '' );
     39                        value = value ? value + '; ' + widthFieldValue : widthFieldValue;
     40                }
     41                else
     42                        value = value.replace( /\s*width: .+?;\s*/, '' );
     43
     44                // Inherit height value from height field.
     45                var heightField = this.getDialog().getContentElement( 'info', 'txtHeight');
     46                var heightFieldValue = heightField.getValue();
     47                if ( heightFieldValue )
     48                {
     49                        heightFieldValue = 'height: ' + heightFieldValue + 'px;';
     50                        if ( value )
     51                                value = value.replace( /\s*height: .+?;\s*/, '' );
     52                        value = value ? value + '; ' + heightFieldValue : heightFieldValue;
     53                }
     54                else
     55                        value = value.replace( /\s*height: .+?;\s*/, '' );
     56
     57                if ( value )
     58                        value = value.replace( /\s*;\s*;\s*/g, ';' );
     59        }
     60
     61        if ( value !== undefined )
     62                this.setValue( value )
     63};
     64
     65var commitAdvParams = function( data, element )
     66{
     67        element = data instanceof CKEDITOR.dom.element ? data : element;
     68
     69        var value = this.getValue();
     70        if ( value )
     71        {
     72                var attrName = advParamsMap[ this.id ];
     73
     74                // Compatibility with showborders plugin.
     75                if ( attrName == 'style' )
     76                {
     77                        this._elementStyleRead = 0;
     78                }
     79                else if ( attrName == 'class' && this._.dialog._.editor.plugins.showborders )
     80                                value += ' cke_show_border';
     81
     82                if ( element )
     83                        element.setAttribute( attrName, value );
     84        }
     85        else
     86                element.removeAttribute( attrName, value );
     87};
     88
     89CKEDITOR.plugins.add( 'dialogadvtab',
     90{
     91        // Synchronous field values to other impacted fields is required, e.g. div styles
     92        // change should also alter inline-style text.
     93        commitInternally: function( targetFields )
     94        {
     95                var dialog = this.getDialog(),
     96                        element = dialog._.selectedElement;
     97
     98                // Commit this field and broadcast to target fields.
     99                //                      this.commit( element, true );
     100
     101                targetFields = [].concat( targetFields );
     102                var length = targetFields.length, field;
     103                for ( var i = 0; i < length; i++ )
     104                {
     105                        field = dialog.getContentElement.apply( dialog, targetFields[ i ].split( ':' ) );
     106                        field && field.setup && field.setup( element, true );
     107                }
     108        },
     109
     110        /**
     111         *
     112         * @param tabConfig
     113         * id, dir, classes, styles
     114         */
     115        createAdvancedTab : function( editor, tabConfig )
     116        {
     117                if ( tabConfig === undefined )
     118                {
     119                        tabConfig = { id:1, dir:1, classes:1, styles:1 };
     120                }
     121
     122                var lang = editor.lang.common;
     123
     124                var result =
     125                {
     126                        id : 'advanced',
     127                        label : lang.advanced,
     128                        title : lang.advanced,
     129                        elements :
     130                                [
     131                                        {
     132                                                type : 'vbox',
     133                                                padding : 1,
     134                                                children : []
     135                                        }
     136                                ]
     137                };
     138
     139                var content = [];
     140
     141                if ( tabConfig.id || tabConfig.dir )
     142                {
     143                        if ( tabConfig.id )
     144                        {
     145                                content.push(
     146                                        {
     147                                                type : 'text',
     148                                                id : 'advId',
     149                                                label : lang.id,
     150                                                setup : setupAdvParams,
     151                                                commit : commitAdvParams
     152                                        });
     153                        }
     154
     155                        if ( tabConfig.dir )
     156                        {
     157                                content.push(
     158                                        {
     159                                                type : 'select',
     160                                                id : 'advLangDir',
     161                                                label : lang.langDir,
     162                                                'default' : '',
     163                                                style : 'width:110px',
     164                                                items :
     165                                                [
     166                                                        [ lang.notSet, '' ],
     167                                                        [ lang.langDirLTR, 'ltr' ],
     168                                                        [ lang.langDirRTL, 'rtl' ]
     169                                                ],
     170                                                setup : setupAdvParams,
     171                                                commit : commitAdvParams
     172                                        });
     173                        }
     174
     175                        result.elements[ 0 ].children.push(
     176                                {
     177                                        type : 'hbox',
     178                                        widths : [ '50%', '50%' ],
     179                                        children : [].concat( content )
     180                                });
     181                }
     182
     183                if ( tabConfig.styles || tabConfig.classes )
     184                {
     185                        content = [];
     186
     187                        if ( tabConfig.id )
     188                        {
     189                                content.push(
     190                                        {
     191                                                type : 'text',
     192                                                label : lang.styles,
     193                                                'default' : '',
     194                                                id : 'advStyles',
     195                                                onChange : function()
     196                                                {
     197                                                        // Transaction prevents from recursive calls to onChange() of this field.
     198                                                        if ( this._duringTransaction )
     199                                                                return;
     200
     201                                                        this._duringTransaction = 1;
     202
     203                                                        var value = this.getValue(),
     204                                                                dialog = this.getDialog(),
     205                                                                match;
     206
     207                                                        // Synchronize width value.
     208                                                        match = value.match( /width\s*:\s*(\d+)(px|%)/ );
     209                                                        if ( match )
     210                                                        {
     211                                                                dialog.getContentElement( 'info', 'txtWidth' ).setValue( match[ 1 ] );
     212                                                                dialog.getContentElement( 'info', 'cmbWidthType' ).setValue(
     213                                                                        match[ 2 ] == 'px' ? 'pixels' : 'percents'
     214                                                                );
     215                                                        }
     216
     217                                                        // Synchronize height value.
     218                                                        match = value.match( /height\s*:\s*(\d+)(px|%)/ );
     219                                                        if ( match )
     220                                                        {
     221                                                                dialog.getContentElement( 'info', 'txtHeight' ).setValue( match[ 1 ] );
     222                                                        }
     223
     224                                                        this._duringTransaction = 0;
     225                                                },
     226                                                setup : setupAdvParams,
     227                                                commit : commitAdvParams
     228
     229                                        });
     230                        }
     231
     232                        if ( tabConfig.classes )
     233                        {
     234                                content.push(
     235                                        {
     236                                                type : 'hbox',
     237                                                widths : [ '45%', '55%' ],
     238                                                children :
     239                                                [
     240                                                        {
     241                                                                type : 'text',
     242                                                                label : lang.cssClasses,
     243                                                                'default' : '',
     244                                                                id : 'advCSSClasses',
     245                                                                setup : setupAdvParams,
     246                                                                commit : commitAdvParams
     247
     248                                                        }
     249                                                ]
     250                                        });
     251                        }
     252
     253                        result.elements[ 0 ].children.push(
     254                                {
     255                                        type : 'hbox',
     256                                        widths : [ '50%', '50%' ],
     257                                        children : [].concat( content )
     258                                });
     259                }
     260
     261                return result;
     262        }
     263});
     264
     265})();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy