Ticket #5910: 5910.patch

File 5910.patch, 4.8 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                         {
    199                                 // Transform current class name to indent step index.
     234        {
     235                console.log( this.indentCssProperty );
     236                if ( this.useIndentClasses )
     237                {
     238                        // Transform current class name to indent step index.
    200239                        var indentClass = element.$.className.match( this.classNameRegex ),
    201                                         indentStep = 0;
    202                                 if ( indentClass )
    203                                 {
    204                                         indentClass = indentClass[1];
    205                                         indentStep = this.indentClassMap[ indentClass ];
    206                                 }
     240                                indentStep = 0;
     241                        if ( indentClass )
     242                        {
     243                                indentClass = indentClass[1];
     244                                indentStep = this.indentClassMap[ indentClass ];
     245                        }
    207246
    208                                 // Operate on indent step index, transform indent step index back to class
    209                                 // name.
    210                                 if ( this.name == 'outdent' )
    211                                         indentStep--;
    212                                 else
    213                                         indentStep++;
     247                        // Operate on indent step index, transform indent step index back to class
     248                        // name.
     249                        if ( this.name == 'outdent' )
     250                                indentStep--;
     251                        else
     252                                indentStep++;
    214253
    215254                        if ( indentStep < 0 )
    216255                                return false;
    217256
    218                                 indentStep = Math.min( indentStep, editor.config.indentClasses.length );
    219                                 indentStep = Math.max( indentStep, 0 );
     257                        indentStep = Math.min( indentStep, editor.config.indentClasses.length );
     258                        indentStep = Math.max( indentStep, 0 );
    220259                        var className = CKEDITOR.tools.ltrim( element.$.className.replace( this.classNameRegex, '' ) );
    221                                 if ( indentStep < 1 )
     260                        if ( indentStep < 1 )
    222261                                element.$.className = className;
    223                                 else
     262                        else
    224263                                element.addClass( editor.config.indentClasses[ indentStep - 1 ] );
    225                         }
    226                         else
    227                         {
     264                }
     265                else
     266                {
    228267                        var currentOffset = parseInt( element.getStyle( this.indentCssProperty ), 10 );
    229                                 if ( isNaN( currentOffset ) )
    230                                         currentOffset = 0;
    231                                 currentOffset += ( this.name == 'indent' ? 1 : -1 ) * editor.config.indentOffset;
     268                        if ( isNaN( currentOffset ) )
     269                                currentOffset = 0;
     270                        currentOffset += ( this.name == 'indent' ? 1 : -1 ) * editor.config.indentOffset;
    232271
    233272                        if ( currentOffset < 0 )
    234273                                return false;
    235274
    236                                 currentOffset = Math.max( currentOffset, 0 );
    237                                 currentOffset = Math.ceil( currentOffset / editor.config.indentOffset ) * editor.config.indentOffset;
     275                        currentOffset = Math.max( currentOffset, 0 );
     276                        currentOffset = Math.ceil( currentOffset / editor.config.indentOffset ) * editor.config.indentOffset;
     277
    238278                        element.setStyle( this.indentCssProperty, currentOffset ? currentOffset + editor.config.indentUnit : '' );
     279
    239280                        if ( element.getAttribute( 'style' ) === '' )
    240281                                element.removeAttribute( 'style' );
    241                         }
     282                }
    242283
    243284                return true;
    244                 }
     285        }
    245286
    246287        function indentCommand( editor, name )
    247288        {
     
    344385                                });
    345386
    346387                        // Register the state changing handlers.
     388                        editor.on( 'selectionChange', onSelectionChangeUpdateDir );
    347389                        editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, indent ) );
    348390                        editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, outdent ) );
    349391
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy