Ticket #4513: 4513_2.patch
File 4513_2.patch, 5.3 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 { … … 92 93 93 94 var parseLink = function( editor, element ) 94 95 { 95 var href = element ? ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) :'',96 var href = ( element && ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) ) || '', 96 97 emailMatch, 97 98 anchorMatch, 98 99 urlMatch, … … 1127 1128 1128 1129 var editor = this.getParentEditor(), 1129 1130 selection = editor.getSelection(), 1130 ranges = selection.getRanges(), 1131 element = null, 1132 me = this; 1133 // Fill in all the relevant fields if there's already one link selected. 1134 if ( ranges.length == 1 ) 1135 { 1131 element = null; 1136 1132 1137 var rangeRoot = ranges[0].getCommonAncestor( true ); 1138 element = rangeRoot.getAscendant( 'a', true ); 1139 if ( element && element.getAttribute( 'href' ) ) 1140 { 1141 selection.selectElement( element ); 1142 } 1143 else if ( ( element = rangeRoot.getAscendant( 'img', true ) ) && 1144 element.getAttribute( '_cke_real_element_type' ) && 1145 element.getAttribute( '_cke_real_element_type' ) == 'anchor' ) 1146 { 1147 this.fakeObj = element; 1148 element = editor.restoreRealElement( this.fakeObj ); 1149 selection.selectElement( this.fakeObj ); 1150 } 1151 else 1152 element = null; 1153 } 1133 // Fill in all the relevant fields if there's already one link selected. 1134 if ( ( element = plugin.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) ) 1135 selection.selectElement( element ); 1136 else if ( ( element = selection.getSelectedElement() ) && element.is( 'img' ) 1137 && element.getAttribute( '_cke_real_element_type' ) 1138 && element.getAttribute( '_cke_real_element_type' ) == 'anchor' ) 1139 { 1140 this.fakeObj = element; 1141 element = editor.restoreRealElement( this.fakeObj ); 1142 selection.selectElement( this.fakeObj ); 1143 } 1144 else 1145 element = null; 1154 1146 1155 1147 this.setupContent( parseLink.apply( this, [ editor, element ] ) ); 1156 1148 }, -
_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 link element under current selection. 154 * @param editor 155 */ 156 getSelectedLink : function( editor ) 157 { 158 var selection = editor.getSelection(), 159 bookmarks = selection.createBookmarks(), 160 ranges = selection.getRanges(), 161 range = ranges[0], 162 link; 163 164 link = range.getSurroundingElement( 'a' ); 165 selection.selectBookmarks( bookmarks ); 166 167 return link; 168 } 169 170 }; 171 150 172 CKEDITOR.unlinkCommand = function(){}; 151 173 CKEDITOR.unlinkCommand.prototype = 152 174 { -
_source/core/dom/range.js
1707 1707 return container ; 1708 1708 1709 1709 return container.getChild( this.endOffset - 1 ) || container ; 1710 } 1711 }; 1710 }, 1711 1712 /** 1713 * Retrieve the element that either surround or touch the boundary of the range. 1714 * Note: This method may result in fragile text nodes. 1715 * @param tagName 1716 * @example 1717 * var link = range.getSurroundingElement( 'a' ); 1718 * <pre> 1719 * <a href="#">li^nk</a> 1720 * <a href="#">[link]</a> 1721 * text[<a href="#">link]</a> 1722 * <a href="#">li[nk</a>] 1723 * [<b><a href="#">li]nk</a></b>] 1724 * [<a href="#"><b>li]nk</b></a> 1725 * </pre> 1726 */ 1727 getSurroundingElement : function( tagName ) 1728 { 1729 var surround; 1730 1731 if( this.collapsed ) 1732 surround = this.startContainer.getAscendant( tagName, true ); 1733 else 1734 { 1735 var walker = new CKEDITOR.dom.walker( this ); 1736 1737 walker.evaluator = function( node ) 1738 { 1739 if ( node.type == CKEDITOR.NODE_TEXT ) 1740 { 1741 var ascendant = node.getAscendant( tagName ); 1742 if ( ascendant && ( !surround || ascendant.equals( surround ) ) ) 1743 { 1744 surround = ascendant; 1745 return true; 1746 } 1747 else 1748 return ( surround = false ); 1749 } 1750 }; 1751 1752 walker.guard = function() 1753 { 1754 return surround !== false; 1755 }; 1756 1757 // Walk through all enclosed text nodes that are parts of the *same* element. 1758 walker.checkForward(); 1759 1760 } 1761 return surround || null; 1762 } 1763 }; 1712 1764 })(); 1713 1765 1714 1766 CKEDITOR.POSITION_AFTER_START = 1; // <element>^contents</element> "^text"