Ticket #4513: 4513_3.patch
File 4513_3.patch, 7.2 KB (added by , 14 years ago) |
---|
-
_source/plugins/link/dialogs/link.js
5 5 6 6 CKEDITOR.dialog.add( 'link', function( editor ) 7 7 { 8 var plugin = CKEDITOR.plugins.link; 8 9 // Handles the event when the "Target" selection box is changed. 9 10 var targetChanged = function() 10 11 { … … 93 94 94 95 var parseLink = function( editor, element ) 95 96 { 96 var href = element ? ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) :'',97 var href = ( element && ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) ) || '', 97 98 javascriptMatch, 98 99 emailMatch, 99 100 anchorMatch, … … 1130 1131 1131 1132 var editor = this.getParentEditor(), 1132 1133 selection = editor.getSelection(), 1133 ranges = selection.getRanges(), 1134 element = null, 1135 me = this; 1136 // Fill in all the relevant fields if there's already one link selected. 1137 if ( ranges.length == 1 ) 1138 { 1134 element = null; 1139 1135 1140 var rangeRoot = ranges[0].getCommonAncestor( true ); 1141 element = rangeRoot.getAscendant( 'a', true ); 1142 if ( element && element.getAttribute( 'href' ) ) 1143 { 1144 selection.selectElement( element ); 1145 } 1146 else if ( ( element = rangeRoot.getAscendant( 'img', true ) ) && 1147 element.getAttribute( '_cke_real_element_type' ) && 1148 element.getAttribute( '_cke_real_element_type' ) == 'anchor' ) 1149 { 1150 this.fakeObj = element; 1151 element = editor.restoreRealElement( this.fakeObj ); 1152 selection.selectElement( this.fakeObj ); 1153 } 1154 else 1155 element = null; 1156 } 1136 // Fill in all the relevant fields if there's already one link selected. 1137 if ( ( element = plugin.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) ) 1138 selection.selectElement( element ); 1139 else if ( ( element = selection.getSelectedElement() ) && element.is( 'img' ) 1140 && element.getAttribute( '_cke_real_element_type' ) 1141 && element.getAttribute( '_cke_real_element_type' ) == 'anchor' ) 1142 { 1143 this.fakeObj = element; 1144 element = editor.restoreRealElement( this.fakeObj ); 1145 selection.selectElement( this.fakeObj ); 1146 } 1147 else 1148 element = null; 1157 1149 1158 1150 this.setupContent( parseLink.apply( this, [ editor, element ] ) ); 1159 1151 }, -
_source/plugins/link/plugin.js
107 107 108 108 if ( !isAnchor ) 109 109 { 110 if ( !( element = element.getAscendant( 'a', true) ) )110 if ( !( element = CKEDITOR.plugins.link.getSelectedLink( editor ) ) ) 111 111 return null; 112 112 113 113 isAnchor = ( element.getAttribute( 'name' ) && !element.getAttribute( 'href' ) ); … … 147 147 requires : [ 'fakeobjects' ] 148 148 } ); 149 149 150 CKEDITOR.plugins.link = 151 { 152 /** 153 * Get the surrounding link element of current selection. 154 * @param editor 155 * @example CKEDITOR.plugins.link.getSelectedLink( editor ); 156 * The following selection will all return the link element. 157 * <pre> 158 * <a href="#">li^nk</a> 159 * <a href="#">[link]</a> 160 * text[<a href="#">link]</a> 161 * <a href="#">li[nk</a>] 162 * [<b><a href="#">li]nk</a></b>] 163 * [<a href="#"><b>li]nk</b></a> 164 * </pre> 165 */ 166 getSelectedLink : function( editor ) 167 { 168 var range; 169 try { range = editor.getSelection().getRanges()[ 0 ]; } 170 catch( e ) { return null; } 171 172 range.shrink(); 173 var root = range.getCommonAncestor(); 174 return root.getAscendant( 'a', true ); 175 } 176 177 }; 178 150 179 CKEDITOR.unlinkCommand = function(){}; 151 180 CKEDITOR.unlinkCommand.prototype = 152 181 { -
_source/core/dom/range.js
1235 1235 }, 1236 1236 1237 1237 /** 1238 * Descrease the range to make sure that boundaries 1239 * always anchor beside text nodes. 1240 */ 1241 shrink : function() 1242 { 1243 // Unable to shrink a collapsed range. 1244 if( this.collapsed ) 1245 return false; 1246 else 1247 { 1248 var walkerRange = this.clone(); 1249 1250 var startContainer = this.startContainer, 1251 endContainer = this.endContainer, 1252 startOffset = this.startOffset, 1253 endOffset = this.endOffset, 1254 collapsed = this.collapsed; 1255 1256 // Whether the start/end boundary is moveable. 1257 var moveStart = 1, 1258 moveEnd = 1; 1259 1260 if ( startContainer && startContainer.type == CKEDITOR.NODE_TEXT ) 1261 { 1262 if ( !startOffset ) 1263 walkerRange.setStartBefore( startContainer ); 1264 else if ( startOffset >= startContainer.getLength( ) ) 1265 walkerRange.setStartAfter( startContainer ); 1266 else 1267 { 1268 // Enlarge the range properly to avoid walker making 1269 // DOM changes caused by triming the text nodes later. 1270 walkerRange.setStartBefore( startContainer ); 1271 moveStart = 0; 1272 } 1273 } 1274 1275 if ( endContainer && endContainer.type == CKEDITOR.NODE_TEXT ) 1276 { 1277 if ( !endOffset ) 1278 walkerRange.setEndBefore( endContainer ); 1279 else if ( endOffset >= endContainer.getLength( ) ) 1280 walkerRange.setEndAfter( endContainer ); 1281 else 1282 { 1283 walkerRange.setEndAfter( endContainer ); 1284 moveEnd = 0; 1285 } 1286 } 1287 1288 var walker = new CKEDITOR.dom.walker( walkerRange ); 1289 walker.evaluator = function( node ) 1290 { 1291 return node.type == CKEDITOR.NODE_TEXT; 1292 }; 1293 1294 var currentElement; 1295 walker.guard = function( node, movingOut ) 1296 { 1297 // Stop when we've walked "through" an element. 1298 if( movingOut && node.equals( currentElement ) ) 1299 return false; 1300 1301 if( !movingOut && node.type == CKEDITOR.NODE_ELEMENT ) 1302 currentElement = node; 1303 }; 1304 1305 if( moveStart ) 1306 { 1307 var textStart = walker.next(); 1308 textStart && this.setStartBefore( textStart ); 1309 } 1310 1311 if( moveEnd ) 1312 { 1313 walker.reset(); 1314 var textEnd = walker.previous(); 1315 textEnd && this.setEndAfter( textEnd ); 1316 } 1317 1318 return !!( moveStart || moveEnd ); 1319 } 1320 }, 1321 1322 /** 1238 1323 * Inserts a node at the start of the range. The range will be expanded 1239 1324 * the contain the node. 1240 1325 */ -
_source/core/dom/walker.js
101 101 node = null; 102 102 } 103 103 else 104 node = ( guard ( node ) === false ) ?104 node = ( guard ( node, true ) === false ) ? 105 105 null : node.getPreviousSourceNode( true, type, guard ); 106 106 } 107 107 else … … 115 115 node = null; 116 116 } 117 117 else 118 node = ( guard ( range.startContainer ) === false ) ?118 node = ( guard ( range.startContainer, true ) === false ) ? 119 119 null : range.startContainer.getNextSourceNode( true, type, guard ) ; 120 120 } 121 121 }