Ticket #8832: 8832.patch

File 8832.patch, 2.3 KB (added by Alfonso Martínez de Lizarrondo, 12 years ago)

Proposed patch

  • _source/plugins/stylesheetparser/plugin.js

     
    9393        CKEDITOR.plugins.add( 'stylesheetparser',
    9494        {
    9595                requires: [ 'styles' ],
    96                 onLoad : function()
     96                init : function( editor )
    9797                {
    98                         var obj = CKEDITOR.editor.prototype;
    99                         obj.getStylesSet = CKEDITOR.tools.override( obj.getStylesSet,  function( org )
     98                        var definitions,
     99                                timer;
     100
     101                        editor.on( 'mode', function( e )
    100102                        {
    101                                 return function( callback )
    102                                 {
    103                                         var self = this;
    104                                         org.call( this, function( definitions )
     103                                // If there was a timeout pending, cancel it
     104                                if ( timer )
     105                                        window.clearTimeout( timer );
     106                                timer = null;
     107
     108                                if ( editor.mode != 'wysiwyg' )
     109                                        return;
     110
     111                                // Do this only once for non-full page
     112                                if ( !editor.config.fullPage )
     113                                        e.removeListener();
     114
     115                                // Use a delay before parsing the stylesheet to avoid errors with Firefox 4. #7784
     116                                // Safari requires even greater delay
     117                                timer = window.setTimeout( function() {
     118                                        editor.getStylesSet( function( stylesDefinitions )
    105119                                        {
    106                                                 // Rules that must be skipped
    107                                                 var skipSelectors = self.config.stylesheetParser_skipSelectors || ( /(^body\.|^\.)/i ),
     120                                                // Use the original definitions or set them at this time
     121                                                definitions = definitions || stylesDefinitions;
     122
     123                                                        // Rules that must be skipped
     124                                                var skipSelectors = editor.config.stylesheetParser_skipSelectors || ( /(^body\.|^\.)/i ),
    108125                                                        // Rules that are valid
    109                                                         validSelectors = self.config.stylesheetParser_validSelectors || ( /\w+\.\w+/ );
     126                                                        validSelectors = editor.config.stylesheetParser_validSelectors || ( /\w+\.\w+/ );
    110127
    111                                                 callback( ( self._.stylesDefinitions = definitions.concat( LoadStylesCSS( self.document.$, skipSelectors, validSelectors ) ) ) );
    112                                         });
    113                                 };
     128                                                // Add the styles found in the document
     129                                                editor._.stylesDefinitions = definitions.concat( LoadStylesCSS( editor.document.$, skipSelectors, validSelectors ) );
     130
     131                                                // Refresh the styles combo
     132                                                var combo = editor.ui._.items[ 'Styles' ];
     133                                                combo && combo.args[ 0 ].reset();
     134                                        } );
     135                                }, 1000 );
    114136                        });
    115137
    116138                }
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy