JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.5.1
[ckeditor.git] / _source / plugins / link / dialogs / link.js
index eac5500..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
@@ -75,6 +75,8 @@ CKEDITOR.dialog.add( 'link', function( editor )
                        else\r
                                element.hide();\r
                }\r
+\r
+               dialog.layout();\r
        };\r
 \r
        // Loads the parameters in a selected link to the link dialog fields.\r
@@ -94,7 +96,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
 \r
        var parseLink = function( editor, element )\r
        {\r
-               var href = ( element  && ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) ) || '',\r
+               var href = ( element  && ( element.data( 'cke-saved-href' ) || element.getAttribute( 'href' ) ) ) || '',\r
                        javascriptMatch,\r
                        emailMatch,\r
                        anchorMatch,\r
@@ -184,7 +186,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
                        // IE BUG: target attribute is an empty string instead of null in IE if it's not set.\r
                        if ( !target )\r
                        {\r
-                               var onclick = element.getAttribute( '_cke_pa_onclick' ) || element.getAttribute( 'onclick' ),\r
+                               var onclick = element.data( 'cke-pa-onclick' ) || element.getAttribute( 'onclick' ),\r
                                        onclickMatch = onclick && onclick.match( popupRegex );\r
                                if ( onclickMatch )\r
                                {\r
@@ -223,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
@@ -242,7 +248,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
                for ( var i = 0; i < elements.count() ; i++ )\r
                {\r
                        var item = elements.getItem( i );\r
-                       if ( item.getAttribute( '_cke_realelement' ) && item.getAttribute( '_cke_real_element_type' ) == 'anchor' )\r
+                       if ( item.data( 'cke-realelement' ) && item.data( 'cke-real-element-type' ) == 'anchor' )\r
                                anchors.push( editor.restoreRealElement( item ) );\r
                }\r
 \r
@@ -448,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
@@ -758,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
@@ -791,7 +797,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                        },\r
                                        {\r
                                                type : 'vbox',\r
-                                               width : 260,\r
+                                               width : '100%',\r
                                                align : 'center',\r
                                                padding : 2,\r
                                                id : 'popupFeatures',\r
@@ -895,9 +901,9 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                                                                [\r
                                                                                        {\r
                                                                                                type :  'text',\r
-                                                                                               widths : [ '30%', '70%' ],\r
+                                                                                               widths : [ '50%', '50%' ],\r
                                                                                                labelLayout : 'horizontal',\r
-                                                                                               label : linkLang.popupWidth,\r
+                                                                                               label : commonLang.width,\r
                                                                                                id : 'width',\r
                                                                                                setup : setupPopupParams,\r
                                                                                                commit : commitPopupParams\r
@@ -906,7 +912,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                                                                        {\r
                                                                                                type :  'text',\r
                                                                                                labelLayout : 'horizontal',\r
-                                                                                               widths : [ '55%', '45%' ],\r
+                                                                                               widths : [ '50%', '50%' ],\r
                                                                                                label : linkLang.popupLeft,\r
                                                                                                id : 'left',\r
                                                                                                setup : setupPopupParams,\r
@@ -922,8 +928,8 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                                                                        {\r
                                                                                                type :  'text',\r
                                                                                                labelLayout : 'horizontal',\r
-                                                                                               widths : [ '30%', '70%' ],\r
-                                                                                               label : linkLang.popupHeight,\r
+                                                                                               widths : [ '50%', '50%' ],\r
+                                                                                               label : commonLang.height,\r
                                                                                                id : 'height',\r
                                                                                                setup : setupPopupParams,\r
                                                                                                commit : commitPopupParams\r
@@ -933,7 +939,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                                                                                type :  'text',\r
                                                                                                labelLayout : 'horizontal',\r
                                                                                                label : linkLang.popupTop,\r
-                                                                                               widths : [ '55%', '45%' ],\r
+                                                                                               widths : [ '50%', '50%' ],\r
                                                                                                id : 'top',\r
                                                                                                setup : setupPopupParams,\r
                                                                                                commit : commitPopupParams\r
@@ -1145,8 +1151,8 @@ CKEDITOR.dialog.add( 'link', function( editor )
                        if ( ( element = plugin.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) )\r
                                selection.selectElement( element );\r
                        else if ( ( element = selection.getSelectedElement() ) && element.is( 'img' )\r
-                                       && element.getAttribute( '_cke_real_element_type' )\r
-                                       && element.getAttribute( '_cke_real_element_type' ) == 'anchor' )\r
+                                       && element.data( 'cke-real-element-type' )\r
+                                       && element.data( 'cke-real-element-type' ) == 'anchor' )\r
                        {\r
                                this.fakeObj = element;\r
                                element = editor.restoreRealElement( this.fakeObj );\r
@@ -1159,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
@@ -1173,12 +1179,12 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                case 'url':\r
                                        var protocol = ( data.url && data.url.protocol != undefined ) ? data.url.protocol : 'http://',\r
                                                url = ( data.url && data.url.url ) || '';\r
-                                       attributes._cke_saved_href = ( url.indexOf( '/' ) === 0 ) ? url : protocol + url;\r
+                                       attributes[ 'data-cke-saved-href' ] = ( url.indexOf( '/' ) === 0 ) ? url : protocol + url;\r
                                        break;\r
                                case 'anchor':\r
                                        var name = ( data.anchor && data.anchor.name ),\r
                                                id = ( data.anchor && data.anchor.id );\r
-                                       attributes._cke_saved_href = '#' + ( name || id || '' );\r
+                                       attributes[ 'data-cke-saved-href' ] = '#' + ( name || id || '' );\r
                                        break;\r
                                case 'email':\r
 \r
@@ -1225,7 +1231,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                                }\r
                                        }\r
 \r
-                                       attributes._cke_saved_href = linkHref.join( '' );\r
+                                       attributes[ 'data-cke-saved-href' ] = linkHref.join( '' );\r
                                        break;\r
                        }\r
 \r
@@ -1253,7 +1259,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                        addFeature( 'top' );\r
 \r
                                        onclickList.push( featureList.join( ',' ), '\'); return false;' );\r
-                                       attributes[ '_cke_pa_onclick' ] = onclickList.join( '' );\r
+                                       attributes[ 'data-cke-pa-onclick' ] = onclickList.join( '' );\r
 \r
                                        // Add the "target" attribute. (#5074)\r
                                        removeAttributes.push( 'target' );\r
@@ -1265,7 +1271,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                        else\r
                                                removeAttributes.push( 'target' );\r
 \r
-                                       removeAttributes.push( '_cke_pa_onclick', 'onclick' );\r
+                                       removeAttributes.push( 'data-cke-pa-onclick', 'onclick' );\r
                                }\r
                        }\r
 \r
@@ -1281,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
@@ -1295,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
@@ -1304,7 +1321,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                {\r
                                        // Short mailto link text view (#5736).\r
                                        var text = new CKEDITOR.dom.text( data.type == 'email' ?\r
-                                                       data.email.address : attributes._cke_saved_href, editor.document );\r
+                                                       data.email.address : attributes[ 'data-cke-saved-href' ], editor.document );\r
                                        ranges[0].insertNode( text );\r
                                        ranges[0].selectNodeContents( text );\r
                                        selection.selectRanges( ranges );\r
@@ -1314,26 +1331,12 @@ 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
                                // We're only editing an existing link, so just overwrite the attributes.\r
                                var element = this._.selectedElement,\r
-                                       href = element.getAttribute( '_cke_saved_href' ),\r
+                                       href = element.data( 'cke-saved-href' ),\r
                                        textView = element.getHtml();\r
 \r
                                // IE BUG: Setting the name attribute to an existing link doesn't work.\r
@@ -1345,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
@@ -1360,7 +1363,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                {\r
                                        // Short mailto link text view (#5736).\r
                                        element.setHtml( data.type == 'email' ?\r
-                                               data.email.address : attributes._cke_saved_href );\r
+                                               data.email.address : attributes[ 'data-cke-saved-href' ] );\r
                                }\r
                                // Make the element display as an anchor if a name has been set.\r
                                if ( element.getAttribute( 'name' ) )\r