/*\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
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
\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
// 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
var featureMatch;\r
while ( ( featureMatch = popupFeaturesRegex.exec( onclickMatch[2] ) ) )\r
{\r
- if ( featureMatch[2] == 'yes' || featureMatch[2] == '1' )\r
+ // Some values should remain numbers (#7300)\r
+ if ( ( featureMatch[2] == 'yes' || featureMatch[2] == '1' ) && !( featureMatch[1] in { height:1, width:1, top:1, left:1 } ) )\r
retval.target[ featureMatch[1] ] = true;\r
else if ( isFinite( featureMatch[2] ) )\r
retval.target[ featureMatch[1] ] = featureMatch[2];\r
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
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.getAttribute( '_cke_realelement' ) && item.getAttribute( '_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
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
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
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
},\r
{\r
type : 'vbox',\r
- width : 260,\r
+ width : '100%',\r
align : 'center',\r
padding : 2,\r
id : 'popupFeatures',\r
[\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
{\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
{\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
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
},\r
{\r
type : 'hbox',\r
+ widths : [ '45%', '55%' ],\r
children :\r
[\r
{\r
type : 'text',\r
+ label : linkLang.rel,\r
+ 'default' : '',\r
+ id : 'advRel',\r
+ setup : setupAdvParams,\r
+ commit : commitAdvParams\r
+ },\r
+ {\r
+ type : 'text',\r
label : linkLang.styles,\r
'default' : '',\r
id : 'advStyles',\r
+ validate : CKEDITOR.dialog.validate.inlineStyle( editor.lang.common.invalidInlineStyle ),\r
setup : setupAdvParams,\r
commit : commitAdvParams\r
-\r
}\r
]\r
}\r
],\r
onShow : function()\r
{\r
- this.fakeObj = false;\r
-\r
var editor = this.getParentEditor(),\r
selection = editor.getSelection(),\r
element = null;\r
// 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.getAttribute( '_cke_real_element_type' )\r
- && element.getAttribute( '_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
},\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
{\r
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
+ 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
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
}\r
}\r
\r
- attributes._cke_saved_href = linkHref.join( '' );\r
+ attributes[ 'data-cke-saved-href' ] = linkHref.join( '' );\r
break;\r
}\r
\r
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
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
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
+ attributes[ 'name' ] = attributes[ 'data-cke-saved-name' ] = data.adv[ 'advName' ];\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
advAttr( 'advCSSClasses', 'class' );\r
advAttr( 'advCharset', 'charset' );\r
advAttr( 'advStyles', 'style' );\r
+ advAttr( 'advRel', 'rel' );\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
{\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
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
- // Must re-create the link from weired syntax to workaround.\r
- if ( CKEDITOR.env.ie && 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.moveChildren( newElement );\r
- element.copyAttributes( newElement, { name : 1 } );\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
// 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
- 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