Ticket #5910: 5910_2.patch
File 5910_2.patch, 5.7 KB (added by , 14 years ago) |
---|
-
_source/plugins/indent/plugin.js
37 37 if ( !firstBlock ) 38 38 return setState.call( this, editor, CKEDITOR.TRISTATE_DISABLED ); 39 39 40 // Fix reference to command property (by redundant copy). 41 this.indentCssProperty = editor._.commands.indent.indentCssProperty; 42 40 43 if ( this.useIndentClasses ) 41 44 { 42 45 var indentClass = firstBlock.$.className.match( this.classNameRegex ), … … 62 65 } 63 66 } 64 67 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 65 100 function indentList( editor, range, listNode ) 66 101 { 67 102 // Our starting and ending points of the range might be inside some blocks under a list item... … … 183 218 184 219 function indentBlock( editor, range ) 185 220 { 221 // Fix reference to command property (by redundant copy). 222 this.indentCssProperty = editor._.commands.indent.indentCssProperty; 223 186 224 var iterator = range.createIterator(), 187 225 enterMode = editor.config.enterMode; 188 226 iterator.enforceRealBlocks = true; … … 193 231 } 194 232 195 233 function indentElement( editor, element ) 196 { 197 if ( this.useIndentClasses ) 198 { 234 { 235 if ( this.useIndentClasses ) 236 { 237 if ( this.useIndentClasses ) 238 { 199 239 // Transform current class name to indent step index. 200 240 var indentClass = element.$.className.match( this.classNameRegex ), 201 241 indentStep = 0; … … 233 273 if ( currentOffset < 0 ) 234 274 return false; 235 275 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' ); 241 301 } 242 302 243 303 return true; 244 304 } 305 } 245 306 246 307 function indentCommand( editor, name ) 247 308 { … … 344 405 }); 345 406 346 407 // Register the state changing handlers. 408 editor.on( 'selectionChange', onSelectionChangeUpdateDir ); 347 409 editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, indent ) ); 348 410 editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, outdent ) ); 349 411 -
_source/plugins/bidi/plugin.js
40 40 * 41 41 * @param {!CKEDITOR.dom.element} element 42 42 */ 43 43 44 function switchDir( element, dir, editor ) 44 45 { 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 } 47 59 else 60 { 48 61 element.setAttribute( 'dir', dir ); 49 62 63 if ( dir != editorDir ) 64 switchMargin = dir; 65 } 66 50 67 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 } 52 91 53 92 /** 54 93 *