Skip to content

Commit

Permalink
Merge branch 't/10136' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Feb 28, 2013
2 parents 75f88e4 + f23c001 commit 8abbc10
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
22 changes: 21 additions & 1 deletion core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,14 @@
// be called asynchronously.
// In both cases - styles will be preload before plugins initialization.
function preloadStylesSet( editor ) {
editor.getStylesSet( function() {
editor.getStylesSet( function( styles ) {
// Wait for editor#loaded, so plugins could add their listeners.
// But listen with high priority to fire editor#stylesSet before editor#uiReady and editor#setData.
editor.once( 'loaded', function() {
// Note: we can't use fireOnce because this event may canceled and fired again.
editor.fire( 'stylesSet', { styles: styles } );
}, null, null, 1 );

loadPlugins( editor );
} );
}
Expand Down Expand Up @@ -1147,6 +1154,19 @@ CKEDITOR.ELEMENT_MODE_INLINE = 3;
* @param {CKEDITOR.editor} editor This editor instance.
*/

/**
* Fired when styles set is loaded. During editor initialization
* phase the {@link #getStylesSet} method returns only styles that
* are already loaded, which may not include e.g. styles parsed
* by `stylesheetparser` plugin. Thus, to be notified when all
* styles are ready you can listen on this event.
*
* @since 4.1
* @event stylesSet
* @param {CKEDITOR.editor} editor This editor instance.
* @param {Array} styles Array of styles definitions.
*/

/**
* Fired before the command execution when {@link #execCommand} is called.
*
Expand Down
12 changes: 4 additions & 8 deletions plugins/stylescombo/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
combo,
allowedContent = [];

editor.getStylesSet( function( stylesDefinitions ) {
editor.on( 'stylesSet', function( evt ) {
var stylesDefinitions = evt.data.styles;

if ( !stylesDefinitions )
return;

Expand Down Expand Up @@ -50,13 +52,7 @@

// Sorts the Array, so the styles get grouped by type in proper order (#9029).
stylesList.sort( function( styleA, styleB ) { return styleA._.weight - styleB._.weight; } );
});

// Hide entire combo when all styles are rejected.
// Although it looks like editor.getStylesSet is asynchronous,
// at this point it should behave synchronously.
if ( !stylesList.length )
return;
} );

editor.ui.addRichCombo( 'Styles', {
label: lang.label,
Expand Down
38 changes: 26 additions & 12 deletions plugins/stylesheetparser/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,36 @@

// Register a plugin named "stylesheetparser".
CKEDITOR.plugins.add( 'stylesheetparser', {
onLoad: function() {
var obj = CKEDITOR.editor.prototype;
obj.getStylesSet = CKEDITOR.tools.override( obj.getStylesSet, function( org ) {
return function( callback ) {
var self = this;
org.call( this, function( definitions ) {
init: function( editor ) {
// Stylesheet parser is incompatible with filter (#10136).
editor.filter.disable();

var cachedDefinitions;

editor.once( 'stylesSet', function( evt ) {
// Cancel event and fire it again when styles are ready.
evt.cancel();

// Overwrite editor#getStylesSet asap (contentDom is the first moment
// when editor.document is ready), but before stylescombo reads styles set (priority 5).
editor.once( 'contentDom', function() {
editor.getStylesSet( function( definitions ) {
// Rules that must be skipped
var skipSelectors = self.config.stylesheetParser_skipSelectors || ( /(^body\.|^\.)/i ),
var skipSelectors = editor.config.stylesheetParser_skipSelectors || ( /(^body\.|^\.)/i ),
// Rules that are valid
validSelectors = self.config.stylesheetParser_validSelectors || ( /\w+\.\w+/ );
validSelectors = editor.config.stylesheetParser_validSelectors || ( /\w+\.\w+/ );

callback( ( self._.stylesDefinitions = definitions.concat( LoadStylesCSS( self.document.$, skipSelectors, validSelectors ) ) ) );
});
};
});
cachedDefinitions = definitions.concat( LoadStylesCSS( editor.document.$, skipSelectors, validSelectors ) );

editor.getStylesSet = function( callback ) {
if ( cachedDefinitions )
return callback( cachedDefinitions );
};

editor.fire( 'stylesSet', { styles: cachedDefinitions } );
} );
} );
}, null, null, 1 );
}
});
})();
Expand Down

0 comments on commit 8abbc10

Please sign in to comment.