X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fbidi%2Fplugin.js;h=a1ae6c8179109ca5bf929d86103b5169662cb936;hp=830e2d4cefd87170acb1065df2baeb28f0b1a7c4;hb=4e90e78dc97789709ee7404359a5517540c27553;hpb=8f6c203fdaa543c3bca40baea6ae4ddcdf1a77f5 diff --git a/_source/plugins/bidi/plugin.js b/_source/plugins/bidi/plugin.js index 830e2d4..a1ae6c8 100644 --- a/_source/plugins/bidi/plugin.js +++ b/_source/plugins/bidi/plugin.js @@ -51,13 +51,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license function handleMixedDirContent( evt ) { var editor = evt.editor, - chromeRoot = editor.container.getChild( 1 ), directionNode = evt.data.path.block || evt.data.path.blockLimit; - if ( directionNode && editor.lang.dir != directionNode.getComputedStyle( 'direction' ) ) - chromeRoot.addClass( 'cke_mixed_dir_content' ); - else - chromeRoot.removeClass( 'cke_mixed_dir_content' ); + editor.fire( 'contentDirChanged', directionNode ? directionNode.getComputedStyle( 'direction' ) : editor.lang.dir ); } /** @@ -80,6 +76,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license function switchDir( element, dir, editor, database ) { + if ( element.isReadOnly() ) + return; + // Mark this element as processed by switchDir. CKEDITOR.dom.element.setMarker( database, element, 'bidi_processed', 1 ); @@ -92,7 +91,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Ancestor style must dominate. element.removeStyle( 'direction' ); element.removeAttribute( 'dir' ); - return null; + return; } } @@ -103,10 +102,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Stop if direction is same as present. if ( elementDir == dir ) - return null; - - // Reuse computedState if we already have it. - var dirBefore = useComputedState ? elementDir : element.getComputedStyle( 'direction' ); + return; // Clear direction on this element. element.removeStyle( 'direction' ); @@ -123,21 +119,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Set new direction for this element. element.setAttribute( 'dir', dir ); - // If the element direction changed, we need to switch the margins of - // the element and all its children, so it will get really reflected - // like a mirror. (#5910) - if ( dir != dirBefore ) - { - editor.fire( 'dirChanged', - { - node : element, - dir : dir - } ); - } - editor.forceNextSelectionCheck(); - return null; + return; } function getFullySelected( range, elements, enterMode ) @@ -195,8 +179,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license ) selectedElement = getFullySelected( range, guardElements, enterMode ); - if ( selectedElement && !selectedElement.isReadOnly() ) - switchDir( selectedElement, dir, editor, database ); + selectedElement && switchDir( selectedElement, dir, editor, database ); var iterator, block; @@ -226,7 +209,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license iterator.enlargeBr = enterMode != CKEDITOR.ENTER_BR; while ( ( block = iterator.getNextParagraph( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ) ) - !block.isReadOnly() && switchDir( block, dir, editor, database ); + switchDir( block, dir, editor, database ); } CKEDITOR.dom.element.clearAllMarkers( database ); @@ -265,9 +248,66 @@ For licensing, see LICENSE.html or http://ckeditor.com/license addButtonCommand( 'BidiRtl', lang.rtl, 'bidirtl', bidiCommand( 'rtl' ) ); editor.on( 'selectionChange', onSelectionChange ); + editor.on( 'contentDom', function() + { + editor.document.on( 'dirChanged', function( evt ) + { + editor.fire( 'dirChanged', + { + node : evt.data, + dir : evt.data.getDirection( 1 ) + } ); + }); + }); } }); + // If the element direction changed, we need to switch the margins of + // the element and all its children, so it will get really reflected + // like a mirror. (#5910) + function isOffline( el ) + { + var html = el.getDocument().getBody().getParent(); + while ( el ) + { + if ( el.equals( html ) ) + return false; + el = el.getParent(); + } + return true; + } + function dirChangeNotifier( org ) + { + var isAttribute = org == elementProto.setAttribute, + isRemoveAttribute = org == elementProto.removeAttribute, + dirStyleRegexp = /\bdirection\s*:\s*(.*?)\s*(:?$|;)/; + + return function( name, val ) + { + if ( !this.getDocument().equals( CKEDITOR.document ) ) + { + var orgDir; + if ( ( name == ( isAttribute || isRemoveAttribute ? 'dir' : 'direction' ) || + name == 'style' && ( isRemoveAttribute || dirStyleRegexp.test( val ) ) ) && !isOffline( this ) ) + { + orgDir = this.getDirection( 1 ); + var retval = org.apply( this, arguments ); + if ( orgDir != this.getDirection( 1 ) ) + { + this.getDocument().fire( 'dirChanged', this ); + return retval; + } + } + } + + return org.apply( this, arguments ); + }; + } + + var elementProto = CKEDITOR.dom.element.prototype, + methods = [ 'setStyle', 'removeStyle', 'setAttribute', 'removeAttribute' ]; + for ( var i = 0; i < methods.length; i++ ) + elementProto[ methods[ i ] ] = CKEDITOR.tools.override( elementProto[ methods [ i ] ], dirChangeNotifier ); })(); /** @@ -278,3 +318,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * @param {Object} eventData.node The element that is being changed. * @param {String} eventData.dir The new direction. */ + +/** + * Fired when the language direction in the specific cursor position is changed + * @name CKEDITOR.editor#contentDirChanged + * @event + * @param {String} eventData The direction in the current position. + */