Ticket #3240: 3240_2.patch
File 3240_2.patch, 2.6 KB (added by , 16 years ago) |
---|
-
_source/core/dom/node.js
435 435 // Handle non element nodes (don't support contains nor sourceIndex). 436 436 if ( this.type != CKEDITOR.NODE_ELEMENT || otherNode.type != CKEDITOR.NODE_ELEMENT ) 437 437 { 438 if ( $.parentNode == $other)438 if ( otherNode.isAncestorOf( this ) ) 439 439 return CKEDITOR.POSITION_IS_CONTAINED + CKEDITOR.POSITION_FOLLOWING; 440 else if ( $other.parentNode == $)440 else if ( this.isAncestorOf( otherNode ) ) 441 441 return CKEDITOR.POSITION_CONTAINS + CKEDITOR.POSITION_PRECEDING; 442 442 else if ( $.parentNode == $other.parentNode ) 443 443 return this.getIndex() < otherNode.getIndex() ? CKEDITOR.POSITION_PRECEDING : CKEDITOR.POSITION_FOLLOWING; … … 443 443 return this.getIndex() < otherNode.getIndex() ? CKEDITOR.POSITION_PRECEDING : CKEDITOR.POSITION_FOLLOWING; 444 444 else 445 445 { 446 $ = $.parentNode; 447 $other = $other.parentNode; 446 // It's safe here to wrapping the text node with temporary element, 447 // and compare the wrapper's 'sourceIndex' instead. (#3240) 448 var wrappers = []; 449 function wrap( node ) 450 { 451 var wrapper = CKEDITOR.document.createElement( 'span' ); 452 wrapper.insertBefore( node ); 453 wrapper.append( node ); 454 wrappers.push( wrapper ); 455 return wrapper.$; 456 } 457 function removeWrappers() 458 { 459 for ( var i = 0; i < wrappers.length ; i++ ) 460 { 461 var wrapper = wrappers[ i ]; 462 wrapper.getFirst().insertAfter( wrapper ); 463 wrapper.remove(); 464 } 465 } 466 467 var result = 468 ( $.sourceIndex || wrap( this ).sourceIndex < 469 $other.sourceIndex || wrap( otherNode ).sourceIndex ) ? 470 CKEDITOR.POSITION_PRECEDING : 471 CKEDITOR.POSITION_FOLLOWING; 472 removeWrappers(); 473 return result; 448 474 } 449 475 } 450 476 451 if ( $.contains( $other ) )452 return CKEDITOR.POSITION_CONTAINS + CKEDITOR.POSITION_PRECEDING;453 454 if ( $other.contains( $ ) )455 return CKEDITOR.POSITION_IS_CONTAINED + CKEDITOR.POSITION_FOLLOWING;456 457 477 if ( 'sourceIndex' in $ ) 458 478 { 459 479 return ( $.sourceIndex < 0 || $other.sourceIndex < 0 ) ? CKEDITOR.POSITION_DISCONNECTED : … … 516 536 } 517 537 return false; 518 538 }, 539 540 isAncestorOf : function( other ) 541 { 542 while( other && ( other = other.getParent() ) ) 543 { 544 if ( this.equals( other ) ) 545 return true; 546 } 547 return false; 548 }, 519 549 520 550 move : function( target, toStart ) 521 551 {