Ticket #5910: 5910.patch
File 5910.patch, 4.8 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 { 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. 200 239 var indentClass = element.$.className.match( this.classNameRegex ), 201 202 203 204 205 206 240 indentStep = 0; 241 if ( indentClass ) 242 { 243 indentClass = indentClass[1]; 244 indentStep = this.indentClassMap[ indentClass ]; 245 } 207 246 208 209 210 211 212 213 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++; 214 253 215 254 if ( indentStep < 0 ) 216 255 return false; 217 256 218 219 257 indentStep = Math.min( indentStep, editor.config.indentClasses.length ); 258 indentStep = Math.max( indentStep, 0 ); 220 259 var className = CKEDITOR.tools.ltrim( element.$.className.replace( this.classNameRegex, '' ) ); 221 260 if ( indentStep < 1 ) 222 261 element.$.className = className; 223 262 else 224 263 element.addClass( editor.config.indentClasses[ indentStep - 1 ] ); 225 226 227 264 } 265 else 266 { 228 267 var currentOffset = parseInt( element.getStyle( this.indentCssProperty ), 10 ); 229 230 231 268 if ( isNaN( currentOffset ) ) 269 currentOffset = 0; 270 currentOffset += ( this.name == 'indent' ? 1 : -1 ) * editor.config.indentOffset; 232 271 233 272 if ( currentOffset < 0 ) 234 273 return false; 235 274 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 238 278 element.setStyle( this.indentCssProperty, currentOffset ? currentOffset + editor.config.indentUnit : '' ); 279 239 280 if ( element.getAttribute( 'style' ) === '' ) 240 281 element.removeAttribute( 'style' ); 241 282 } 242 283 243 284 return true; 244 285 } 245 286 246 287 function indentCommand( editor, name ) 247 288 { … … 344 385 }); 345 386 346 387 // Register the state changing handlers. 388 editor.on( 'selectionChange', onSelectionChangeUpdateDir ); 347 389 editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, indent ) ); 348 390 editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, outdent ) ); 349 391