Ticket #5479: 5479_11.patch
File 5479_11.patch, 7.3 KB (added by , 13 years ago) |
---|
-
_source/core/dom/element.js
234 234 this.append( new CKEDITOR.dom.text( text ) ); 235 235 }, 236 236 237 appendBogus : function()238 {239 var lastChild = this.getLast() ;240 241 // Ignore empty/spaces text.242 while ( lastChild && lastChild.type == CKEDITOR.NODE_TEXT && !CKEDITOR.tools.rtrim( lastChild.getText() ) )243 lastChild = lastChild.getPrevious();244 if ( !lastChild || !lastChild.is || !lastChild.is( 'br' ) )245 {246 var bogus = CKEDITOR.env.opera ?247 this.getDocument().createText('') :248 this.getDocument().createElement( 'br' );249 250 CKEDITOR.env.gecko && bogus.setAttribute( 'type', '_moz' );251 252 this.append( bogus );253 }254 },255 256 237 /** 257 238 * Retrieve block element's filler node if existed. 258 239 */ -
_source/core/dom/walker.js
449 449 return false; 450 450 }; 451 451 452 // Append a filler node at the end of an element if not exists. 453 CKEDITOR.dom.element.prototype.appendBogus = function() 454 { 455 var lastChild = this.getLast( fillerEvaluator ) ; 456 if ( !lastChild || !lastChild.is || !lastChild.is( 'br' ) ) 457 { 458 var bogus = CKEDITOR.env.opera ? 459 this.getDocument().createText('') : 460 this.getDocument().createElement( 'br' ); 461 462 CKEDITOR.env.gecko && bogus.setAttribute( 'type', '_moz' ); 463 464 this.append( bogus ); 465 } 466 }; 467 468 452 469 })(); -
_source/plugins/wysiwygarea/plugin.js
38 38 39 39 insertFunc.call( this, evt.data ); 40 40 41 paddingBody( this ); 42 41 43 // Save snaps after the whole execution completed. 42 44 // This's a workaround for make DOM modification's happened after 43 45 // 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents' … … 304 306 return block.getOuterHtml().match( emptyParagraphRegexp ); 305 307 } 306 308 307 isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true );308 309 309 // Gecko need a key event to 'wake up' the editing 310 310 // ability when document is empty.(#3864, #5781) 311 311 function activateEditing( editor ) … … 343 343 } 344 344 } 345 345 346 function paddingBody( editor ) 347 { 348 // All browsers are incapable to moving cursor out of certain non-exitable 349 // blocks (e.g. table, list, pre) at the end of document, make this happen by 350 // place a bogus node there, which would be later removed by dataprocessor. 351 var body = editor.document.getBody(), 352 enterMode = editor.config.enterMode, 353 selection = editor.getSelection(), 354 walkerRange = new CKEDITOR.dom.range( editor.document ), 355 walker = new CKEDITOR.dom.walker( walkerRange ); 356 357 walkerRange.selectNodeContents( body ); 358 walker.evaluator = function( node ) 359 { 360 return node.type == CKEDITOR.NODE_ELEMENT && nonExitable( node ); 361 }; 362 walker.guard = function( node, isMoveout ) 363 { 364 return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout ); 365 }; 366 367 if ( walker.previous() ) 368 { 369 editor.fire( 'updateSnapshot' ); 370 restoreDirty( editor ); 371 CKEDITOR.env.ie && selection && restoreSelection( selection ); 372 373 var paddingBlock; 374 if ( enterMode != CKEDITOR.ENTER_BR ) 375 paddingBlock = body.append( new CKEDITOR.dom.element( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ); 376 else 377 paddingBlock = body; 378 379 if ( !CKEDITOR.env.ie ) 380 paddingBlock.appendBogus(); 381 else if ( paddingBlock.is( 'body' ) ) 382 { 383 // IE need at least a node to show the cursor, use a zero height br 384 // to fly under the radar, additionally wrap the br element with an extra span , 385 // so selection change event could be easily captured when cursor move inside of it. 386 var paddingNode = CKEDITOR.dom.element.createFromHtml( '<span data-cke-bogus=1>' + 387 '<br data-cke-temp=1 style="line-height:0"/></span>', editor.document ); 388 paddingBlock.append( paddingNode ); 389 } 390 } 391 } 392 346 393 /** 347 394 * Auto-fixing block-less content by wrapping paragraph (#3190), prevent 348 395 * non-exitable-block by padding extra br.(#3189) … … 359 406 360 407 CKEDITOR.env.gecko && activateEditing( editor ); 361 408 409 // Remove the padding body node used in IE. 410 if ( CKEDITOR.env.ie ) 411 { 412 var start = range.collapsed && range.startContainer; 413 if ( start.type == CKEDITOR.NODE_ELEMENT && start.is( 'span') && start.data( 'cke-bogus') ) 414 { 415 range.moveToPosition( start, CKEDITOR.POSITION_BEFORE_START ); 416 start.remove(); 417 range.select(); 418 return; 419 } 420 } 421 362 422 // When enterMode set to block, we'll establing new paragraph only if we're 363 423 // selecting inline contents right under body. (#3657) 364 424 if ( enterMode != CKEDITOR.ENTER_BR … … 396 456 { 397 457 element = fixedBlock.getPrevious( isNotWhitespace ); 398 458 if ( element && 399 element.type == CKEDITOR.NODE_ELEMENT && 400 !nonExitable( element ) ) 459 element.type == CKEDITOR.NODE_ELEMENT ) 401 460 { 402 range.moveToElementEditEnd( element ); 403 fixedBlock.remove(); 404 } 405 } 406 } 461 if ( !nonExitable( element ) ) 462 { 463 range.moveToElementEditEnd( element ); 464 fixedBlock.remove(); 465 } 466 else if ( element.getDirection() ) 467 fixedBlock.setAttribute( 'dir', element.getDirection() ); 468 } 469 } 470 } 407 471 408 472 range.select(); 409 473 // Notify non-IE that selection has changed. … … 415 479 } 416 480 } 417 481 418 // All browsers are incapable to moving cursor out of certain non-exitable 419 // blocks (e.g. table, list, pre) at the end of document, make this happen by 420 // place a bogus node there, which would be later removed by dataprocessor. 421 var walkerRange = new CKEDITOR.dom.range( editor.document ), 422 walker = new CKEDITOR.dom.walker( walkerRange ); 423 walkerRange.selectNodeContents( body ); 424 walker.evaluator = function( node ) 425 { 426 return node.type == CKEDITOR.NODE_ELEMENT && ( node.getName() in nonExitableElementNames ); 427 }; 428 walker.guard = function( node, isMoveout ) 429 { 430 return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout ); 431 }; 432 433 if ( walker.previous() ) 434 { 435 editor.fire( 'updateSnapshot' ); 436 restoreDirty( editor ); 437 CKEDITOR.env.ie && restoreSelection( selection ); 438 439 var paddingBlock; 440 if ( enterMode != CKEDITOR.ENTER_BR ) 441 paddingBlock = body.append( new CKEDITOR.dom.element( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ); 442 else 443 paddingBlock = body; 444 445 if ( !CKEDITOR.env.ie ) 446 paddingBlock.appendBogus(); 447 } 448 } 482 paddingBody( editor ); 483 } 449 484 450 485 CKEDITOR.plugins.add( 'wysiwygarea', 451 486 { … … 1082 1117 var title = editor.document.getElementsByTag( 'title' ).getItem( 0 ); 1083 1118 title.data( 'cke-title', editor.document.$.title ); 1084 1119 editor.document.$.title = frameLabel; 1120 paddingBody( editor ); 1085 1121 }); 1086 1122 1087 1123 // IE8 stricts mode doesn't have 'contentEditable' in effect