Ticket #4973: 4973_3.patch

File 4973_3.patch, 9.3 KB (added by Garry Yao, 14 years ago)
  • _source/core/resourcemanager.js

     
    127127                var external = this.externals[ name ];
    128128                return CKEDITOR.getUrl(
    129129                                this.getPath( name ) +
    130                                 ( ( external && external.file ) || ( this.fileName + '.js' ) ) );
     130                                ( ( external && external.file != null ) ? external.file : this.fileName + '.js' ) );
    131131        },
    132132
    133133        /**
     
    136136         * @param {String} names The resource names, separated by commas.
    137137         * @param {String} path The path of the folder containing the resource.
    138138         * @param {String} [fileName] The resource file name. If not provided, the
    139          *              default name is used.
     139         *              default name is used; If provided with a empty string, will implicitly indicates that {@param path}
     140         *              is already the full path.
    140141         * @example
    141142         * // Loads a plugin from '/myplugin/samples/plugin.js'.
    142143         * CKEDITOR.plugins.addExternal( 'sample', '/myplugins/sample/' );
    143144         * @example
    144145         * // Loads a plugin from '/myplugin/samples/my_plugin.js'.
    145146         * CKEDITOR.plugins.addExternal( 'sample', '/myplugins/sample/', 'my_plugin.js' );
     147         * @example
     148         * // Loads a plugin from '/myplugin/samples/my_plugin.js'.
     149         * CKEDITOR.plugins.addExternal( 'sample', '/myplugins/sample/my_plugin.js', '' );
    146150         */
    147151        addExternal : function( names, path, fileName )
    148152        {
  • _source/plugins/div/dialogs/div.js

     
    259259                        return groups;
    260260                }
    261261
     262                // Synchronous field values to other impacted fields is required, e.g. div styles
     263                // change should also alter inline-style text.
     264                function commitInternally( targetFields )
     265                {
     266                        var dialog = this.getDialog(),
     267                                 element = dialog._element && dialog._element.clone()
     268                                                 || new CKEDITOR.dom.element( 'div', editor.document );
     269
     270                        // Commit this field and broadcast to target fields.
     271                        this.commit( element, true );
     272
     273                        targetFields = [].concat( targetFields );
     274                        var length = targetFields.length, field;
     275                        for ( var i = 0; i < length; i++ )
     276                        {
     277                                field = dialog.getContentElement.apply( dialog, targetFields[ i ].split( ':' ) );
     278                                field && field.setup && field.setup( element, true );
     279                        }
     280                }
     281
     282
     283                // Registered 'CKEDITOR.style' instances.
     284                var styles = {} ;
    262285                /**
    263286                 * Hold a collection of created block container elements.
    264287                 */
     
    289312                                                                style :'width: 100%;',
    290313                                                                label :editor.lang.div.styleSelectLabel,
    291314                                                                'default' : '',
    292                                                                 items : [],
     315                                                                // Options are loaded dynamically.
     316                                                                items :
     317                                                                [
     318                                                                        [ editor.lang.common.notSet , '' ]
     319                                                                ],
     320                                                                onChange : function()
     321                                                                {
     322                                                                        commitInternally.call( this, [ 'info:class', 'advanced:dir', 'advanced:style' ] );
     323                                                                },
    293324                                                                setup : function( element )
    294325                                                                {
    295                                                                         this.setValue( element.$.style.cssText || '' );
     326                                                                        for ( var name in styles )
     327                                                                                styles[ name ].checkElementRemovable( element, true ) && this.setValue( name );
    296328                                                                },
    297329                                                                commit: function( element )
    298330                                                                {
    299                                                                         if ( this.getValue() )
    300                                                                                 element.$.style.cssText = this.getValue();
    301                                                                         else
    302                                                                                 element.removeAttribute( 'style' );
     331                                                                        var styleName;
     332                                                                        if ( styleName = this.getValue() )
     333                                                                                styles[ styleName ].applyToObject( element )
    303334                                                                }
    304335                                                        },
    305336                                                        {
     
    351382                                                                                        id :'style',
    352383                                                                                        style :'width: 100%;',
    353384                                                                                        label :editor.lang.common.cssStyle,
    354                                                                                         'default' : ''
     385                                                                                        'default' : '',
     386                                                                                        commit : function( element )
     387                                                                                        {
     388                                                                                                // Merge with 'elementStyle', which is of higher priority.
     389                                                                                                var value = this.getValue(),
     390                                                                                                                merged = [ value, element.getAttribute( 'style' ) ].join( ';' );
     391                                                                                                value && element.setAttribute( 'style', merged );
     392                                                                                        }
    355393                                                                                }
    356394                                                                ]
    357395                                                        },
     
    376414                                                                'default' : '',
    377415                                                                items :
    378416                                                                [
     417                                                                        [ editor.lang.common.notSet , '' ],
    379418                                                                        [
    380419                                                                                editor.lang.common.langDirLtr,
    381420                                                                                'ltr'
     
    394433                        onLoad : function()
    395434                        {
    396435                                setupFields.call(this);
     436
     437                                // Preparing for the 'elementStyle' field.
     438                                var dialog = this,
     439                                         stylesField = this.getContentElement( 'info', 'elementStyle' ),
     440                                         // Reuse the 'stylescombo' plugin's styles definition.
     441                                         customStylesConfig =  editor.config.stylesCombo_stylesSet,
     442                                         stylesSetName = customStylesConfig && customStylesConfig.split( ':' )[ 0 ];
     443                               
     444                                if( stylesSetName )
     445                                {
     446                                        CKEDITOR.stylesSet.load( stylesSetName,
     447                                                function( stylesSet )
     448                                                {
     449                                                        var stylesDefinitions = stylesSet[ stylesSetName ],
     450                                                                styleName;
     451
     452                                                        if ( stylesDefinitions )
     453                                                        {
     454                                                                // Digg only those styles that apply to 'div'.
     455                                                                for ( var i = 0 ; i < stylesDefinitions.length ; i++ )
     456                                                                {
     457                                                                        var styleDefinition = stylesDefinitions[ i ];
     458                                                                        if( styleDefinition.element && styleDefinition.element == 'div' )
     459                                                                        {
     460                                                                                styleName = styleDefinition.name;
     461                                                                                styles[ styleName ] = new CKEDITOR.style( styleDefinition );
     462
     463                                                                                // Populate the styles field options with style name.
     464                                                                                stylesField.items.push( [ styleName, styleName ] );
     465                                                                                stylesField.add( styleName, styleName );
     466                                                                        }
     467                                                                }
     468                                                        }
     469
     470                                                        var fieldBox =  stylesField.getElement().getParent();
     471
     472                                                        // We should disable the content element
     473                                                        // it if no options are available at all.
     474                                                        stylesField.items.length ?
     475                                                                fieldBox.removeStyle( 'display' )  :
     476                                                                fieldBox.setStyle( 'display', 'none' );
     477
     478                                                        // Now setup the field value manually.
     479                                                        setTimeout( function() { stylesField.setup( dialog._element ); }, 0 );
     480                                                } );
     481                                }
    397482                        },
    398483                        onShow : function()
    399484                        {
     
    416501                                        containers = createDiv( editor, true );
    417502
    418503                                // Update elements attributes
    419                                 for( var i = 0 ; i < containers.length ; i++ )
     504                                var size = containers.length;
     505                                for ( var i = 0; i < size; i++ )
     506                                {
    420507                                        this.commitContent( containers[ i ] );
     508
     509                                        // Remove empty 'style' attribute.
     510                                        !containers[ i ].getAttribute( 'style' ) && containers[ i ].removeAttribute( 'style' );
     511                                }
     512
    421513                                this.hide();
    422514                        }
    423515                };
  • _source/plugins/stylescombo/plugin.js

     
    1616                                pluginPath = this.path,
    1717                                styles;
    1818
     19                        var stylesSet = config.stylesCombo_stylesSet.split( ':' ),
     20                                styleSetName = stylesSet[ 0 ],
     21                                externalPath = stylesSet[ 1 ];
     22
     23                        CKEDITOR.stylesSet.addExternal( styleSetName,
     24                                        externalPath ?
     25                                                stylesSet.slice( 1 ).join( ':' ) :
     26                                                pluginPath + 'styles/' + styleSetName + '.js', '' );
     27
    1928                        editor.ui.addRichCombo( 'Styles',
    2029                                {
    2130                                        label : lang.label,
     
    3241
    3342                                        init : function()
    3443                                        {
    35                                                 var combo = this,
    36                                                         stylesSet = config.stylesCombo_stylesSet.split( ':' );
     44                                                var combo = this;
    3745
    38                                                 var stylesSetPath = stylesSet[ 1 ] ?
    39                                                                 stylesSet.slice( 1 ).join( ':' ) :              // #4481
    40                                                                 CKEDITOR.getUrl( pluginPath + 'styles/' + stylesSet[ 0 ] + '.js' ) ;
    41 
    42                                                 stylesSet = stylesSet[ 0 ];
    43 
    44                                                 CKEDITOR.loadStylesSet( stylesSet, stylesSetPath, function( stylesDefinitions )
     46                                                CKEDITOR.stylesSet.load( styleSetName, function( stylesSet )
    4547                                                        {
    46                                                                 var style,
     48                                                                var stylesDefinitions = stylesSet[ styleSetName ],
     49                                                                        style,
    4750                                                                        styleName,
    4851                                                                        stylesList = [];
    4952
     
    207210                }
    208211        });
    209212
    210         var stylesSets = {};
     213        var stylesSet = (CKEDITOR.stylesSet = new CKEDITOR.resourceManager( '', 'stylesSet' ) );
    211214
    212         CKEDITOR.addStylesSet = function( name, styles )
    213         {
    214                 stylesSets[ name ] = styles;
    215         };
    216 
     215        // Backward compatibilities (#5025).
     216        CKEDITOR.addStylesSet = CKEDITOR.tools.bind( stylesSet.add, stylesSet );
    217217        CKEDITOR.loadStylesSet = function( name, url, callback )
    218         {
    219                 var stylesSet = stylesSets[ name ];
    220 
    221                 if ( stylesSet )
    222218                {
    223                         callback( stylesSet );
    224                         return ;
    225                 }
    226 
    227                 CKEDITOR.scriptLoader.load( url, function()
    228                         {
    229                                 callback( stylesSets[ name ] );
    230                         });
    231         };
    232 
     219                        stylesSet.addExternal( name, url, '' );
     220                        CKEDITOR.stylesSet.load( name, callback );
     221                };
     222       
    233223        function buildPreview( styleDefinition )
    234224        {
    235225                var html = [];
  • _source/plugins/stylescombo/styles/default.js

     
    1 /*
     1/*
    22Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
    33For licensing, see LICENSE.html or http://ckeditor.com/license
    44*/
    55
    6 CKEDITOR.addStylesSet( 'default',
     6CKEDITOR.stylesSet.add( 'default',
    77[
    88        /* Block Styles */
    99
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy