Ticket #4973: 4973_2.patch

File 4973_2.patch, 7.8 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/stylescombo/plugin.js

     
    3232
    3333                                        init : function()
    3434                                        {
    35                                                 var combo = this,
    36                                                         stylesSet = config.stylesCombo_stylesSet.split( ':' );
     35                                                var combo = this;
    3736
    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 )
     37                                                CKEDITOR.stylesSet.load( styleSetName, function( stylesSet )
    4538                                                        {
    46                                                                 var style,
     39                                                                var stylesDefinitions = stylesSet[ styleSetName ],
     40                                                                        style,
    4741                                                                        styleName,
    4842                                                                        stylesList = [];
    4943
     
    204198                                                        this.hideGroup( lang[ 'panelTitle' + String( CKEDITOR.STYLE_OBJECT ) ] );
    205199                                        }
    206200                                });
    207                 }
    208         });
    209201
    210         var stylesSets = {};
     202                        var stylesSet = config.stylesCombo_stylesSet.split( ':' ),
     203                                styleSetName = stylesSet[ 0 ],
     204                                externalPath = stylesSet[ 1 ];
    211205
    212         CKEDITOR.addStylesSet = function( name, styles )
    213         {
    214                 stylesSets[ name ] = styles;
    215         };
     206                        CKEDITOR.stylesSet.addExternal( styleSetName,
     207                                        externalPath ? stylesSet.slice( 1 ).join( ':' ) : pluginPath + 'styles/',
     208                                        externalPath ? '' : styleSetName + '.js' );
    216209
    217         CKEDITOR.loadStylesSet = function( name, url, callback )
    218         {
    219                 var stylesSet = stylesSets[ name ];
    220 
    221                 if ( stylesSet )
    222                 {
    223                         callback( stylesSet );
    224                         return ;
    225210                }
    226 
    227                 CKEDITOR.scriptLoader.load( url, function()
    228                         {
    229                                 callback( stylesSets[ name ] );
    230                         });
    231         };
     211        });
    232212
     213        // Custom stylesSets as global resources.
     214        CKEDITOR.stylesSet = new CKEDITOR.resourceManager( '', 'stylesSet' );
     215       
    233216        function buildPreview( styleDefinition )
    234217        {
    235218                var html = [];
  • _source/plugins/stylescombo/styles/default.js

     
    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
  • _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 = new CKEDITOR.dom.element( 'div' );
     268
     269                        // Commit this field and broadcast to target fields.
     270                        this.commit( element, true );
     271
     272                        targetFields = [].concat( targetFields );
     273                        var length = targetFields.length, field;
     274                        for ( var i = 0; i < length; i++ )
     275                        {
     276                                field = dialog.getContentElement.apply( dialog, targetFields[ i ].split( ':' ) );
     277                                field && field.setup && field.setup( element, true );
     278                        }
     279                }
     280
     281
     282                // Registered 'CKEDITOR.style' instances.
     283                var styles = {} ;
    262284                /**
    263285                 * Hold a collection of created block container elements.
    264286                 */
     
    290312                                                                label :editor.lang.div.styleSelectLabel,
    291313                                                                'default' : '',
    292314                                                                items : [],
     315                                                                onChange : function()
     316                                                                {
     317                                                                        commitInternally        .call( this, [ 'info:class', 'advanced:dir', 'advanced:style' ] );
     318                                                                },
    293319                                                                setup : function( element )
    294320                                                                {
    295                                                                         this.setValue( element.$.style.cssText || '' );
     321                                                                        for ( var name in styles )
     322                                                                                styles[ name ].checkElementRemovable( element, true ) && this.setValue( name );
    296323                                                                },
    297324                                                                commit: function( element )
    298325                                                                {
    299                                                                         if ( this.getValue() )
    300                                                                                 element.$.style.cssText = this.getValue();
    301                                                                         else
    302                                                                                 element.removeAttribute( 'style' );
     326                                                                        var styleName;
     327                                                                        if ( styleName = this.getValue() )
     328                                                                                styles[ styleName ].applyToObject( element )
    303329                                                                }
    304330                                                        },
    305331                                                        {
     
    351377                                                                                        id :'style',
    352378                                                                                        style :'width: 100%;',
    353379                                                                                        label :editor.lang.common.cssStyle,
    354                                                                                         'default' : ''
    355                                                                                 }
     380                                                                                        'default' : '',
     381                                                                                        commit : function( element )
     382                                                                                        {
     383                                                                                                var style = element.$.style;
     384                                                                                                // Merge with 'elementStyle', which is of higher priority.
     385                                                                                                style.cssText = this.getValue() + ';' + style.cssText;
     386                                                                                        }
     387                                                                                }
    356388                                                                ]
    357389                                                        },
    358390                                                        {
     
    376408                                                                'default' : '',
    377409                                                                items :
    378410                                                                [
     411                                                                        [ editor.lang.common.notSet , '' ],
    379412                                                                        [
    380413                                                                                editor.lang.common.langDirLtr,
    381414                                                                                'ltr'
     
    394427                        onLoad : function()
    395428                        {
    396429                                setupFields.call(this);
     430
     431                                // Preparing for the 'elementStyle' field.
     432                                var dialog = this,
     433                                         stylesField = this.getContentElement( 'info', 'elementStyle' ),
     434                                         // Reuse the 'stylescombo' plugin's styles definition.
     435                                         customStylesConfig =  editor.config.stylesCombo_stylesSet,
     436                                         customStylesSetName = customStylesConfig && customStylesConfig.split( ':' )[ 0 ];
     437
     438                                stylesField.add( editor.lang.common.notSet, '' );
     439                                customStylesSetName && CKEDITOR.stylesSet.load( customStylesSetName,
     440                                        function( stylesSet )
     441                                        {
     442                                                var stylesDefinitions = stylesSet[ customStylesSetName ],
     443                                                        style, styleName;
     444
     445                                                if( stylesDefinitions )
     446                                                {
     447                                                        for ( var i = 0 ; i < stylesDefinitions.length ; i++ )
     448                                                        {
     449                                                                var styleDefinition = stylesDefinitions[ i ];
     450                                                                if( styleDefinition.element && styleDefinition.element == 'div' )
     451                                                                {
     452                                                                        styleName = styleDefinition.name;
     453                                                                        style = styles[ styleName ] = new CKEDITOR.style( styleDefinition );
     454                                                                        // Populate the styles field options with style name.
     455                                                                        stylesField.items.push( [ styleName, styleName ] );
     456                                                                        stylesField.add( styleName, styleName );
     457                                                                }
     458                                                        }
     459                                                }
     460
     461                                                // We should disable it if no styles are available.
     462                                                var fieldBox =  stylesField.getElement().getParent();
     463                                                stylesField.items.length ? fieldBox.removeStyle( 'display' ) : fieldBox.setStyle( 'display', 'none' );
     464                                                // Now setup the field value manually.
     465                                                setTimeout( function() { stylesField.setup( dialog._element ); }, 0 );
     466                                        } );
    397467                        },
    398468                        onShow : function()
    399469                        {
     
    416486                                        containers = createDiv( editor, true );
    417487
    418488                                // Update elements attributes
    419                                 for( var i = 0 ; i < containers.length ; i++ )
     489                                for ( var i = 0; i < containers.length; i++ )
     490                                {
    420491                                        this.commitContent( containers[ i ] );
     492                                        // Remove empty style attribute.
     493                                        !containers[ i ].getAttribute( 'style' ) && containers[ i ].removeAttribute( 'style' );
     494                                }
     495
    421496                                this.hide();
    422497                        }
    423498                };
  • _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 file name could be an empty one,
     131                                // which indicate dir is already of the full path.
     132                                ( external ? external.file : this.fileName + '.js' ) );
    131133        },
    132134
    133135        /**
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy