Ticket #6099: 6099_8.patch
File 6099_8.patch, 3.0 KB (added by , 14 years ago) |
---|
-
_source/plugins/bidi/plugin.js
6 6 (function() 7 7 { 8 8 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 = {}; 10 12 CKEDITOR.tools.extend( directSelectionGuardElements, guardElements, { tr:1, p:1, div:1, li:1 } ); 13 CKEDITOR.tools.extend( allGuardElements, directSelectionGuardElements, { td:1 } ); 11 14 12 function onSelectionChange( e vt)15 function onSelectionChange( e ) 13 16 { 17 setToolbarStates( e ); 18 handleMixedDirContent( e ); 19 } 20 21 function setToolbarStates( evt ) 22 { 14 23 var editor = evt.editor, 15 24 path = evt.data.path; 16 25 var useComputedState = editor.config.useComputedState, … … 18 27 19 28 useComputedState = useComputedState === undefined || useComputedState; 20 29 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 ); 25 33 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 || selectedElement30 && !( selectedElement.type == CKEDITOR.NODE_ELEMENT && selectedElement.getName() in directSelectionGuardElements )31 )32 selectedElement = getFullySelected( selection, guardElements );33 }34 35 34 selectedElement = selectedElement || path.block || path.blockLimit; 36 35 37 36 if ( !selectedElement || selectedElement.getName() == 'body' ) … … 43 42 44 43 editor.getCommand( 'bidirtl' ).setState( selectionDir == 'rtl' ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF ); 45 44 editor.getCommand( 'bidiltr' ).setState( selectionDir == 'ltr' ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF ); 45 } 46 46 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' ) ) 50 54 chromeRoot.addClass( 'cke_mixed_dir_content' ); 51 55 else 52 56 chromeRoot.removeClass( 'cke_mixed_dir_content' ); 53 57 } 54 58 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 55 77 function switchDir( element, dir, editor, state ) 56 78 { 57 79 var dirBefore = element.getComputedStyle( 'direction' );