+ // If the element direction changed, we need to switch the margins of\r
+ // the element and all its children, so it will get really reflected\r
+ // like a mirror. (#5910)\r
+ function isOffline( el )\r
+ {\r
+ var html = el.getDocument().getBody().getParent();\r
+ while ( el )\r
+ {\r
+ if ( el.equals( html ) )\r
+ return false;\r
+ el = el.getParent();\r
+ }\r
+ return true;\r
+ }\r
+ function dirChangeNotifier( org )\r
+ {\r
+ var isAttribute = org == elementProto.setAttribute,\r
+ isRemoveAttribute = org == elementProto.removeAttribute,\r
+ dirStyleRegexp = /\bdirection\s*:\s*(.*?)\s*(:?$|;)/;\r
+\r
+ return function( name, val )\r
+ {\r
+ if ( !this.getDocument().equals( CKEDITOR.document ) )\r
+ {\r
+ var orgDir;\r
+ if ( ( name == ( isAttribute || isRemoveAttribute ? 'dir' : 'direction' ) ||\r
+ name == 'style' && ( isRemoveAttribute || dirStyleRegexp.test( val ) ) ) && !isOffline( this ) )\r
+ {\r
+ orgDir = this.getDirection( 1 );\r
+ var retval = org.apply( this, arguments );\r
+ if ( orgDir != this.getDirection( 1 ) )\r
+ {\r
+ this.getDocument().fire( 'dirChanged', this );\r
+ return retval;\r
+ }\r
+ }\r
+ }\r
+\r
+ return org.apply( this, arguments );\r
+ };\r
+ }\r
+\r
+ var elementProto = CKEDITOR.dom.element.prototype,\r
+ methods = [ 'setStyle', 'removeStyle', 'setAttribute', 'removeAttribute' ];\r
+ for ( var i = 0; i < methods.length; i++ )\r
+ elementProto[ methods[ i ] ] = CKEDITOR.tools.override( elementProto[ methods [ i ] ], dirChangeNotifier );\r