aboutsummaryrefslogtreecommitdiff
path: root/sources/plugins/justify/plugin.js
diff options
context:
space:
mode:
Diffstat (limited to 'sources/plugins/justify/plugin.js')
-rw-r--r--sources/plugins/justify/plugin.js41
1 files changed, 33 insertions, 8 deletions
diff --git a/sources/plugins/justify/plugin.js b/sources/plugins/justify/plugin.js
index ce5cab3..21b9221 100644
--- a/sources/plugins/justify/plugin.js
+++ b/sources/plugins/justify/plugin.js
@@ -37,7 +37,6 @@
37 this.name = name; 37 this.name = name;
38 this.value = value; 38 this.value = value;
39 this.context = 'p'; 39 this.context = 'p';
40
41 var classes = editor.config.justifyClasses, 40 var classes = editor.config.justifyClasses,
42 blockTag = editor.config.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div'; 41 blockTag = editor.config.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div';
43 42
@@ -150,6 +149,17 @@
150 if ( block.isReadOnly() ) 149 if ( block.isReadOnly() )
151 continue; 150 continue;
152 151
152 // Check if style or class might be applied to currently processed element (#455).
153 var tag = block.getName(),
154 isAllowedTextAlign, isAllowedCssClass;
155
156 isAllowedTextAlign = editor.activeFilter.check( tag + '{text-align}' );
157 isAllowedCssClass = editor.activeFilter.check( tag + '(' + cssClassName + ')' );
158
159 if ( !isAllowedCssClass && !isAllowedTextAlign ) {
160 continue;
161 }
162
153 block.removeAttribute( 'align' ); 163 block.removeAttribute( 'align' );
154 block.removeStyle( 'text-align' ); 164 block.removeStyle( 'text-align' );
155 165
@@ -158,13 +168,13 @@
158 168
159 var apply = ( this.state == CKEDITOR.TRISTATE_OFF ) && ( !useComputedState || ( getAlignment( block, true ) != this.value ) ); 169 var apply = ( this.state == CKEDITOR.TRISTATE_OFF ) && ( !useComputedState || ( getAlignment( block, true ) != this.value ) );
160 170
161 if ( cssClassName ) { 171 if ( cssClassName && isAllowedCssClass ) {
162 // Append the desired class name. 172 // Append the desired class name.
163 if ( apply ) 173 if ( apply )
164 block.addClass( cssClassName ); 174 block.addClass( cssClassName );
165 else if ( !className ) 175 else if ( !className )
166 block.removeAttribute( 'class' ); 176 block.removeAttribute( 'class' );
167 } else if ( apply ) { 177 } else if ( apply && isAllowedTextAlign ) {
168 block.setStyle( 'text-align', this.value ); 178 block.setStyle( 'text-align', this.value );
169 } 179 }
170 } 180 }
@@ -177,15 +187,31 @@
177 }, 187 },
178 188
179 refresh: function( editor, path ) { 189 refresh: function( editor, path ) {
180 var firstBlock = path.block || path.blockLimit; 190 var firstBlock = path.block || path.blockLimit,
181 191 name = firstBlock.getName(),
182 this.setState( firstBlock.getName() != 'body' && getAlignment( firstBlock, this.editor.config.useComputedState ) == this.value ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF ); 192 isEditable = firstBlock.equals( editor.editable() ),
193 isStylable = this.cssClassName ? editor.activeFilter.check( name + '(' + this.cssClassName + ')' ) :
194 editor.activeFilter.check( name + '{text-align}' );
195
196 // #455
197 // 1. Check if we are directly in editbale. Justification should be always allowed, and not highlighted.
198 // Checking path.elements.length is required to filter out situation `body > ul` where ul is selected and path.blockLimit returns editable.
199 // 2. Check if current element can have applied specific class.
200 // 3. Check if current element can have applied text-align style.
201 if ( isEditable && path.elements.length === 1 ) {
202 this.setState( CKEDITOR.TRISTATE_OFF );
203 } else if ( !isEditable && isStylable ) {
204 // 2 & 3 in one condition.
205 this.setState( getAlignment( firstBlock, this.editor.config.useComputedState ) == this.value ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
206 } else {
207 this.setState( CKEDITOR.TRISTATE_DISABLED );
208 }
183 } 209 }
184 }; 210 };
185 211
186 CKEDITOR.plugins.add( 'justify', { 212 CKEDITOR.plugins.add( 'justify', {
187 // jscs:disable maximumLineLength 213 // jscs:disable maximumLineLength
188 lang: 'af,ar,az,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,oc,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% 214 lang: 'af,ar,az,bg,bn,bs,ca,cs,cy,da,de,de-ch,el,en,en-au,en-ca,en-gb,eo,es,es-mx,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,oc,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%
189 // jscs:enable maximumLineLength 215 // jscs:enable maximumLineLength
190 icons: 'justifyblock,justifycenter,justifyleft,justifyright', // %REMOVE_LINE_CORE% 216 icons: 'justifyblock,justifycenter,justifyleft,justifyright', // %REMOVE_LINE_CORE%
191 hidpi: true, // %REMOVE_LINE_CORE% 217 hidpi: true, // %REMOVE_LINE_CORE%
@@ -225,7 +251,6 @@
225 toolbar: 'align,40' 251 toolbar: 'align,40'
226 } ); 252 } );
227 } 253 }
228
229 editor.on( 'dirChanged', onDirChanged ); 254 editor.on( 'dirChanged', onDirChanged );
230 } 255 }
231 } ); 256 } );