JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4.3
[ckeditor.git] / _source / plugins / link / plugin.js
index 7993a0f..f0278ec 100644 (file)
@@ -37,8 +37,8 @@ CKEDITOR.plugins.add( 'link',
                                'background-position: center center;' +\r
                                'background-repeat: no-repeat;' +\r
                                'border: 1px solid #a9a9a9;' +\r
-                               'width: 18px;' +\r
-                               'height: 18px;' +\r
+                               'width: 18px !important;' +\r
+                               'height: 18px !important;' +\r
                        '}\n' +\r
                        'a.cke_anchor' +\r
                        '{' +\r
@@ -58,13 +58,26 @@ CKEDITOR.plugins.add( 'link',
                                 * for this in Firefox. So we must detect the state by element paths.\r
                                 */\r
                                var command = editor.getCommand( 'unlink' ),\r
-                                       element = evt.data.path.lastElement.getAscendant( 'a', true );\r
+                                       element = evt.data.path.lastElement && evt.data.path.lastElement.getAscendant( 'a', true );\r
                                if ( element && element.getName() == 'a' && element.getAttribute( 'href' ) )\r
                                        command.setState( CKEDITOR.TRISTATE_OFF );\r
                                else\r
                                        command.setState( CKEDITOR.TRISTATE_DISABLED );\r
                        } );\r
 \r
+               editor.on( 'doubleclick', function( evt )\r
+                       {\r
+                               var element = CKEDITOR.plugins.link.getSelectedLink( editor ) || evt.data.element;\r
+\r
+                               if ( !element.isReadOnly() )\r
+                               {\r
+                                       if ( element.is( 'a' ) )\r
+                                               evt.data.dialog =  ( element.getAttribute( 'name' ) && !element.getAttribute( 'href' ) ) ? 'anchor' : 'link';\r
+                                       else if ( element.is( 'img' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' )\r
+                                               evt.data.dialog = 'anchor';\r
+                               }\r
+                       });\r
+\r
                // If the "menu" plugin is loaded, register the menu items.\r
                if ( editor.addMenuItems )\r
                {\r
@@ -100,14 +113,14 @@ CKEDITOR.plugins.add( 'link',
                {\r
                        editor.contextMenu.addListener( function( element, selection )\r
                                {\r
-                                       if ( !element )\r
+                                       if ( !element || element.isReadOnly() )\r
                                                return null;\r
 \r
                                        var isAnchor = ( element.is( 'img' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' );\r
 \r
                                        if ( !isAnchor )\r
                                        {\r
-                                               if ( !( element = element.getAscendant( 'a', true ) ) )\r
+                                               if ( !( element = CKEDITOR.plugins.link.getSelectedLink( editor ) ) )\r
                                                        return null;\r
 \r
                                                isAnchor = ( element.getAttribute( 'name' ) && !element.getAttribute( 'href' ) );\r
@@ -147,6 +160,44 @@ CKEDITOR.plugins.add( 'link',
        requires : [ 'fakeobjects' ]\r
 } );\r
 \r
+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
+\r
 CKEDITOR.unlinkCommand = function(){};\r
 CKEDITOR.unlinkCommand.prototype =\r
 {\r
@@ -178,7 +229,9 @@ CKEDITOR.unlinkCommand.prototype =
                selection.selectRanges( ranges );\r
                editor.document.$.execCommand( 'unlink', false, null );\r
                selection.selectBookmarks( bookmarks );\r
-       }\r
+       },\r
+\r
+       startDisabled : true\r
 };\r
 \r
 CKEDITOR.tools.extend( CKEDITOR.config,\r