Ticket #4513: 4513_5.patch
| File 4513_5.patch, 4.0 KB (added by garry.yao, 3 years ago) |
|---|
-
_source/plugins/link/dialogs/link.js
1 /* 1 /* 2 2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. 3 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 4 */ 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, … … 1136 1137 1137 1138 var editor = this.getParentEditor(), 1138 1139 selection = editor.getSelection(), 1139 ranges = selection.getRanges(), 1140 element = null, 1141 me = this; 1142 // Fill in all the relevant fields if there's already one link selected. 1143 if ( ranges.length == 1 ) 1144 { 1140 element = null; 1145 1141 1146 var rangeRoot = ranges[0].getCommonAncestor( true ); 1147 element = rangeRoot.getAscendant( 'a', true ); 1148 if ( element && element.getAttribute( 'href' ) ) 1149 { 1150 selection.selectElement( element ); 1151 } 1152 else if ( ( element = rangeRoot.getAscendant( 'img', true ) ) && 1153 element.getAttribute( '_cke_real_element_type' ) && 1154 element.getAttribute( '_cke_real_element_type' ) == 'anchor' ) 1155 { 1156 this.fakeObj = element; 1157 element = editor.restoreRealElement( this.fakeObj ); 1158 selection.selectElement( this.fakeObj ); 1159 } 1160 else 1161 element = null; 1162 } 1142 // Fill in all the relevant fields if there's already one link selected. 1143 if ( ( element = plugin.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) ) 1144 selection.selectElement( element ); 1145 else if ( ( element = selection.getSelectedElement() ) && element.is( 'img' ) 1146 && element.getAttribute( '_cke_real_element_type' ) 1147 && element.getAttribute( '_cke_real_element_type' ) == 'anchor' ) 1148 { 1149 this.fakeObj = element; 1150 element = editor.restoreRealElement( this.fakeObj ); 1151 selection.selectElement( this.fakeObj ); 1152 } 1153 else 1154 element = null; 1163 1155 1164 1156 this.setupContent( parseLink.apply( this, [ editor, element ] ) ); 1165 1157 }, -
_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 * @since 3.2.1 157 * The following selection will all return the link element. 158 * <pre> 159 * <a href="#">li^nk</a> 160 * <a href="#">[link]</a> 161 * text[<a href="#">link]</a> 162 * <a href="#">li[nk</a>] 163 * [<b><a href="#">li]nk</a></b>] 164 * [<a href="#"><b>li]nk</b></a> 165 * </pre> 166 */ 167 getSelectedLink : function( editor ) 168 { 169 var range; 170 try { range = editor.getSelection().getRanges()[ 0 ]; } 171 catch( e ) { return null; } 172 173 range.shrink( CKEDITOR.SHRINK_TEXT ); 174 var root = range.getCommonAncestor(); 175 return root.getAscendant( 'a', true ); 176 } 177 }; 178 150 179 CKEDITOR.unlinkCommand = function(){}; 151 180 CKEDITOR.unlinkCommand.prototype = 152 181 {
