Ticket #5479: 5479_12.patch
File 5479_12.patch, 7.8 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 // IE below version 8 doesn't require this fix. 349 if ( CKEDITOR.env.ie6Compat || CKEDITOR.env.ie7Compat ) 350 return; 351 352 // All browsers are incapable to moving cursor out of certain non-exitable 353 // blocks (e.g. table, list, pre) at the end of document, make this happen by 354 // place a bogus node there, which would be later removed by dataprocessor. 355 var body = editor.document.getBody(), 356 enterMode = editor.config.enterMode, 357 selection = editor.getSelection(), 358 walkerRange = new CKEDITOR.dom.range( editor.document ), 359 walker = new CKEDITOR.dom.walker( walkerRange ); 360 361 walkerRange.selectNodeContents( body ); 362 walker.evaluator = function( node ) 363 { 364 return node.type == CKEDITOR.NODE_ELEMENT && nonExitable( node ); 365 }; 366 walker.guard = function( node, isMoveout ) 367 { 368 return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout ); 369 }; 370 371 if ( walker.previous() ) 372 { 373 editor.fire( 'updateSnapshot' ); 374 restoreDirty( editor ); 375 CKEDITOR.env.ie && selection && restoreSelection( selection ); 376 377 var paddingBlock; 378 if ( enterMode != CKEDITOR.ENTER_BR ) 379 paddingBlock = body.append( new CKEDITOR.dom.element( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ); 380 else 381 paddingBlock = body; 382 383 if ( !CKEDITOR.env.ie ) 384 paddingBlock.appendBogus(); 385 else if ( paddingBlock.is( 'body' ) ) 386 { 387 // IE need at least a node to show the cursor, use a zero height br 388 // to fly under the radar, additionally wrap the br element with an extra span , 389 // so selection change event could be easily captured when cursor move inside of it. 390 var paddingNode = CKEDITOR.dom.element.createFromHtml( '<span data-cke-bogus=1>' + 391 '<br data-cke-temp=1 style="line-height:0"/></span>', editor.document ); 392 paddingBlock.append( paddingNode ); 393 } 394 } 395 } 396 346 397 /** 347 398 * Auto-fixing block-less content by wrapping paragraph (#3190), prevent 348 399 * non-exitable-block by padding extra br.(#3189) … … 359 410 360 411 CKEDITOR.env.gecko && activateEditing( editor ); 361 412 413 // Remove the padding body node used in IE. 414 if ( CKEDITOR.env.ie ) 415 { 416 var start = range.collapsed && range.startContainer; 417 if ( start.type == CKEDITOR.NODE_ELEMENT && start.is( 'span') && start.data( 'cke-bogus') ) 418 { 419 range.moveToPosition( start, CKEDITOR.POSITION_BEFORE_START ); 420 start.remove(); 421 range.select(); 422 return; 423 } 424 } 425 362 426 // When enterMode set to block, we'll establing new paragraph only if we're 363 427 // selecting inline contents right under body. (#3657) 364 428 if ( enterMode != CKEDITOR.ENTER_BR … … 396 460 { 397 461 element = fixedBlock.getPrevious( isNotWhitespace ); 398 462 if ( element && 399 element.type == CKEDITOR.NODE_ELEMENT && 400 !nonExitable( element ) ) 463 element.type == CKEDITOR.NODE_ELEMENT ) 401 464 { 402 range.moveToElementEditEnd( element ); 403 fixedBlock.remove(); 404 } 405 } 406 } 465 if ( !nonExitable( element ) ) 466 { 467 range.moveToElementEditEnd( element ); 468 fixedBlock.remove(); 469 } 470 else if ( element.getDirection() ) 471 fixedBlock.setAttribute( 'dir', element.getDirection() ); 472 } 473 } 474 } 407 475 408 476 range.select(); 409 477 // Notify non-IE that selection has changed. … … 415 483 } 416 484 } 417 485 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 } 486 paddingBody( editor ); 487 } 449 488 450 489 CKEDITOR.plugins.add( 'wysiwygarea', 451 490 { … … 1082 1121 var title = editor.document.getElementsByTag( 'title' ).getItem( 0 ); 1083 1122 title.data( 'cke-title', editor.document.$.title ); 1084 1123 editor.document.$.title = frameLabel; 1124 paddingBody( editor ); 1085 1125 }); 1086 1126 1087 1127 // IE8 stricts mode doesn't have 'contentEditable' in effect … … 1165 1205 element.data( 'cke-editable', element.hasAttribute( 'contenteditable' ) ? 'true' : '1' ); 1166 1206 element.setAttribute( 'contentEditable', false ); 1167 1207 } 1208 1209 paddingBody( editor ); 1168 1210 }); 1169 1211 1170 }1171 });1212 } 1213 }); 1172 1214 1173 1215 // Fixing Firefox 'Back-Forward Cache' break design mode. (#4514) 1174 1216 if ( CKEDITOR.env.gecko )