Ticket #4513: 4513.patch
File 4513.patch, 4.4 KB (added by , 14 years ago) |
---|
-
_source/plugins/link/dialogs/link.js
84 84 85 85 var parseLink = function( editor, element ) 86 86 { 87 var href = element ? ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) :'',87 var href = ( element && ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) ) || '', 88 88 emailMatch, 89 89 anchorMatch, 90 90 urlMatch, … … 351 351 return 'String.fromCharCode(' + encodedChars.join( ',' ) + ')'; 352 352 } 353 353 354 function getPartialSelectedElement( editor, tagName ) 355 { 356 try 357 { 358 var selection = editor.getSelection(), 359 ranges = selection.getRanges(), 360 range = ranges[0]; 361 362 /* Have to deal with the following cases: (#4513) 363 <a href="#">li^nk</a> 364 <a href="#">[link]</a> 365 text[<a href="#">link]</a> 366 <a href="#">li[nk</a>] 367 ... 368 */ 369 370 range.trim( false, false, true ); 371 372 var selectedStartNode = range.getTouchedStartNode(), 373 selectedEndNode = range.getTouchedEndNode(), 374 elementAtStart = selectedStartNode.getAscendant( tagName, true ), 375 elementAtEnd = selectedEndNode.getAscendant( tagName, true ); 376 377 if( elementAtStart.equals( elementAtEnd ) ) 378 return elementAtStart; 379 380 } 381 catch(er) 382 { 383 return null; 384 } 385 } 386 354 387 return { 355 388 title : editor.lang.link.title, 356 389 minWidth : 350, … … 1119 1152 1120 1153 var editor = this.getParentEditor(), 1121 1154 selection = editor.getSelection(), 1122 ranges = selection.getRanges(), 1123 element = null, 1124 me = this; 1125 // Fill in all the relevant fields if there's already one link selected. 1126 if ( ranges.length == 1 ) 1127 { 1155 element = null; 1128 1156 1129 var rangeRoot = ranges[0].getCommonAncestor( true ); 1130 element = rangeRoot.getAscendant( 'a', true ); 1131 if ( element && element.getAttribute( 'href' ) ) 1132 { 1133 selection.selectElement( element ); 1134 } 1135 else if ( ( element = rangeRoot.getAscendant( 'img', true ) ) && 1136 element.getAttribute( '_cke_real_element_type' ) && 1137 element.getAttribute( '_cke_real_element_type' ) == 'anchor' ) 1138 { 1139 this.fakeObj = element; 1140 element = editor.restoreRealElement( this.fakeObj ); 1141 selection.selectElement( this.fakeObj ); 1142 } 1143 else 1144 element = null; 1145 } 1157 // Fill in all the relevant fields if there's already one link selected. 1158 if ( ( element = getPartialSelectedElement( editor, 'a' ) ) && element.hasAttribute( 'href' ) ) 1159 selection.selectElement( element ); 1160 else if ( ( element = selection.getSelectedElement() ) && element.is( 'img' ) 1161 && element.getAttribute( '_cke_real_element_type' ) 1162 && element.getAttribute( '_cke_real_element_type' ) == 'anchor' ) 1163 { 1164 this.fakeObj = element; 1165 element = editor.restoreRealElement( this.fakeObj ); 1166 selection.selectElement( this.fakeObj ); 1167 } 1168 else 1169 element = null; 1146 1170 1147 1171 this.setupContent( parseLink.apply( this, [ editor, element ] ) ); 1148 1172 }, -
_source/core/dom/range.js
712 712 this.setEndAt( endNode, CKEDITOR.POSITION_AFTER_END ); 713 713 }, 714 714 715 trim : function( ignoreStart, ignoreEnd ) 715 /** 716 * Favor element as range containers over text node, 717 * optionally break text node into two when necessary. 718 * @param ignoreStart Avoid trimming at the front. 719 * @param ignoreEnd Avoid trimming at the end. 720 * @param noSplit Don't split up in middle of text node (No DOM change). 721 */ 722 trim : function( ignoreStart, ignoreEnd, noSplit ) 716 723 { 717 724 var startContainer = this.startContainer, 718 725 startOffset = this.startOffset, … … 736 743 } 737 744 // In other case, we split the text node and insert the new 738 745 // node at the split point. 739 else 746 else if( !noSplit ) 740 747 { 741 748 var nextText = startContainer.split( startOffset ); 742 749 … … 775 782 } 776 783 // In other case, we split the text node and insert the new 777 784 // node at the split point. 778 else 785 else if ( !noSplit ) 779 786 { 780 787 endContainer.split( endOffset ); 781 788