Ticket #5910: 5910_3.patch

File 5910_3.patch, 4.4 KB (added by Tobiasz Cudnik, 14 years ago)
  • _source/plugins/indent/plugin.js

     
    2626                var elementPath = evt.data.path,
    2727                                list = elementPath && elementPath.contains( listNodeNames );
    2828
     29                var elementDirection = evt.data.element.getComputedStyle( 'direction' ).toLowerCase();
     30                editor._.commands.indent.indentCssProperty = ( elementDirection == 'ltr' ) ? 'margin-left' : 'margin-right';
     31
    2932                if ( list )
    3033                                return setState.call( this, editor, CKEDITOR.TRISTATE_OFF );
    3134
     
    3740                if ( !firstBlock )
    3841                        return setState.call( this, editor, CKEDITOR.TRISTATE_DISABLED );
    3942
     43                // Fix reference to command property (by redundant copy).
     44                this.indentCssProperty = editor._.commands.indent.indentCssProperty;
     45
    4046                if ( this.useIndentClasses )
    4147                {
    4248                        var indentClass = firstBlock.$.className.match( this.classNameRegex ),
     
    183189
    184190        function indentBlock( editor, range )
    185191        {
     192                // Fix reference to command property (by redundant copy).
     193                this.indentCssProperty = editor._.commands.indent.indentCssProperty;
     194
    186195                var iterator = range.createIterator(),
    187196                        enterMode = editor.config.enterMode;
    188197                iterator.enforceRealBlocks = true;
     
    233242                        if ( currentOffset < 0 )
    234243                                return false;
    235244
    236                                 currentOffset = Math.max( currentOffset, 0 );
    237                                 currentOffset = Math.ceil( currentOffset / editor.config.indentOffset ) * editor.config.indentOffset;
    238                         element.setStyle( this.indentCssProperty, currentOffset ? currentOffset + editor.config.indentUnit : '' );
    239                         if ( element.getAttribute( 'style' ) === '' )
    240                                 element.removeAttribute( 'style' );
     245                        currentOffset = Math.max( currentOffset, 0 );
     246                        currentOffset = Math.ceil( currentOffset / editor.config.indentOffset ) * editor.config.indentOffset;
     247
     248                                // Determine text direction for this element.
     249                                var editorDir = ( editor.config.contentsLangDirection == 'ui' )
     250                                        ? editor.lang.dir : editor.config.contentsLangDirection;
     251                                var dir = element.getComputedStyle( 'direction' ).toLowerCase();
     252
     253                                var marginDir = ( dir == 'ltr' ) ? 'left' : 'right';
     254                                element.setStyle( 'margin-' + marginDir, currentOffset ? currentOffset + editor.config.indentUnit : '' );
     255
     256                                if ( element.getAttribute( 'style' ) === '' )
     257                                        element.removeAttribute( 'style' );
    241258                        }
    242259
    243260                return true;
    244                 }
     261        }
    245262
    246263        function indentCommand( editor, name )
    247264        {
  • _source/plugins/bidi/plugin.js

     
    2626                                && !( selectedElement.type == CKEDITOR.NODE_ELEMENT && selectedElement.getName() in directSelectionGuardElements )
    2727                        )
    2828                        selectedElement = getFullySelected( selection, guardElements );
    29                
     29
    3030                selectedElement = selectedElement || path.block || path.blockLimit;
    3131
    3232                if ( !selectedElement || selectedElement.getName() == 'body' )
     
    4242         */
    4343        function switchDir( element, dir, editor )
    4444        {
    45                 if ( element.hasAttribute( 'dir' ) && element.getAttribute( 'dir' ).toLowerCase()  == dir )
    46                         element.removeAttribute( 'dir' );
    47                 else
    48                         element.setAttribute( 'dir', dir );
     45                var switchMargin,
     46                        editorDir = ( editor.config.contentsLangDirection == 'ui' )
     47                                ? editor.lang.dir : editor.config.contentsLangDirection;
     48
     49                if ( element.hasAttribute( 'dir' ) )
     50                {
     51                        if ( element.getAttribute( 'dir' ).toLowerCase() == dir )
     52                                element.removeAttribute( 'dir' );
     53                        else
     54                                element.setAttribute( 'dir', dir );
     55                }
     56                else
     57                {
     58                        element.setAttribute( 'dir', dir );
    4959
     60                        if ( dir != editorDir )
     61                                switchMargin = dir;
     62                }
     63
    5064                editor.forceNextSelectionCheck();
    51         }
     65
     66                if ( !switchMargin )
     67                        return;
     68
     69                var selection = new CKEDITOR.dom.selection( editor.document );
     70                selection.selectElement( element );
     71                // Walker searching for guardElements.
     72                var walker = new CKEDITOR.dom.walker( selection.getRanges()[ 0 ] );
     73
     74                var block;
     75                var sourceMargin = ( dir == 'rtl' ) ? 'left' : 'right';
     76                var targetMargin = ( sourceMargin == 'left' ) ? 'right' : 'left';
     77
     78                while ( block = walker.next() )
     79                {
     80                        if ( block.type == CKEDITOR.NODE_ELEMENT && block.getStyle( 'margin-' + sourceMargin ) )
     81                        {
     82                                var val = block.getStyle( 'margin-' + sourceMargin );
     83                                block.setStyle( 'margin-' + targetMargin, val );
     84                                block.removeStyle( 'margin-' + sourceMargin );
     85                        }
     86                }
     87        }
    5288
    5389        /**
    5490         *
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy