JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.1
[ckeditor.git] / _source / plugins / link / dialogs / link.js
index 94ee042..51f5623 100644 (file)
@@ -235,37 +235,51 @@ CKEDITOR.dialog.add( 'link', function( editor )
                        advAttr( 'advTabIndex', 'tabindex' );\r
                        advAttr( 'advTitle', 'title' );\r
                        advAttr( 'advContentType', 'type' );\r
-                       advAttr( 'advCSSClasses', 'class' );\r
+                       CKEDITOR.plugins.link.synAnchorSelector ?\r
+                               retval.adv.advCSSClasses = getLinkClass( element )\r
+                               : advAttr( 'advCSSClasses', 'class' );\r
                        advAttr( 'advCharset', 'charset' );\r
                        advAttr( 'advStyles', 'style' );\r
                        advAttr( 'advRel', 'rel' );\r
                }\r
 \r
                // Find out whether we have any anchors in the editor.\r
-               // Get all IMG elements in CK document.\r
-               var elements = editor.document.getElementsByTag( 'img' ),\r
-                       realAnchors = new CKEDITOR.dom.nodeList( editor.document.$.anchors ),\r
-                       anchors = retval.anchors = [];\r
+               var anchors = retval.anchors = [],\r
+                       item;\r
 \r
-               for ( var i = 0; i < elements.count() ; i++ )\r
+               // For some browsers we set contenteditable="false" on anchors, making document.anchors not to include them, so we must traverse the links manually (#7893).\r
+               if ( CKEDITOR.plugins.link.emptyAnchorFix )\r
                {\r
-                       var item = elements.getItem( i );\r
-                       if ( item.data( 'cke-realelement' ) && item.data( 'cke-real-element-type' ) == 'anchor' )\r
-                               anchors.push( editor.restoreRealElement( item ) );\r
+                       var links = editor.document.getElementsByTag( 'a' );\r
+                       for ( i = 0, count = links.count(); i < count; i++ )\r
+                       {\r
+                               item = links.getItem( i );\r
+                               if ( item.data( 'cke-saved-name' ) || item.hasAttribute( 'name' ) )\r
+                                       anchors.push( { name : item.data( 'cke-saved-name' ) || item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) } );\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       var anchorList = new CKEDITOR.dom.nodeList( editor.document.$.anchors );\r
+                       for ( var i = 0, count = anchorList.count(); i < count; i++ )\r
+                       {\r
+                               item = anchorList.getItem( i );\r
+                               anchors[ i ] = { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) };\r
+                       }\r
                }\r
 \r
-               for ( i = 0 ; i < realAnchors.count() ; i++ )\r
-                       anchors.push( realAnchors.getItem( i ) );\r
-\r
-               for ( i = 0 ; i < anchors.length ; i++ )\r
+               if ( CKEDITOR.plugins.link.fakeAnchor )\r
                {\r
-                       item = anchors[ i ];\r
-                       anchors[ i ] = { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) };\r
+                       var imgs = editor.document.getElementsByTag( 'img' );\r
+                       for ( i = 0, count = imgs.count(); i < count; i++ )\r
+                       {\r
+                               if ( ( item = CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, imgs.getItem( i ) ) ) )\r
+                                       anchors.push( { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) } );\r
+                       }\r
                }\r
 \r
                // Record down the selected element in the dialog.\r
                this._.selectedElement = element;\r
-\r
                return retval;\r
        };\r
 \r
@@ -369,6 +383,12 @@ CKEDITOR.dialog.add( 'link', function( editor )
                return 'String.fromCharCode(' + encodedChars.join( ',' ) + ')';\r
        }\r
 \r
+       function getLinkClass( ele )\r
+       {\r
+               var className = ele.getAttribute( 'class' );\r
+               return className ? className.replace( /\s*(?:cke_anchor_empty|cke_anchor)(?:\s*$)?/g, '' ) : '';\r
+       }\r
+\r
        var commonLang = editor.lang.common,\r
                linkLang = editor.lang.link;\r
 \r
@@ -1151,8 +1171,6 @@ CKEDITOR.dialog.add( 'link', function( editor )
                ],\r
                onShow : function()\r
                {\r
-                       this.fakeObj = false;\r
-\r
                        var editor = this.getParentEditor(),\r
                                selection = editor.getSelection(),\r
                                element = null;\r
@@ -1160,14 +1178,6 @@ CKEDITOR.dialog.add( 'link', function( editor )
                        // Fill in all the relevant fields if there's already one link selected.\r
                        if ( ( element = plugin.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) )\r
                                selection.selectElement( element );\r
-                       else if ( ( element = selection.getSelectedElement() ) && element.is( 'img' )\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
-                               selection.selectElement( this.fakeObj );\r
-                       }\r
                        else\r
                                element = null;\r
 \r
@@ -1188,7 +1198,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
                        {\r
                                case 'url':\r
                                        var protocol = ( data.url && data.url.protocol != undefined ) ? data.url.protocol : 'http://',\r
-                                               url = ( data.url && data.url.url ) || '';\r
+                                               url = ( data.url && CKEDITOR.tools.trim( data.url.url ) ) || '';\r
                                        attributes[ 'data-cke-saved-href' ] = ( url.indexOf( '/' ) === 0 ) ? url : protocol + url;\r
                                        break;\r
                                case 'anchor':\r
@@ -1302,10 +1312,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                advAttr( 'advAccessKey', 'accessKey' );\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
@@ -1350,25 +1357,12 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                        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
-                               // Must re-create the link from weired syntax to workaround.\r
-                               if ( CKEDITOR.env.ie && !( CKEDITOR.document.$.documentMode >= 8 ) && attributes.name != element.getAttribute( 'name' ) )\r
-                               {\r
-                                       var newElement = new CKEDITOR.dom.element( '<a name="' + CKEDITOR.tools.htmlEncode( attributes.name ) + '">',\r
-                                                       editor.document );\r
-\r
-                                       selection = editor.getSelection();\r
-\r
-                                       element.copyAttributes( newElement, { name : 1 } );\r
-                                       element.moveChildren( newElement );\r
-                                       newElement.replace( element );\r
-                                       element = newElement;\r
-\r
-                                       selection.selectElement( element );\r
-                               }\r
-\r
                                element.setAttributes( attributes );\r
                                element.removeAttributes( removeAttributes );\r
+\r
+                               if ( data.adv && data.adv.advName && CKEDITOR.plugins.link.synAnchorSelector )\r
+                                       element.addClass( element.getChildCount() ? 'cke_anchor' : 'cke_anchor_empty' );\r
+\r
                                // Update text view when user changes protocol (#4612).\r
                                if ( href == textView || data.type == 'email' && textView.indexOf( '@' ) != -1 )\r
                                {\r
@@ -1376,14 +1370,6 @@ CKEDITOR.dialog.add( 'link', function( editor )
                                        element.setHtml( data.type == 'email' ?\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
-                                       element.addClass( 'cke_anchor' );\r
-                               else\r
-                                       element.removeClass( 'cke_anchor' );\r
-\r
-                               if ( this.fakeObj )\r
-                                       editor.createFakeElement( element, 'cke_anchor', 'anchor' ).replace( this.fakeObj );\r
 \r
                                delete this._.selectedElement;\r
                        }\r