X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fjustify%2Fplugin.js;h=1b3aaa5ec303079598f61a10c336d0d288d94e41;hb=fb481ba0a7d298e3e7b9034fcb9f2afdc6e8e796;hp=695f91010eceb77ba08f49a380c882b385b9c1f0;hpb=48b1db88210b4160dce439c6e3e32e14af8c106b;p=ckeditor.git diff --git a/_source/plugins/justify/plugin.js b/_source/plugins/justify/plugin.js index 695f910..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' ); @@ -49,13 +38,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license function onSelectionChange( evt ) { - var command = evt.editor.getCommand( this.name ); - command.state = getState.call( this, evt.editor, evt.data.path ); - command.fire( 'state' ); + if ( evt.editor.readOnly ) + return; + + evt.editor.getCommand( this.name ).refresh( evt.data.path ); } function justifyCommand( editor, name, value ) { + this.editor = editor; this.name = name; this.value = value; @@ -189,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 ); } }; @@ -237,3 +238,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license requires : [ 'domiterator' ] }); })(); + + /** + * List of classes to use for aligning the contents. If it's null, no classes will be used + * and instead the corresponding CSS values will be used. The array should contain 4 members, in the following order: left, center, right, justify. + * @name CKEDITOR.config.justifyClasses + * @type Array + * @default null + * @example + * // Use the classes 'AlignLeft', 'AlignCenter', 'AlignRight', 'AlignJustify' + * config.justifyClasses = [ 'AlignLeft', 'AlignCenter', 'AlignRight', 'AlignJustify' ]; + */