/*\r
-Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
For licensing, see LICENSE.html or http://ckeditor.com/license\r
*/\r
\r
{\r
useComputedState = useComputedState === undefined || useComputedState;\r
\r
- var align = useComputedState ?\r
- element.getComputedStyle( 'text-align' ) :\r
- element.getStyle( 'text-align' ) || element.getAttribute( 'align' ) || '';\r
+ var align;\r
+ if ( useComputedState )\r
+ align = element.getComputedStyle( 'text-align' );\r
+ else\r
+ {\r
+ while ( !element.hasAttribute || !( element.hasAttribute( 'align' ) || element.getStyle( 'text-align' ) ) )\r
+ {\r
+ var parent = element.getParent();\r
+ if ( !parent )\r
+ break;\r
+ element = parent;\r
+ }\r
+ align = element.getStyle( 'text-align' ) || element.getAttribute( 'align' ) || '';\r
+ }\r
\r
align && ( align = align.replace( /-moz-|-webkit-|start|auto/i, '' ) );\r
\r
\r
function onSelectionChange( evt )\r
{\r
+ if ( evt.editor.readOnly )\r
+ return;\r
+\r
var command = evt.editor.getCommand( this.name );\r
command.state = getState.call( this, evt.editor, evt.data.path );\r
command.fire( 'state' );\r
}\r
}\r
\r
+ function onDirChanged( e )\r
+ {\r
+ var editor = e.editor;\r
+\r
+ var range = new CKEDITOR.dom.range( editor.document );\r
+ range.setStartBefore( e.data.node );\r
+ range.setEndAfter( e.data.node );\r
+\r
+ var walker = new CKEDITOR.dom.walker( range ),\r
+ node;\r
+\r
+ while ( ( node = walker.next() ) )\r
+ {\r
+ if ( node.type == CKEDITOR.NODE_ELEMENT )\r
+ {\r
+ // A child with the defined dir is to be ignored.\r
+ if ( !node.equals( e.data.node ) && node.getDirection() )\r
+ {\r
+ range.setStartAfter( node );\r
+ walker = new CKEDITOR.dom.walker( range );\r
+ continue;\r
+ }\r
+\r
+ // Switch the alignment.\r
+ var classes = editor.config.justifyClasses;\r
+ if ( classes )\r
+ {\r
+ // The left align class.\r
+ if ( node.hasClass( classes[ 0 ] ) )\r
+ {\r
+ node.removeClass( classes[ 0 ] );\r
+ node.addClass( classes[ 2 ] );\r
+ }\r
+ // The right align class.\r
+ else if ( node.hasClass( classes[ 2 ] ) )\r
+ {\r
+ node.removeClass( classes[ 2 ] );\r
+ node.addClass( classes[ 0 ] );\r
+ }\r
+ }\r
+\r
+ // Always switch CSS margins.\r
+ var style = 'text-align';\r
+ var align = node.getStyle( style );\r
+\r
+ if ( align == 'left' )\r
+ node.setStyle( style, 'right' );\r
+ else if ( align == 'right' )\r
+ node.setStyle( style, 'left' );\r
+ }\r
+ }\r
+ }\r
+\r
justifyCommand.prototype = {\r
exec : function( editor )\r
{\r
iterator = ranges[ i ].createIterator();\r
iterator.enlargeBr = enterMode != CKEDITOR.ENTER_BR;\r
\r
- while ( ( block = iterator.getNextParagraph() ) )\r
+ while ( ( block = iterator.getNextParagraph( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ) )\r
{\r
block.removeAttribute( 'align' );\r
block.removeStyle( 'text-align' );\r
editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, right ) );\r
editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, center ) );\r
editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, justify ) );\r
+ editor.on( 'dirChanged', onDirChanged );\r
},\r
\r
requires : [ 'domiterator' ]\r
});\r
})();\r
\r
-CKEDITOR.tools.extend( CKEDITOR.config,\r
- {\r
- justifyClasses : null\r
- } );\r
+ /**\r
+ * List of classes to use for aligning the contents. If it's null, no classes will be used\r
+ * and instead the corresponding CSS values will be used. The array should contain 4 members, in the following order: left, center, right, justify.\r
+ * @name CKEDITOR.config.justifyClasses\r
+ * @type Array\r
+ * @default null\r
+ * @example\r
+ * // Use the classes 'AlignLeft', 'AlignCenter', 'AlignRight', 'AlignJustify'\r
+ * config.justifyClasses = [ 'AlignLeft', 'AlignCenter', 'AlignRight', 'AlignJustify' ];\r
+ */\r