X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fjustify%2Fplugin.js;h=1b3aaa5ec303079598f61a10c336d0d288d94e41;hp=82c1fccff5e1cf80b40d3879646a181fd80f0ec2;hb=2f22c0c38f17e75be5541089076885442aaa2377;hpb=e73319a12b56100b29ef456fd74114fe5519e01c diff --git a/_source/plugins/justify/plugin.js b/_source/plugins/justify/plugin.js index 82c1fcc..1b3aaa5 100644 --- a/_source/plugins/justify/plugin.js +++ b/_source/plugins/justify/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -9,18 +9,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license (function() { - function getState( editor, path ) - { - var firstBlock = path.block || path.blockLimit; - - if ( !firstBlock || firstBlock.getName() == 'body' ) - return CKEDITOR.TRISTATE_OFF; - - return ( getAlignment( firstBlock, editor.config.useComputedState ) == this.value ) ? - CKEDITOR.TRISTATE_ON : - CKEDITOR.TRISTATE_OFF; - } - function getAlignment( element, useComputedState ) { useComputedState = useComputedState === undefined || useComputedState; @@ -40,7 +28,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license align = element.getStyle( 'text-align' ) || element.getAttribute( 'align' ) || ''; } - align && ( align = align.replace( /-moz-|-webkit-|start|auto/i, '' ) ); + // Sometimes computed values doesn't tell. + align && ( align = align.replace( /(?:-(?:moz|webkit)-)?(?:start|auto)/i, '' ) ); !align && useComputedState && ( align = element.getComputedStyle( 'direction' ) == 'rtl' ? 'right' : 'left' ); @@ -52,13 +41,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( evt.editor.readOnly ) return; - var command = evt.editor.getCommand( this.name ); - command.state = getState.call( this, evt.editor, evt.data.path ); - command.fire( 'state' ); + evt.editor.getCommand( this.name ).refresh( evt.data.path ); } function justifyCommand( editor, name, value ) { + this.editor = editor; this.name = name; this.value = value; @@ -192,6 +180,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license editor.focus(); editor.forceNextSelectionCheck(); selection.selectBookmarks( bookmarks ); + }, + + refresh : function( 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 ); } };