Skip to content

Commit

Permalink
Merge branch 't/9992' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Feb 18, 2013
2 parents a40810f + ef24dcc commit 6a0fd35
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 55 deletions.
14 changes: 13 additions & 1 deletion core/editor.js
Expand Up @@ -370,10 +370,22 @@

editor.fire( 'langLoaded' );

loadPlugins( editor );
preloadStylesSet( editor );
});
}

// Preloads styles set file (config.stylesSet).
// If stylesSet was defined directly (by an array)
// this function will call loadPlugins fully synchronously.
// If stylesSet is a string (path) loadPlugins will
// be called asynchronously.
// In both cases - styles will be preload before plugins initialization.
function preloadStylesSet( editor ) {
editor.getStylesSet( function() {
loadPlugins( editor );
} );
}

function loadPlugins( editor ) {
var config = editor.config,
plugins = config.plugins,
Expand Down
30 changes: 23 additions & 7 deletions core/style.js
Expand Up @@ -1491,7 +1491,13 @@ CKEDITOR.editor.prototype.getStylesSet = function( callback ) {
if ( !this._.stylesDefinitions ) {
var editor = this,
// Respect the backwards compatible definition entry
configStyleSet = editor.config.stylesCombo_stylesSet || editor.config.stylesSet || 'default';
configStyleSet = editor.config.stylesCombo_stylesSet || editor.config.stylesSet;

// The false value means that none styles should be loaded.
if ( configStyleSet === false ) {
callback( null );
return;
}

// #5352 Allow to define the styles directly in the config object
if ( configStyleSet instanceof Array ) {
Expand All @@ -1500,6 +1506,10 @@ CKEDITOR.editor.prototype.getStylesSet = function( callback ) {
return;
}

// Default value is 'default'.
if ( !configStyleSet )
configStyleSet = 'default';

var partsStylesSet = configStyleSet.split( ':' ),
styleSetName = partsStylesSet[ 0 ],
externalPath = partsStylesSet[ 1 ];
Expand Down Expand Up @@ -1546,18 +1556,24 @@ CKEDITOR.editor.prototype.getStylesSet = function( callback ) {
*
* The styles may be defined in the page containing the editor, or can be
* loaded on demand from an external file. In the second case, if this setting
* contains only a name, the styles definition file will be loaded from the
* `styles` folder inside the styles plugin folder.
* contains only a name, the `styles.js` file will be loaded from the
* CKEditor root folder (what ensures backward compatibility with CKEditor 4.0).
*
* Otherwise, this setting has the `name:url` syntax, making it
* possible to set the URL from which loading the styles file.
* Note that the `name` has to be equal to the name used in
* {@link CKEDITOR.stylesSet#add} while registering styles set.
*
* *Note:* Since 4.1 it is possible to set `stylesSet` to `false`
* to prevent loading any styles set.
*
* Previously this setting was available as `config.stylesCombo_stylesSet`.
* // Do not load any file. Styles set is empty.
* config.stylesSet = false;
*
* // Load from the styles' styles folder (mystyles.js file).
* // Load the 'mystyles' styles set from styles.js file.
* config.stylesSet = 'mystyles';
*
* // Load from a relative URL.
* // Load the 'mystyles' styles set from a relative URL.
* config.stylesSet = 'mystyles:/editorstyles/styles.js';
*
* // Load from a full URL.
Expand All @@ -1571,6 +1587,6 @@ CKEDITOR.editor.prototype.getStylesSet = function( callback ) {
* ];
*
* @since 3.3
* @cfg {String/Array} [stylesSet='default']
* @cfg {String/Array/false} [stylesSet='default']
* @member CKEDITOR.config
*/
97 changes: 50 additions & 47 deletions plugins/stylescombo/plugin.js
Expand Up @@ -4,6 +4,8 @@
*/

(function() {
'use strict';

CKEDITOR.plugins.add( 'stylescombo', {
requires: 'richcombo',
lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,el,en-au,en-ca,en-gb,en,eo,es,et,eu,fa,fi,fo,fr-ca,fr,gl,gu,he,hi,hr,hu,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,pl,pt-br,pt,ro,ru,sk,sl,sr-latn,sr,sv,th,tr,ug,uk,vi,zh-cn,zh', // %REMOVE_LINE_CORE%
Expand All @@ -13,44 +15,54 @@
lang = editor.lang.stylescombo,
styles = {},
stylesList = [],
combo;
combo,
allowedContent = [];

function loadStylesSet( callback ) {
editor.getStylesSet( function( stylesDefinitions ) {
if ( !stylesList.length ) {
var style, styleName;
editor.getStylesSet( function( stylesDefinitions ) {
if ( !stylesDefinitions )
return;

// Put all styles into an Array.
for ( var i = 0, count = stylesDefinitions.length; i < count; i++ ) {
var styleDefinition = stylesDefinitions[ i ];
var style, styleName;

if ( editor.blockless && ( styleDefinition.element in CKEDITOR.dtd.$block ) )
continue;
// Put all styles into an Array.
for ( var i = 0, count = stylesDefinitions.length; i < count; i++ ) {
var styleDefinition = stylesDefinitions[ i ];

styleName = styleDefinition.name;
if ( editor.blockless && ( styleDefinition.element in CKEDITOR.dtd.$block ) )
continue;

style = styles[ styleName ] = new CKEDITOR.style( styleDefinition );
style._name = styleName;
style._.enterMode = config.enterMode;
styleName = styleDefinition.name;

// Weight is used to sort styles (#9029).
style._.weight = i + ( style.type == CKEDITOR.STYLE_OBJECT ? 1 : style.type == CKEDITOR.STYLE_BLOCK ? 2 : 3 ) * 1000;
style = new CKEDITOR.style( styleDefinition );

stylesList.push( style );
}
if ( !editor.filter.customConfig || editor.filter.check( style ) ) {
style._name = styleName;
style._.enterMode = config.enterMode;

// Sorts the Array, so the styles get grouped by type in proper order (#9029).
stylesList.sort( function( styleA, styleB ) { return styleA._.weight - styleB._.weight; } );
// Weight is used to sort styles (#9029).
style._.weight = i + ( style.type == CKEDITOR.STYLE_OBJECT ? 1 : style.type == CKEDITOR.STYLE_BLOCK ? 2 : 3 ) * 1000;

styles[ styleName ] = style;
stylesList.push( style );
allowedContent.push( style );
}
}

callback && callback();
});
}
// 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,
title: lang.panelTitle,
toolbar: 'styles,10',
allowedContent: allowedContent,

panel: {
css: [ CKEDITOR.skin.getPath( 'editor' ) ].concat( config.contentsCss ),
Expand All @@ -59,29 +71,24 @@
},

init: function() {
combo = this;

loadStylesSet( function() {
var style, styleName, lastType, type, i, count;

// Loop over the Array, adding all items to the
// combo.
for ( i = 0, count = stylesList.length; i < count; i++ ) {
style = stylesList[ i ];
styleName = style._name;
type = style.type;

if ( type != lastType ) {
combo.startGroup( lang[ 'panelTitle' + String( type ) ] );
lastType = type;
}

combo.add( styleName, style.type == CKEDITOR.STYLE_OBJECT ? styleName : style.buildPreview(), styleName );
var style, styleName, lastType, type, i, count;

// Loop over the Array, adding all items to the
// combo.
for ( i = 0, count = stylesList.length; i < count; i++ ) {
style = stylesList[ i ];
styleName = style._name;
type = style.type;

if ( type != lastType ) {
this.startGroup( lang[ 'panelTitle' + String( type ) ] );
lastType = type;
}

combo.commit();
this.add( styleName, style.type == CKEDITOR.STYLE_OBJECT ? styleName : style.buildPreview(), styleName );
}

});
this.commit();
},

onClick: function( value ) {
Expand Down Expand Up @@ -173,10 +180,6 @@
loadStylesSet();
}
});

editor.on( 'instanceReady', function() {
loadStylesSet();
});
}
});
})();

0 comments on commit 6a0fd35

Please sign in to comment.