/**\r
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.\r
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.\r
* For licensing, see LICENSE.md or http://ckeditor.com/license\r
*/\r
\r
this.name = name;\r
this.value = value;\r
this.context = 'p';\r
-\r
var classes = editor.config.justifyClasses,\r
blockTag = editor.config.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div';\r
\r
if ( block.isReadOnly() )\r
continue;\r
\r
+ // Check if style or class might be applied to currently processed element (#455).\r
+ var tag = block.getName(),\r
+ isAllowedTextAlign, isAllowedCssClass;\r
+\r
+ isAllowedTextAlign = editor.activeFilter.check( tag + '{text-align}' );\r
+ isAllowedCssClass = editor.activeFilter.check( tag + '(' + cssClassName + ')' );\r
+\r
+ if ( !isAllowedCssClass && !isAllowedTextAlign ) {\r
+ continue;\r
+ }\r
+\r
block.removeAttribute( 'align' );\r
block.removeStyle( 'text-align' );\r
\r
\r
var apply = ( this.state == CKEDITOR.TRISTATE_OFF ) && ( !useComputedState || ( getAlignment( block, true ) != this.value ) );\r
\r
- if ( cssClassName ) {\r
+ if ( cssClassName && isAllowedCssClass ) {\r
// Append the desired class name.\r
if ( apply )\r
block.addClass( cssClassName );\r
else if ( !className )\r
block.removeAttribute( 'class' );\r
- } else if ( apply ) {\r
+ } else if ( apply && isAllowedTextAlign ) {\r
block.setStyle( 'text-align', this.value );\r
}\r
}\r
},\r
\r
refresh: function( editor, path ) {\r
- var firstBlock = path.block || path.blockLimit;\r
-\r
- this.setState( firstBlock.getName() != 'body' && getAlignment( firstBlock, this.editor.config.useComputedState ) == this.value ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );\r
+ var firstBlock = path.block || path.blockLimit,\r
+ name = firstBlock.getName(),\r
+ isEditable = firstBlock.equals( editor.editable() ),\r
+ isStylable = this.cssClassName ? editor.activeFilter.check( name + '(' + this.cssClassName + ')' ) :\r
+ editor.activeFilter.check( name + '{text-align}' );\r
+\r
+ // #455\r
+ // 1. Check if we are directly in editbale. Justification should be always allowed, and not highlighted.\r
+ // Checking path.elements.length is required to filter out situation `body > ul` where ul is selected and path.blockLimit returns editable.\r
+ // 2. Check if current element can have applied specific class.\r
+ // 3. Check if current element can have applied text-align style.\r
+ if ( isEditable && path.elements.length === 1 ) {\r
+ this.setState( CKEDITOR.TRISTATE_OFF );\r
+ } else if ( !isEditable && isStylable ) {\r
+ // 2 & 3 in one condition.\r
+ this.setState( getAlignment( firstBlock, this.editor.config.useComputedState ) == this.value ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );\r
+ } else {\r
+ this.setState( CKEDITOR.TRISTATE_DISABLED );\r
+ }\r
}\r
};\r
\r
CKEDITOR.plugins.add( 'justify', {\r
// jscs:disable maximumLineLength\r
- 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%\r
+ 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%\r
// jscs:enable maximumLineLength\r
icons: 'justifyblock,justifycenter,justifyleft,justifyright', // %REMOVE_LINE_CORE%\r
hidpi: true, // %REMOVE_LINE_CORE%\r
toolbar: 'align,40'\r
} );\r
}\r
-\r
editor.on( 'dirChanged', onDirChanged );\r
}\r
} );\r