X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Flink%2Fplugin.js;h=26a8cb3be2ce39f9bd1c9b6e9242b785c87f3f41;hp=7993a0f30d60b9c9528b55a3131fd4f1d9be6f6b;hb=e7789c1ad838194d45eeee6ac2eb6e55f5cf35a1;hpb=059b4c2fef02528bf1af189f7996e80652faddfb diff --git a/_source/plugins/link/plugin.js b/_source/plugins/link/plugin.js index 7993a0f..26a8cb3 100644 --- a/_source/plugins/link/plugin.js +++ b/_source/plugins/link/plugin.js @@ -107,7 +107,7 @@ CKEDITOR.plugins.add( 'link', if ( !isAnchor ) { - if ( !( element = element.getAscendant( 'a', true ) ) ) + if ( !( element = CKEDITOR.plugins.link.getSelectedLink( editor ) ) ) return null; isAnchor = ( element.getAttribute( 'name' ) && !element.getAttribute( 'href' ) ); @@ -147,6 +147,35 @@ CKEDITOR.plugins.add( 'link', requires : [ 'fakeobjects' ] } ); +CKEDITOR.plugins.link = +{ + /** + * Get the surrounding link element of current selection. + * @param editor + * @example CKEDITOR.plugins.link.getSelectedLink( editor ); + * @since 3.2.1 + * The following selection will all return the link element. + *
+	 *  li^nk
+	 *  [link]
+	 *  text[link]
+	 *  li[nk]
+	 *  [li]nk]
+	 *  [li]nk
+	 * 
+ */ + getSelectedLink : function( editor ) + { + var range; + try { range = editor.getSelection().getRanges()[ 0 ]; } + catch( e ) { return null; } + + range.shrink( CKEDITOR.SHRINK_TEXT ); + var root = range.getCommonAncestor(); + return root.getAscendant( 'a', true ); + } +}; + CKEDITOR.unlinkCommand = function(){}; CKEDITOR.unlinkCommand.prototype = { @@ -178,7 +207,9 @@ CKEDITOR.unlinkCommand.prototype = selection.selectRanges( ranges ); editor.document.$.execCommand( 'unlink', false, null ); selection.selectBookmarks( bookmarks ); - } + }, + + startDisabled : true }; CKEDITOR.tools.extend( CKEDITOR.config,