Ticket #6099: 6099_8.patch

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

     
    66(function()
    77{
    88        var guardElements = { table:1, ul:1, ol:1, blockquote:1, div:1 },
    9                 directSelectionGuardElements = {};
     9                directSelectionGuardElements = {},
     10                // All guard elements which can have a direction applied on them.
     11                allGuardElements = {};
    1012        CKEDITOR.tools.extend( directSelectionGuardElements, guardElements, { tr:1, p:1, div:1, li:1 } );
     13        CKEDITOR.tools.extend( allGuardElements, directSelectionGuardElements, { td:1 } );
    1114
    12         function onSelectionChange( evt )
     15        function onSelectionChange( e )
    1316        {
     17                setToolbarStates( e );
     18                handleMixedDirContent( e );
     19        }
     20
     21        function setToolbarStates( evt )
     22        {
    1423                var editor = evt.editor,
    1524                        path = evt.data.path;
    1625                var useComputedState = editor.config.useComputedState,
     
    1827
    1928                useComputedState = useComputedState === undefined || useComputedState;
    2029
    21                 if ( useComputedState )
    22                 {
    23                         var selection = editor.getSelection(),
    24                                 ranges = selection.getRanges();
     30                // We can use computedState provided by the browser or traverse parents manually.
     31                if ( !useComputedState )
     32                        selectedElement = getElementForDirection( path.lastElement );
    2533
    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                 }
    34 
    3534                selectedElement = selectedElement || path.block || path.blockLimit;
    3635
    3736                if ( !selectedElement || selectedElement.getName() == 'body' )
     
    4342
    4443                editor.getCommand( 'bidirtl' ).setState( selectionDir == 'rtl' ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
    4544                editor.getCommand( 'bidiltr' ).setState( selectionDir == 'ltr' ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
     45        }
    4646
    47                 var chromeRoot = editor.container.getChild( 1 );
    48 
    49                 if ( selectionDir != editor.lang.dir )
     47        function handleMixedDirContent( evt )
     48        {
     49                var editor = evt.editor,
     50                        chromeRoot = editor.container.getChild( 1 ),
     51                        directionNode = getElementForDirection( evt.data.path.lastElement );
     52               
     53                if ( directionNode && editor.lang.dir != directionNode.getComputedStyle( 'direction' ) )
    5054                        chromeRoot.addClass( 'cke_mixed_dir_content' );
    5155                else
    5256                        chromeRoot.removeClass( 'cke_mixed_dir_content' );
    5357        }
    5458
     59        /**
     60         * Returns element with possibility of applying the direction.
     61         * @param node
     62         */
     63        function getElementForDirection( node )
     64        {
     65                while ( node && !( node.getName() in allGuardElements || node.is( 'body' ) ) )
     66                {
     67                        var parent = node.getParent();
     68                        if ( !parent )
     69                                break;
     70
     71                        node = parent;
     72                }
     73
     74                return node;
     75        }
     76
    5577        function switchDir( element, dir, editor, state )
    5678        {
    5779                var dirBefore = element.getComputedStyle( 'direction' );
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy