X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fstylescombo%2Fplugin.js;h=8ed7f9b429dabef53f6d4ce025f83a5a57b8a590;hb=e7789c1ad838194d45eeee6ac2eb6e55f5cf35a1;hp=c7e749bb928ddea0763a4ec7b5a7542151a4c679;hpb=941b0a9ba4e673e292510d80a5a86806994b8ea6;p=ckeditor.git diff --git a/_source/plugins/stylescombo/plugin.js b/_source/plugins/stylescombo/plugin.js index c7e749b..8ed7f9b 100644 --- a/_source/plugins/stylescombo/plugin.js +++ b/_source/plugins/stylescombo/plugin.js @@ -13,63 +13,64 @@ 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; + + 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 ); + } + + callback && callback(); + }); + } editor.ui.addRichCombo( 'Styles', { label : lang.label, title : lang.panelTitle, - voiceLabel : lang.voiceLabel, className : 'cke_styles', - multiSelect : true, panel : { css : editor.skin.editor.css.concat( config.contentsCss ), - voiceLabel : lang.panelVoiceLabel + multiSelect : true, + attributes : { 'aria-label' : lang.panelTitle } }, init : function() { - var combo = this, - stylesSet = config.stylesCombo_stylesSet.split( ':' ); + var combo = this; - var stylesSetPath = stylesSet[ 1 ] ? - stylesSet.slice( 1 ).join( ':' ) : // #4481 - CKEDITOR.getUrl( pluginPath + 'styles/' + stylesSet[ 0 ] + '.js' ) ; - - stylesSet = stylesSet[ 0 ]; - - CKEDITOR.loadStylesSet( stylesSet, stylesSetPath, function( stylesDefinitions ) + loadStylesSet( function() { - var 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; @@ -84,7 +85,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 ); } @@ -102,15 +103,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 ) ) @@ -156,13 +148,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 ]; @@ -173,25 +164,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 ] ) @@ -204,63 +185,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license this.hideGroup( lang[ 'panelTitle' + String( CKEDITOR.STYLE_OBJECT ) ] ); } }); - } - }); - - var stylesSets = {}; - - CKEDITOR.addStylesSet = function( name, styles ) - { - stylesSets[ name ] = styles; - }; - - CKEDITOR.loadStylesSet = function( name, url, callback ) - { - var stylesSet = stylesSets[ name ]; - - if ( stylesSet ) - { - callback( stylesSet ); - return ; - } - - CKEDITOR.scriptLoader.load( url, function() - { - callback( stylesSets[ name ] ); - }); - }; - - 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 ) { @@ -274,25 +202,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';