X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fstylescombo%2Fplugin.js;h=a5d4b7c3d6ea352020c4fde5c62f89aec99c22a0;hb=8665a7c6c60586526e32e8941fe2896739b6ebfb;hp=2b4716aae8cdd185bc7918a1ac3ba74976b1fdcf;hpb=059b4c2fef02528bf1af189f7996e80652faddfb;p=ckeditor.git diff --git a/_source/plugins/stylescombo/plugin.js b/_source/plugins/stylescombo/plugin.js index 2b4716a..a5d4b7c 100644 --- a/_source/plugins/stylescombo/plugin.js +++ b/_source/plugins/stylescombo/plugin.js @@ -5,8 +5,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license (function() { - var stylesManager; - CKEDITOR.plugins.add( 'stylescombo', { requires : [ 'richcombo', 'styles' ], @@ -15,20 +13,39 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { var config = editor.config, lang = editor.lang.stylesCombo, - pluginPath = this.path, - styles; + styles = {}, + stylesList = []; + + function loadStylesSet( callback ) + { + editor.getStylesSet( function( stylesDefinitions ) + { + if ( !stylesList.length ) + { + var style, + styleName; + + // Put all styles into an Array. + for ( var i = 0 ; i < stylesDefinitions.length ; i++ ) + { + var styleDefinition = stylesDefinitions[ i ]; + + styleName = styleDefinition.name; - if ( !stylesManager ) - stylesManager = CKEDITOR.stylesSet; + style = styles[ styleName ] = new CKEDITOR.style( styleDefinition ); + style._name = styleName; + style._.enterMode = config.enterMode; - var comboStylesSet = config.stylesCombo_stylesSet.split( ':' ), - styleSetName = comboStylesSet[ 0 ], - externalPath = comboStylesSet[ 1 ]; + stylesList.push( style ); + } - stylesManager.addExternal( styleSetName, - externalPath ? - comboStylesSet.slice( 1 ).join( ':' ) : - pluginPath + 'styles/' + styleSetName + '.js', '' ); + // Sorts the Array, so the styles get grouped by type. + stylesList.sort( sortStyles ); + } + + callback && callback(); + }); + } editor.ui.addRichCombo( 'Styles', { @@ -47,36 +64,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { var combo = this; - CKEDITOR.stylesSet.load( styleSetName, function( stylesSet ) + loadStylesSet( function() { - var stylesDefinitions = stylesSet[ styleSetName ], - style, - styleName, - stylesList = []; - - styles = {}; - - // Put all styles into an Array. - for ( var i = 0 ; i < stylesDefinitions.length ; i++ ) - { - var styleDefinition = stylesDefinitions[ i ]; - - styleName = styleDefinition.name; - - style = styles[ styleName ] = new CKEDITOR.style( styleDefinition ); - style._name = styleName; - - stylesList.push( style ); - } - - // Sorts the Array, so the styles get grouped - // by type. - stylesList.sort( sortStyles ); + var style, styleName; // Loop over the Array, adding all items to the // combo. var lastType; - for ( i = 0 ; i < stylesList.length ; i++ ) + for ( var i = 0 ; i < stylesList.length ; i++ ) { style = stylesList[ i ]; styleName = style._name; @@ -91,7 +86,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license combo.add( styleName, - style.type == CKEDITOR.STYLE_OBJECT ? styleName : buildPreview( style._.definition ), + style.type == CKEDITOR.STYLE_OBJECT ? styleName : style.buildPreview(), styleName ); } @@ -109,15 +104,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var style = styles[ value ], selection = editor.getSelection(); - if ( style.type == CKEDITOR.STYLE_OBJECT ) - { - var element = selection.getSelectedElement(); - if ( element ) - style.applyToObject( element ); - - return; - } - var elementPath = new CKEDITOR.dom.elementPath( selection.getStartElement() ); if ( style.type == CKEDITOR.STYLE_INLINE && style.checkActive( elementPath ) ) @@ -163,13 +149,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license onOpen : function() { - if ( CKEDITOR.env.ie ) + if ( CKEDITOR.env.ie || CKEDITOR.env.webkit ) editor.focus(); var selection = editor.getSelection(); var element = selection.getSelectedElement(), - elementName = element && element.getName(), elementPath = new CKEDITOR.dom.elementPath( element || selection.getStartElement() ); var counter = [ 0, 0, 0, 0 ]; @@ -180,25 +165,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var style = styles[ name ], type = style.type; - if ( type == CKEDITOR.STYLE_OBJECT ) + if ( style.checkActive( elementPath ) ) + this.mark( name ); + else if ( type == CKEDITOR.STYLE_OBJECT && !style.checkApplicable( elementPath ) ) { - if ( element && style.element == elementName ) - { - if ( style.checkElementRemovable( element, true ) ) - this.mark( name ); - - counter[ type ]++; - } - else - this.hideItem( name ); + this.hideItem( name ); + counter[ type ]--; } - else - { - if ( style.checkActive( elementPath ) ) - this.mark( name ); - counter[ type ]++; - } + counter[ type ]++; } if ( !counter[ CKEDITOR.STYLE_BLOCK ] ) @@ -211,40 +186,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license this.hideGroup( lang[ 'panelTitle' + String( CKEDITOR.STYLE_OBJECT ) ] ); } }); - } - }); - - function buildPreview( styleDefinition ) - { - var html = []; - - var elementName = styleDefinition.element; - // Avoid in the preview. - if ( elementName == 'bdo' ) - elementName = 'span'; - - html = [ '<', elementName ]; - - // Assign all defined attributes. - var attribs = styleDefinition.attributes; - if ( attribs ) - { - for ( var att in attribs ) - { - html.push( ' ', att, '="', attribs[ att ], '"' ); - } + editor.on( 'instanceReady', function() { loadStylesSet(); } ); } - - // Assign the style attribute. - var cssStyle = CKEDITOR.style.getStyleText( styleDefinition ); - if ( cssStyle ) - html.push( ' style="', cssStyle, '"' ); - - html.push( '>', styleDefinition.name, '' ); - - return html.join( '' ); - } + }); function sortStyles( styleA, styleB ) { @@ -258,25 +203,3 @@ For licensing, see LICENSE.html or http://ckeditor.com/license -1; } })(); - -/** - * The "styles definition set" to load into the styles combo. The styles may - * be defined in the page containing the editor, or can be loaded on demand - * from an external file when opening the styles combo for the fist time. In - * the second case, if this setting contains only a name, the styles definition - * file will be loaded from the "styles" folder inside the stylescombo plugin - * folder. Otherwise, this setting has the "name:url" syntax, making it - * possible to set the URL from which loading the styles file. - * @type string - * @default 'default' - * @example - * // Load from the stylescombo styles folder (mystyles.js file). - * config.stylesCombo_stylesSet = 'mystyles'; - * @example - * // Load from a relative URL. - * config.stylesCombo_stylesSet = 'mystyles:/editorstyles/styles.js'; - * @example - * // Load from a full URL. - * config.stylesCombo_stylesSet = 'mystyles:http://www.example.com/editorstyles/styles.js'; - */ -CKEDITOR.config.stylesCombo_stylesSet = 'default';