+CKEDITOR.plugins.link =\r
+{\r
+ /**\r
+ * Get the surrounding link element of current selection.\r
+ * @param editor\r
+ * @example CKEDITOR.plugins.link.getSelectedLink( editor );\r
+ * @since 3.2.1\r
+ * The following selection will all return the link element.\r
+ * <pre>\r
+ * <a href="#">li^nk</a>\r
+ * <a href="#">[link]</a>\r
+ * text[<a href="#">link]</a>\r
+ * <a href="#">li[nk</a>]\r
+ * [<b><a href="#">li]nk</a></b>]\r
+ * [<a href="#"><b>li]nk</b></a>\r
+ * </pre>\r
+ */\r
+ getSelectedLink : function( editor )\r
+ {\r
+ try\r
+ {\r
+ var selection = editor.getSelection();\r
+ if ( selection.getType() == CKEDITOR.SELECTION_ELEMENT )\r
+ {\r
+ var selectedElement = selection.getSelectedElement();\r
+ if ( selectedElement.is( 'a' ) )\r
+ return selectedElement;\r
+ }\r
+\r
+ var range = selection.getRanges( true )[ 0 ];\r
+ range.shrink( CKEDITOR.SHRINK_TEXT );\r
+ var root = range.getCommonAncestor();\r
+ return root.getAscendant( 'a', true );\r
+ }\r
+ catch( e ) { return null; }\r
+ },\r
+\r
+ // Opera and WebKit don't make it possible to select empty anchors. Fake\r
+ // elements must be used for them.\r
+ fakeAnchor : CKEDITOR.env.opera || CKEDITOR.env.webkit,\r
+\r
+ // For browsers that don't support CSS3 a[name]:empty(), note IE9 is included because of #7783.\r
+ synAnchorSelector : CKEDITOR.env.ie,\r
+\r
+ // For browsers that have editing issue with empty anchor.\r
+ emptyAnchorFix : CKEDITOR.env.ie && CKEDITOR.env.version < 8,\r
+\r
+ tryRestoreFakeAnchor : function( editor, element )\r
+ {\r
+ if ( element && element.data( 'cke-real-element-type' ) && element.data( 'cke-real-element-type' ) == 'anchor' )\r
+ {\r
+ var link = editor.restoreRealElement( element );\r
+ if ( link.data( 'cke-saved-name' ) )\r
+ return link;\r
+ }\r
+ }\r
+};\r
+\r