Ticket #5910: 5910_2.patch

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

     
    3737                if ( !firstBlock )
    3838                        return setState.call( this, editor, CKEDITOR.TRISTATE_DISABLED );
    3939
     40                // Fix reference to command property (by redundant copy).
     41                this.indentCssProperty = editor._.commands.indent.indentCssProperty;
     42
    4043                if ( this.useIndentClasses )
    4144                {
    4245                        var indentClass = firstBlock.$.className.match( this.classNameRegex ),
     
    6265                }
    6366        }
    6467
     68        function onSelectionChangeUpdateDir( evt )
     69        {
     70                var editor = evt.editor;
     71
     72                editor._.commands.indent.indentCssProperty = ( getDirFromSelection( editor ) == 'ltr' )
     73                        ? 'margin-left' : 'margin-right';
     74        }
     75
     76        function getDirFromSelection( editor )
     77        {
     78                var selection = editor.getSelection(),
     79                        enterMode = editor.config.enterMode,
     80                        ranges = selection && selection.getRanges();
     81
     82                var commonAncestor = ranges && ranges[0].getCommonAncestor( true );
     83
     84                var elementCheck = commonAncestor,
     85                        dir = editor.config.contentsLangDirection;
     86               
     87                while ( elementCheck )
     88                {
     89                        if ( elementCheck.type == CKEDITOR.NODE_ELEMENT && elementCheck.hasAttribute( 'dir' ) )
     90                        {
     91                                dir = elementCheck.getAttribute( 'dir' );
     92                                break;
     93                        }
     94                        elementCheck = elementCheck.getParent();
     95                }
     96
     97                return dir;
     98        }
     99
    65100        function indentList( editor, range, listNode )
    66101        {
    67102                // Our starting and ending points of the range might be inside some blocks under a list item...
     
    183218
    184219        function indentBlock( editor, range )
    185220        {
     221                // Fix reference to command property (by redundant copy).
     222                this.indentCssProperty = editor._.commands.indent.indentCssProperty;
     223
    186224                var iterator = range.createIterator(),
    187225                        enterMode = editor.config.enterMode;
    188226                iterator.enforceRealBlocks = true;
     
    193231        }
    194232
    195233        function indentElement( editor, element )
    196                 {
    197                         if ( this.useIndentClasses )
    198                         {
     234        {
     235                if ( this.useIndentClasses )
     236                {
     237                        if ( this.useIndentClasses )
     238                        {
    199239                                // Transform current class name to indent step index.
    200240                        var indentClass = element.$.className.match( this.classNameRegex ),
    201241                                        indentStep = 0;
     
    233273                        if ( currentOffset < 0 )
    234274                                return false;
    235275
    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' );
     276                        currentOffset = Math.max( currentOffset, 0 );
     277                        currentOffset = Math.ceil( currentOffset / editor.config.indentOffset ) * editor.config.indentOffset;
     278
     279                                // Determine text direction for this element.
     280                                var editorDir = ( editor.config.contentsLangDirection == 'ui' )
     281                                        ? editor.lang.dir : editor.config.contentsLangDirection;
     282                                var dir = element.hasAttribute && element.hasAttribute( 'dir' ) && element.getAttribute( 'dir' ) || editorDir;
     283
     284                                var parent = element.getParent();
     285                                while ( parent )
     286                                {
     287                                        if ( parent.hasAttribute && parent.hasAttribute( 'dir' ) )
     288                                        {
     289                                                dir = parent.getAttribute( 'dir' );
     290                                                break;
     291                                        }
     292                                        parent = parent.getParent();
     293                                }
     294                                dir = dir.toLowerCase();
     295
     296                                var marginDir = ( dir == 'ltr' ) ? 'left' : 'right';
     297                                element.setStyle( 'margin-' + marginDir, currentOffset ? currentOffset + editor.config.indentUnit : '' );
     298
     299                                if ( element.getAttribute( 'style' ) === '' )
     300                                        element.removeAttribute( 'style' );
    241301                        }
    242302
    243303                return true;
    244304                }
     305        }
    245306
    246307        function indentCommand( editor, name )
    247308        {
     
    344405                                });
    345406
    346407                        // Register the state changing handlers.
     408                        editor.on( 'selectionChange', onSelectionChangeUpdateDir );
    347409                        editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, indent ) );
    348410                        editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, outdent ) );
    349411
  • _source/plugins/bidi/plugin.js

     
    4040         *
    4141         * @param {!CKEDITOR.dom.element} element
    4242         */
     43
    4344        function switchDir( element, dir, editor )
    4445        {
    45                 if ( element.hasAttribute( 'dir' ) && element.getAttribute( 'dir' ).toLowerCase()  == dir )
    46                         element.removeAttribute( 'dir' );
     46                var switchMargin,
     47                        editorDir = ( editor.config.contentsLangDirection == 'ui' )
     48                                ? editor.lang.dir : editor.config.contentsLangDirection;
     49
     50                if ( element.hasAttribute( 'dir' ) )
     51                {
     52                        if ( element.getAttribute( 'dir' ).toLowerCase() == dir )
     53                        {
     54                                if ( dir != editorDir )
     55                                        switchMargin = dir == 'rtl' ? 'ltr' : 'rtl';
     56                                element.removeAttribute( 'dir' );
     57                        }
     58                }
    4759                else
     60                {
    4861                        element.setAttribute( 'dir', dir );
    4962
     63                        if ( dir != editorDir )
     64                                switchMargin = dir;
     65                }
     66
    5067                editor.forceNextSelectionCheck();
    51         }
     68
     69                if ( !switchMargin )
     70                        return;
     71
     72                var selection = new CKEDITOR.dom.selection( editor.document );
     73                selection.selectElement( element );
     74                // Walker searching for guardElements.
     75                var walker = new CKEDITOR.dom.walker( selection.getRanges()[ 0 ] );
     76
     77                var block;
     78                var sourceMargin = ( dir == 'rtl' ) ? 'left' : 'right';
     79                var targetMargin = ( sourceMargin == 'left' ) ? 'right' : 'left';
     80
     81                while ( block = walker.next() )
     82                {
     83                        if ( block.type == CKEDITOR.NODE_ELEMENT && block.getStyle( 'margin-' + sourceMargin ) )
     84                        {
     85                                var val = block.getStyle( 'margin-' + sourceMargin );
     86                                block.setStyle( 'margin-' + targetMargin, val );
     87                                block.removeStyle( 'margin-' + sourceMargin );
     88                        }
     89                }
     90        }
    5291
    5392        /**
    5493         *
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy