X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fjustify%2Fplugin.js;h=0a5f07d00207d42098a017e7ce554a3bc682ccbd;hb=1056598c95187351dc58f4991d331e2258d038b5;hp=ad134c532636066e3bb497b37d048754859f6b84;hpb=039a051ccf3901311661022a30afd60fc38130c9;p=ckeditor.git diff --git a/_source/plugins/justify/plugin.js b/_source/plugins/justify/plugin.js index ad134c5..0a5f07d 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-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -87,8 +87,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var editor = e.editor; var range = new CKEDITOR.dom.range( editor.document ); - range.setStartBefore( e.data ); - range.setEndAfter( e.data ); + range.setStartBefore( e.data.node ); + range.setEndAfter( e.data.node ); var walker = new CKEDITOR.dom.walker( range ), node; @@ -98,7 +98,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( node.type == CKEDITOR.NODE_ELEMENT ) { // A child with the defined dir is to be ignored. - if ( !node.equals( e.data ) && node.getDirection() ) + if ( !node.equals( e.data.node ) && node.getDirection() ) { range.setStartAfter( node ); walker = new CKEDITOR.dom.walker( range ); @@ -106,6 +106,24 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } // Switch the alignment. + var classes = editor.config.justifyClasses; + if ( classes ) + { + // The left align class. + if ( node.hasClass( classes[ 0 ] ) ) + { + node.removeClass( classes[ 0 ] ); + node.addClass( classes[ 2 ] ); + } + // The right align class. + else if ( node.hasClass( classes[ 2 ] ) ) + { + node.removeClass( classes[ 2 ] ); + node.addClass( classes[ 0 ] ); + } + } + + // Always switch CSS margins. var style = 'text-align'; var align = node.getStyle( style ); @@ -141,7 +159,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' ); @@ -219,3 +237,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' ]; + */