086f1097551e6025e3131300e368a575e2156b04
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
8 CKEDITOR
.plugins
.add( 'stylescombo',
10 requires
: [ 'richcombo', 'styles' ],
12 init : function( editor
)
14 var config
= editor
.config
,
15 lang
= editor
.lang
.stylesCombo
,
20 function loadStylesSet( callback
)
22 editor
.getStylesSet( function( stylesDefinitions
)
24 if ( !stylesList
.length
)
29 // Put all styles into an Array.
30 for ( var i
= 0, count
= stylesDefinitions
.length
; i
< count
; i
++ )
32 var styleDefinition
= stylesDefinitions
[ i
];
34 styleName
= styleDefinition
.name
;
36 style
= styles
[ styleName
] = new CKEDITOR
.style( styleDefinition
);
37 style
._name
= styleName
;
38 style
._
.enterMode
= config
.enterMode
;
40 stylesList
.push( style
);
43 // Sorts the Array, so the styles get grouped by type.
44 stylesList
.sort( sortStyles
);
47 callback
&& callback();
51 editor
.ui
.addRichCombo( 'Styles',
54 title
: lang
.panelTitle
,
55 className
: 'cke_styles',
59 css
: editor
.skin
.editor
.css
.concat( config
.contentsCss
),
61 attributes
: { 'aria-label' : lang
.panelTitle
}
68 loadStylesSet( function()
77 // Loop over the Array, adding all items to the
79 for ( i
= 0, count
= stylesList
.length
; i
< count
; i
++ )
81 style
= stylesList
[ i
];
82 styleName
= style
._name
;
85 if ( type
!= lastType
)
87 combo
.startGroup( lang
[ 'panelTitle' + String( type
) ] );
93 style
.type
== CKEDITOR
.STYLE_OBJECT
? styleName
: style
.buildPreview(),
102 onClick : function( value
)
105 editor
.fire( 'saveSnapshot' );
107 var style
= styles
[ value
],
108 selection
= editor
.getSelection(),
109 elementPath
= new CKEDITOR
.dom
.elementPath( selection
.getStartElement() );
111 style
[ style
.checkActive( elementPath
) ? 'remove' : 'apply' ]( editor
.document
);
113 editor
.fire( 'saveSnapshot' );
116 onRender : function()
118 editor
.on( 'selectionChange', function( ev
)
120 var currentValue
= this.getValue(),
121 elementPath
= ev
.data
.path
,
122 elements
= elementPath
.elements
;
124 // For each element into the elements path.
125 for ( var i
= 0, count
= elements
.length
, element
; i
< count
; i
++ )
127 element
= elements
[i
];
129 // Check if the element is removable by any of
131 for ( var value
in styles
)
133 if ( styles
[ value
].checkElementRemovable( element
, true ) )
135 if ( value
!= currentValue
)
136 this.setValue( value
);
142 // If no styles match, just empty it.
150 if ( CKEDITOR
.env
.ie
|| CKEDITOR
.env
.webkit
)
153 var selection
= editor
.getSelection(),
154 element
= selection
.getSelectedElement(),
155 elementPath
= new CKEDITOR
.dom
.elementPath( element
|| selection
.getStartElement() ),
156 counter
= [ 0, 0, 0, 0 ];
160 for ( var name
in styles
)
162 var style
= styles
[ name
],
165 if ( style
.checkActive( elementPath
) )
167 else if ( type
== CKEDITOR
.STYLE_OBJECT
&& !style
.checkApplicable( elementPath
) )
169 this.hideItem( name
);
176 if ( !counter
[ CKEDITOR
.STYLE_BLOCK
] )
177 this.hideGroup( lang
[ 'panelTitle' + String( CKEDITOR
.STYLE_BLOCK
) ] );
179 if ( !counter
[ CKEDITOR
.STYLE_INLINE
] )
180 this.hideGroup( lang
[ 'panelTitle' + String( CKEDITOR
.STYLE_INLINE
) ] );
182 if ( !counter
[ CKEDITOR
.STYLE_OBJECT
] )
183 this.hideGroup( lang
[ 'panelTitle' + String( CKEDITOR
.STYLE_OBJECT
) ] );
186 // Force a reload of the data
191 delete combo
._
.panel
;
193 combo
._
.committed
= 0;
195 combo
._
.state
= CKEDITOR
.TRISTATE_OFF
;
203 editor
.on( 'instanceReady', function() { loadStylesSet(); } );
207 function sortStyles( styleA
, styleB
)
209 var typeA
= styleA
.type
,
212 return typeA
== typeB
? 0 :
213 typeA
== CKEDITOR
.STYLE_OBJECT
? -1 :
214 typeB
== CKEDITOR
.STYLE_OBJECT
? 1 :
215 typeB
== CKEDITOR
.STYLE_BLOCK
? 1 :