Ticket #6099: 6099_5.patch

File 6099_5.patch, 2.6 KB (added by Tobiasz Cudnik, 14 years ago)
  • _source/plugins/bidi/plugin.js

     
    99        var directSelectionGuardElements = {};
    1010        CKEDITOR.tools.extend( directSelectionGuardElements, guardElements, { tr:1, p:1, div:1, li:1 } );
    1111
    12         function onSelectionChange( evt )
     12        function setToolbarStates( evt )
    1313        {
    1414                var editor = evt.editor,
    1515                        path = evt.data.path;
     
    1818
    1919                useComputedState = useComputedState === undefined || useComputedState;
    2020
    21                 if ( useComputedState )
     21                // We can use computedState provided by the browser or traverse parents manually.
     22                if ( !useComputedState )
    2223                {
    23                         var selection = editor.getSelection(),
    24                                 ranges = selection.getRanges();
     24                        selectedElement = path.elements[ 0 ];
    2525
    26                         selectedElement = ranges && ranges[ 0 ].getEnclosedNode();
    27 
    28                         // If this is not our element of interest, apply to fully selected elements from guardElements.
    29                         if ( !selectedElement || selectedElement
    30                                         && !( selectedElement.type == CKEDITOR.NODE_ELEMENT && selectedElement.getName() in directSelectionGuardElements )
    31                                 )
    32                                 selectedElement = getFullySelected( selection, guardElements );
    33                 }
     26                        while ( !( selectedElement.getName() in directSelectionGuardElements || selectedElement.is( 'body' ) ) )
     27                        {
     28                                var parent = selectedElement.getParent();
     29                                if ( !parent )
     30                                        break;
     31                               
     32                                selectedElement = parent;
     33                        }
     34                }
    3435
    3536                selectedElement = selectedElement || path.block || path.blockLimit;
    3637
     
    4344
    4445                editor.getCommand( 'bidirtl' ).setState( selectionDir == 'rtl' ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
    4546                editor.getCommand( 'bidiltr' ).setState( selectionDir == 'ltr' ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
     47        }
    4648
     49        function handleMixedDirContent( evt )
     50        {
    4751                var chromeRoot = editor.container.getChild( 1 );
    48 
    49                 if ( selectionDir != editor.lang.dir )
     52                var node = evt.data.path.elements[ 0 ];
     53               
     54                if ( node && editor.lang.dir != evt.data.path.elements[ 0 ].getComputedStyle( 'direction' ) )
    5055                        chromeRoot.addClass( 'cke_mixed_dir_content' );
    5156                else
    5257                        chromeRoot.removeClass( 'cke_mixed_dir_content' );
     
    240245                        addButtonCommand( 'BidiLtr', lang.ltr, 'bidiltr', bidiCommand( 'ltr' ) );
    241246                        addButtonCommand( 'BidiRtl', lang.rtl, 'bidirtl', bidiCommand( 'rtl' ) );
    242247
    243                         editor.on( 'selectionChange', onSelectionChange );
     248                        editor.on( 'selectionChange', function( e )
     249                        {
     250                                setToolbarStates( e );
     251                                handleMixedDirContent( e );
     252                        });
    244253                }
    245254        });
    246255
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy