+ 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