X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2Fpackagist%2Fludivine-ckeditor-component.git;a=blobdiff_plain;f=sources%2Fplugins%2Fjustify%2Fplugin.js;h=21b9221090f5f8e55f74a2e4d7e5ee44df1aaad5;hp=ce5cab382b02549d328aa87e11662d269ee6f88f;hb=1794320dcfdfcd19572fb1676294f9853a6bbc20;hpb=7183f6a6a21ad9124e70c997e0168459f377a9f2 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 @@ this.name = name; this.value = value; this.context = 'p'; - var classes = editor.config.justifyClasses, blockTag = editor.config.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div'; @@ -150,6 +149,17 @@ if ( block.isReadOnly() ) continue; + // Check if style or class might be applied to currently processed element (#455). + var tag = block.getName(), + isAllowedTextAlign, isAllowedCssClass; + + isAllowedTextAlign = editor.activeFilter.check( tag + '{text-align}' ); + isAllowedCssClass = editor.activeFilter.check( tag + '(' + cssClassName + ')' ); + + if ( !isAllowedCssClass && !isAllowedTextAlign ) { + continue; + } + block.removeAttribute( 'align' ); block.removeStyle( 'text-align' ); @@ -158,13 +168,13 @@ var apply = ( this.state == CKEDITOR.TRISTATE_OFF ) && ( !useComputedState || ( getAlignment( block, true ) != this.value ) ); - if ( cssClassName ) { + if ( cssClassName && isAllowedCssClass ) { // Append the desired class name. if ( apply ) block.addClass( cssClassName ); else if ( !className ) block.removeAttribute( 'class' ); - } else if ( apply ) { + } else if ( apply && isAllowedTextAlign ) { block.setStyle( 'text-align', this.value ); } } @@ -177,15 +187,31 @@ }, refresh: function( editor, path ) { - var firstBlock = path.block || path.blockLimit; - - this.setState( firstBlock.getName() != 'body' && getAlignment( firstBlock, this.editor.config.useComputedState ) == this.value ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF ); + var firstBlock = path.block || path.blockLimit, + name = firstBlock.getName(), + isEditable = firstBlock.equals( editor.editable() ), + isStylable = this.cssClassName ? editor.activeFilter.check( name + '(' + this.cssClassName + ')' ) : + editor.activeFilter.check( name + '{text-align}' ); + + // #455 + // 1. Check if we are directly in editbale. Justification should be always allowed, and not highlighted. + // Checking path.elements.length is required to filter out situation `body > ul` where ul is selected and path.blockLimit returns editable. + // 2. Check if current element can have applied specific class. + // 3. Check if current element can have applied text-align style. + if ( isEditable && path.elements.length === 1 ) { + this.setState( CKEDITOR.TRISTATE_OFF ); + } else if ( !isEditable && isStylable ) { + // 2 & 3 in one condition. + this.setState( getAlignment( firstBlock, this.editor.config.useComputedState ) == this.value ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF ); + } else { + this.setState( CKEDITOR.TRISTATE_DISABLED ); + } } }; CKEDITOR.plugins.add( 'justify', { // jscs:disable maximumLineLength - 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% + 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% // jscs:enable maximumLineLength icons: 'justifyblock,justifycenter,justifyleft,justifyright', // %REMOVE_LINE_CORE% hidpi: true, // %REMOVE_LINE_CORE% @@ -225,7 +251,6 @@ toolbar: 'align,40' } ); } - editor.on( 'dirChanged', onDirChanged ); } } );