JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.1
[ckeditor.git] / _source / plugins / link / plugin.js
index 083256c..4442432 100644 (file)
@@ -11,6 +11,7 @@ CKEDITOR.plugins.add( 'link',
                editor.addCommand( 'link', new CKEDITOR.dialogCommand( 'link' ) );\r
                editor.addCommand( 'anchor', new CKEDITOR.dialogCommand( 'anchor' ) );\r
                editor.addCommand( 'unlink', new CKEDITOR.unlinkCommand() );\r
+               editor.addCommand( 'removeAnchor', new CKEDITOR.removeAnchorCommand() );\r
                editor.ui.addButton( 'Link',\r
                        {\r
                                label : editor.lang.link.toolbar,\r
@@ -108,7 +109,16 @@ CKEDITOR.plugins.add( 'link',
                                        {\r
                                                label : editor.lang.anchor.menu,\r
                                                command : 'anchor',\r
-                                               group : 'anchor'\r
+                                               group : 'anchor',\r
+                                               order : 1\r
+                                       },\r
+\r
+                                       removeAnchor :\r
+                                       {\r
+                                               label : editor.lang.anchor.remove,\r
+                                               command : 'removeAnchor',\r
+                                               group : 'anchor',\r
+                                               order : 5\r
                                        },\r
 \r
                                        link :\r
@@ -148,7 +158,7 @@ CKEDITOR.plugins.add( 'link',
                                                menu = { link : CKEDITOR.TRISTATE_OFF, unlink : CKEDITOR.TRISTATE_OFF };\r
 \r
                                        if ( anchor && anchor.hasAttribute( 'name' ) )\r
-                                               menu.anchor = CKEDITOR.TRISTATE_OFF;\r
+                                               menu.anchor = menu.removeAnchor = CKEDITOR.TRISTATE_OFF;\r
 \r
                                        return menu;\r
                                });\r
@@ -329,6 +339,34 @@ CKEDITOR.unlinkCommand.prototype =
        startDisabled : true\r
 };\r
 \r
+CKEDITOR.removeAnchorCommand = function(){};\r
+CKEDITOR.removeAnchorCommand.prototype =\r
+{\r
+       /** @ignore */\r
+       exec : function( editor )\r
+       {\r
+               var sel = editor.getSelection(),\r
+                       bms = sel.createBookmarks(),\r
+                       anchor;\r
+               if ( sel && ( anchor = sel.getSelectedElement() ) && ( CKEDITOR.plugins.link.fakeAnchor && !anchor.getChildCount() ? CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, anchor ) : anchor.is( 'a' ) ) )\r
+                       anchor.remove( 1 );\r
+               else\r
+               {\r
+                       if ( ( anchor = CKEDITOR.plugins.link.getSelectedLink( editor ) ) )\r
+                       {\r
+                               if ( anchor.hasAttribute( 'href' ) )\r
+                               {\r
+                                       anchor.removeAttributes( { name : 1, 'data-cke-saved-name' : 1 } );\r
+                                       anchor.removeClass( 'cke_anchor' );\r
+                               }\r
+                               else\r
+                                       anchor.remove( 1 );\r
+                       }\r
+               }\r
+               sel.selectBookmarks( bms );\r
+       }\r
+};\r
+\r
 CKEDITOR.tools.extend( CKEDITOR.config,\r
 {\r
        linkShowAdvancedTab : true,\r