JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.5.1
[ckeditor.git] / _source / plugins / link / dialogs / link.js
index 5362b16..56baa05 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -225,7 +225,11 @@ CKEDITOR.dialog.add( 'link', function( editor )
                        advAttr( 'advId', 'id' );\r
                        advAttr( 'advLangDir', 'dir' );\r
                        advAttr( 'advAccessKey', 'accessKey' );\r
-                       advAttr( 'advName', 'name' );\r
+\r
+                       retval.adv.advName =\r
+                               element.data( 'cke-saved-name' )\r
+                               || element.getAttribute( 'name' )\r
+                               || '';\r
                        advAttr( 'advLangCode', 'lang' );\r
                        advAttr( 'advTabIndex', 'tabindex' );\r
                        advAttr( 'advTitle', 'title' );\r
@@ -450,8 +454,8 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                                                                        this.allowOnChange = false;\r
                                                                                        var     protocolCmb = this.getDialog().getContentElement( 'info', 'protocol' ),\r
                                                                                                url = this.getValue(),\r
-                                                                                               urlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/gi,\r
-                                                                                               urlOnChangeTestOther = /^((javascript:)|[#\/\.\?])/gi;\r
+                                                                                               urlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/i,\r
+                                                                                               urlOnChangeTestOther = /^((javascript:)|[#\/\.\?])/i;\r
 \r
                                                                                        var protocol = urlOnChangeProtocol.exec( url );\r
                                                                                        if ( protocol )\r
@@ -760,7 +764,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                                                setup : function( data )\r
                                                                {\r
                                                                        if ( data.target )\r
-                                                                               this.setValue( data.target.type );\r
+                                                                               this.setValue( data.target.type || 'notSet' );\r
                                                                        targetChanged.call( this );\r
                                                                },\r
                                                                commit : function( data )\r
@@ -1161,9 +1165,9 @@ CKEDITOR.dialog.add( 'link', function( editor )
                },\r
                onOk : function()\r
                {\r
-                       var attributes = { href : 'javascript:void(0)/*' + CKEDITOR.tools.getNextNumber() + '*/' },\r
+                       var attributes = {},\r
                                removeAttributes = [],\r
-                               data = { href : attributes.href },\r
+                               data = {},\r
                                me = this,\r
                                editor = this.getParentEditor();\r
 \r
@@ -1283,11 +1287,18 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                                removeAttributes.push( attrName );\r
                                };\r
 \r
-                               if ( this._.selectedElement )\r
-                                       advAttr( 'advId', 'id' );\r
+                               advAttr( 'advId', 'id' );\r
                                advAttr( 'advLangDir', 'dir' );\r
                                advAttr( 'advAccessKey', 'accessKey' );\r
-                               advAttr( 'advName', 'name' );\r
+\r
+                               if ( data.adv[ 'advName' ] )\r
+                               {\r
+                                       attributes[ 'name' ] = attributes[ 'data-cke-saved-name' ] = data.adv[ 'advName' ];\r
+                                       attributes[ 'class' ] = ( attributes[ 'class' ] ? attributes[ 'class' ] + ' ' : '' ) + 'cke_anchor';\r
+                               }\r
+                               else\r
+                                       removeAttributes = removeAttributes.concat( [ 'data-cke-saved-name', 'name' ] );\r
+\r
                                advAttr( 'advLangCode', 'lang' );\r
                                advAttr( 'advTabIndex', 'tabindex' );\r
                                advAttr( 'advTitle', 'title' );\r
@@ -1297,6 +1308,10 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                advAttr( 'advStyles', 'style' );\r
                        }\r
 \r
+\r
+                       // Browser need the "href" fro copy/paste link to work. (#6641)\r
+                       attributes.href = attributes[ 'data-cke-saved-href' ];\r
+\r
                        if ( !this._.selectedElement )\r
                        {\r
                                // Create element if current selection is collapsed.\r
@@ -1316,20 +1331,6 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );\r
                                style.type = CKEDITOR.STYLE_INLINE;             // need to override... dunno why.\r
                                style.apply( editor.document );\r
-\r
-                               // Id. Apply only to the first link.\r
-                               if ( data.adv && data.adv.advId )\r
-                               {\r
-                                       var links = this.getParentEditor().document.$.getElementsByTagName( 'a' );\r
-                                       for ( i = 0 ; i < links.length ; i++ )\r
-                                       {\r
-                                               if ( links[i].href == attributes.href )\r
-                                               {\r
-                                                       links[i].id = data.adv.advId;\r
-                                                       break;\r
-                                               }\r
-                                       }\r
-                               }\r
                        }\r
                        else\r
                        {\r
@@ -1347,8 +1348,8 @@ CKEDITOR.dialog.add( 'link', function( editor )
 \r
                                        selection = editor.getSelection();\r
 \r
-                                       element.moveChildren( newElement );\r
                                        element.copyAttributes( newElement, { name : 1 } );\r
+                                       element.moveChildren( newElement );\r
                                        newElement.replace( element );\r
                                        element = newElement;\r
 \r