]>
git.immae.eu Git - perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git/blob - sources/plugins/stylescombo/plugin.js
2 * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
9 CKEDITOR
.plugins
.add( 'stylescombo', {
10 requires: 'richcombo',
11 // jscs:disable maximumLineLength
12 lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,de-ch,el,en,en-au,en-ca,en-gb,eo,es,et,eu,fa,fi,fo,fr,fr-ca,gl,gu,he,hi,hr,hu,id,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%
13 // jscs:enable maximumLineLength
15 init: function( editor
) {
16 var config
= editor
.config
,
17 lang
= editor
.lang
.stylescombo
,
23 editor
.on( 'stylesSet', function( evt
) {
24 var stylesDefinitions
= evt
.data
.styles
;
26 if ( !stylesDefinitions
)
29 var style
, styleName
, styleType
;
31 // Put all styles into an Array.
32 for ( var i
= 0, count
= stylesDefinitions
.length
; i
< count
; i
++ ) {
33 var styleDefinition
= stylesDefinitions
[ i
];
35 if ( editor
.blockless
&& ( styleDefinition
.element
in CKEDITOR
.dtd
.$block
) )
38 styleName
= styleDefinition
.name
;
39 style
= new CKEDITOR
.style( styleDefinition
);
41 if ( !editor
.filter
.customConfig
|| editor
.filter
.check( style
) ) {
42 style
._name
= styleName
;
43 style
._
.enterMode
= config
.enterMode
;
44 // Get the type (which will be used to assign style to one of 3 groups) from assignedTo if it's defined.
45 style
._
.type
= styleType
= style
.assignedTo
|| style
.type
;
47 // Weight is used to sort styles (#9029).
48 style
._
.weight
= i
+ ( styleType
== CKEDITOR
.STYLE_OBJECT
? 1 : styleType
== CKEDITOR
.STYLE_BLOCK
? 2 : 3 ) * 1000;
50 styles
[ styleName
] = style
;
51 stylesList
.push( style
);
52 allowedContent
.push( style
);
56 // Sorts the Array, so the styles get grouped by type in proper order (#9029).
57 stylesList
.sort( function( styleA
, styleB
) {
58 return styleA
._
.weight
- styleB
._
.weight
;
62 editor
.ui
.addRichCombo( 'Styles', {
64 title: lang
.panelTitle
,
66 allowedContent: allowedContent
,
69 css: [ CKEDITOR
.skin
.getPath( 'editor' ) ].concat( config
.contentsCss
),
71 attributes: { 'aria-label': lang
.panelTitle
}
75 var style
, styleName
, lastType
, type
, i
, count
;
77 // Loop over the Array, adding all items to the
79 for ( i
= 0, count
= stylesList
.length
; i
< count
; i
++ ) {
80 style
= stylesList
[ i
];
81 styleName
= style
._name
;
84 if ( type
!= lastType
) {
85 this.startGroup( lang
[ 'panelTitle' + String( type
) ] );
89 this.add( styleName
, style
.type
== CKEDITOR
.STYLE_OBJECT
? styleName : style
.buildPreview(), styleName
);
95 onClick: function( value
) {
97 editor
.fire( 'saveSnapshot' );
99 var style
= styles
[ value
],
100 elementPath
= editor
.elementPath();
102 editor
[ style
.checkActive( elementPath
, editor
) ? 'removeStyle' : 'applyStyle' ]( style
);
103 editor
.fire( 'saveSnapshot' );
106 onRender: function() {
107 editor
.on( 'selectionChange', function( ev
) {
108 var currentValue
= this.getValue(),
109 elementPath
= ev
.data
.path
,
110 elements
= elementPath
.elements
;
112 // For each element into the elements path.
113 for ( var i
= 0, count
= elements
.length
, element
; i
< count
; i
++ ) {
114 element
= elements
[ i
];
116 // Check if the element is removable by any of
118 for ( var value
in styles
) {
119 if ( styles
[ value
].checkElementRemovable( element
, true, editor
) ) {
120 if ( value
!= currentValue
)
121 this.setValue( value
);
127 // If no styles match, just empty it.
133 var selection
= editor
.getSelection(),
134 element
= selection
.getSelectedElement(),
135 elementPath
= editor
.elementPath( element
),
136 counter
= [ 0, 0, 0, 0 ];
140 for ( var name
in styles
) {
141 var style
= styles
[ name
],
144 if ( style
.checkApplicable( elementPath
, editor
, editor
.activeFilter
) )
147 this.hideItem( name
);
149 if ( style
.checkActive( elementPath
, editor
) )
153 if ( !counter
[ CKEDITOR
.STYLE_BLOCK
] )
154 this.hideGroup( lang
[ 'panelTitle' + String( CKEDITOR
.STYLE_BLOCK
) ] );
156 if ( !counter
[ CKEDITOR
.STYLE_INLINE
] )
157 this.hideGroup( lang
[ 'panelTitle' + String( CKEDITOR
.STYLE_INLINE
) ] );
159 if ( !counter
[ CKEDITOR
.STYLE_OBJECT
] )
160 this.hideGroup( lang
[ 'panelTitle' + String( CKEDITOR
.STYLE_OBJECT
) ] );
163 refresh: function() {
164 var elementPath
= editor
.elementPath();
169 for ( var name
in styles
) {
170 var style
= styles
[ name
];
172 if ( style
.checkApplicable( elementPath
, editor
, editor
.activeFilter
) )
175 this.setState( CKEDITOR
.TRISTATE_DISABLED
);
178 // Force a reload of the data
181 delete combo
._
.panel
;
183 combo
._
.committed
= 0;
185 combo
._
.state
= CKEDITOR
.TRISTATE_OFF
;