X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fjustify%2Fplugin.js;h=1b3aaa5ec303079598f61a10c336d0d288d94e41;hb=2f22c0c38f17e75be5541089076885442aaa2377;hp=2de9b0b77f37393e5530b2b0f6b7cebf893fe8bc;hpb=614511639979907ceb0da3614122a4d8eb963ad4;p=ckeditor.git diff --git a/_source/plugins/justify/plugin.js b/_source/plugins/justify/plugin.js index 2de9b0b..1b3aaa5 100644 --- a/_source/plugins/justify/plugin.js +++ b/_source/plugins/justify/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2010, 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; @@ -159,7 +150,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license iterator = ranges[ i ].createIterator(); iterator.enlargeBr = enterMode != CKEDITOR.ENTER_BR; - while ( ( block = iterator.getNextParagraph() ) ) + while ( ( block = iterator.getNextParagraph( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ) ) { block.removeAttribute( 'align' ); block.removeStyle( 'text-align' ); @@ -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' ]; + */