Skip to content
Permalink
Browse files

Merge branch 't/10136' into major

  • Loading branch information...
Reinmar committed Feb 28, 2013
2 parents 75f88e4 + f23c001 commit 8abbc10bed32868b9c54524185c0773a63a87dce
Showing with 51 additions and 21 deletions.
  1. +21 −1 core/editor.js
  2. +4 −8 plugins/stylescombo/plugin.js
  3. +26 −12 plugins/stylesheetparser/plugin.js
@@ -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 );
} );
}
@@ -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.
*
@@ -18,7 +18,9 @@
combo,
allowedContent = [];

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

if ( !stylesDefinitions )
return;

@@ -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,
@@ -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 );
}
});
})();

0 comments on commit 8abbc10

Please sign in to comment.
You can’t perform that action at this time.