JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.2
[ckeditor.git] / _source / plugins / link / dialogs / link.js
1 /*\r
2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license\r
4 */\r
5 \r
6 CKEDITOR.dialog.add( 'link', function( editor )\r
7 {\r
8         // Handles the event when the "Target" selection box is changed.\r
9         var targetChanged = function()\r
10         {\r
11                 var dialog = this.getDialog(),\r
12                         popupFeatures = dialog.getContentElement( 'target', 'popupFeatures' ),\r
13                         targetName = dialog.getContentElement( 'target', 'linkTargetName' ),\r
14                         value = this.getValue();\r
15 \r
16                 if ( !popupFeatures || !targetName )\r
17                         return;\r
18 \r
19                 popupFeatures = popupFeatures.getElement();\r
20                 popupFeatures.hide();\r
21                 targetName.setValue( '' );\r
22 \r
23                 switch ( value )\r
24                 {\r
25                         case 'frame' :\r
26                                 targetName.setLabel( editor.lang.link.targetFrameName );\r
27                                 targetName.getElement().show();\r
28                                 break;\r
29                         case 'popup' :\r
30                                 popupFeatures.show();\r
31                                 targetName.setLabel( editor.lang.link.targetPopupName );\r
32                                 targetName.getElement().show();\r
33                                 break;\r
34                         default :\r
35                                 targetName.setValue( value );\r
36                                 targetName.getElement().hide();\r
37                                 break;\r
38                 }\r
39 \r
40         };\r
41 \r
42         // Handles the event when the "Type" selection box is changed.\r
43         var linkTypeChanged = function()\r
44         {\r
45                 var dialog = this.getDialog(),\r
46                         partIds = [ 'urlOptions', 'anchorOptions', 'emailOptions' ],\r
47                         typeValue = this.getValue(),\r
48                         uploadTab = dialog.definition.getContents( 'upload' ),\r
49                         uploadInitiallyHidden = uploadTab && uploadTab.hidden;\r
50 \r
51                 if ( typeValue == 'url' )\r
52                 {\r
53                         if ( editor.config.linkShowTargetTab )\r
54                                 dialog.showPage( 'target' );\r
55                         if ( !uploadInitiallyHidden )\r
56                                 dialog.showPage( 'upload' );\r
57                 }\r
58                 else\r
59                 {\r
60                         dialog.hidePage( 'target' );\r
61                         if ( !uploadInitiallyHidden )\r
62                                 dialog.hidePage( 'upload' );\r
63                 }\r
64 \r
65                 for ( var i = 0 ; i < partIds.length ; i++ )\r
66                 {\r
67                         var element = dialog.getContentElement( 'info', partIds[i] );\r
68                         if ( !element )\r
69                                 continue;\r
70 \r
71                         element = element.getElement().getParent().getParent();\r
72                         if ( partIds[i] == typeValue + 'Options' )\r
73                                 element.show();\r
74                         else\r
75                                 element.hide();\r
76                 }\r
77         };\r
78 \r
79         // Loads the parameters in a selected link to the link dialog fields.\r
80         var javascriptProtocolRegex = /^javascript:/,\r
81                 emailRegex = /^mailto:([^?]+)(?:\?(.+))?$/,\r
82                 emailSubjectRegex = /subject=([^;?:@&=$,\/]*)/,\r
83                 emailBodyRegex = /body=([^;?:@&=$,\/]*)/,\r
84                 anchorRegex = /^#(.*)$/,\r
85                 urlRegex = /^((?:http|https|ftp|news):\/\/)?(.*)$/,\r
86                 selectableTargets = /^(_(?:self|top|parent|blank))$/,\r
87                 encodedEmailLinkRegex = /^javascript:void\(location\.href='mailto:'\+String\.fromCharCode\(([^)]+)\)(?:\+'(.*)')?\)$/,\r
88                 functionCallProtectedEmailLinkRegex = /^javascript:([^(]+)\(([^)]+)\)$/;\r
89 \r
90         var popupRegex =\r
91                 /\s*window.open\(\s*this\.href\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*/;\r
92         var popupFeaturesRegex = /(?:^|,)([^=]+)=(\d+|yes|no)/gi;\r
93 \r
94         var parseLink = function( editor, element )\r
95         {\r
96                 var href = element ? ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) : '',\r
97                         javascriptMatch,\r
98                         emailMatch,\r
99                         anchorMatch,\r
100                         urlMatch,\r
101                         retval = {};\r
102 \r
103                 if ( ( javascriptMatch = href.match( javascriptProtocolRegex ) ) )\r
104                 {\r
105                         if ( emailProtection == 'encode' )\r
106                         {\r
107                                 href = href.replace( encodedEmailLinkRegex,\r
108                                                 function ( match, protectedAddress, rest )\r
109                                                 {\r
110                                                         return 'mailto:' +\r
111                                                                String.fromCharCode.apply( String, protectedAddress.split( ',' ) ) +\r
112                                                                ( rest && unescapeSingleQuote( rest ) );\r
113                                                 });\r
114                         }\r
115                         // Protected email link as function call.\r
116                         else if ( emailProtection )\r
117                         {\r
118                                 href.replace( functionCallProtectedEmailLinkRegex, function( match, funcName, funcArgs )\r
119                                 {\r
120                                         if ( funcName == compiledProtectionFunction.name )\r
121                                         {\r
122                                                 retval.type = 'email';\r
123                                                 var email = retval.email = {};\r
124 \r
125                                                 var paramRegex = /[^,\s]+/g,\r
126                                                         paramQuoteRegex = /(^')|('$)/g,\r
127                                                         paramsMatch = funcArgs.match( paramRegex ),\r
128                                                         paramsMatchLength = paramsMatch.length,\r
129                                                         paramName,\r
130                                                         paramVal;\r
131 \r
132                                                 for ( var i = 0; i < paramsMatchLength; i++ )\r
133                                                 {\r
134                                                         paramVal = decodeURIComponent( unescapeSingleQuote( paramsMatch[ i ].replace( paramQuoteRegex, '' ) ) );\r
135                                                         paramName = compiledProtectionFunction.params[ i ].toLowerCase();\r
136                                                         email[ paramName ] = paramVal;\r
137                                                 }\r
138                                                 email.address = [ email.name, email.domain ].join( '@' );\r
139                                         }\r
140                                 } );\r
141                         }\r
142                 }\r
143 \r
144                 if ( !retval.type )\r
145                 {\r
146                         if ( ( anchorMatch = href.match( anchorRegex ) ) )\r
147                         {\r
148                                 retval.type = 'anchor';\r
149                                 retval.anchor = {};\r
150                                 retval.anchor.name = retval.anchor.id = anchorMatch[1];\r
151                         }\r
152                         // Protected email link as encoded string.\r
153                         else if ( ( emailMatch = href.match( emailRegex ) ) )\r
154                         {\r
155                                 var subjectMatch = href.match( emailSubjectRegex ),\r
156                                         bodyMatch = href.match( emailBodyRegex );\r
157 \r
158                                 retval.type = 'email';\r
159                                 var email = ( retval.email = {} );\r
160                                 email.address = emailMatch[ 1 ];\r
161                                 subjectMatch && ( email.subject = decodeURIComponent( subjectMatch[ 1 ] ) );\r
162                                 bodyMatch && ( email.body = decodeURIComponent( bodyMatch[ 1 ] ) );\r
163                         }\r
164                         // urlRegex matches empty strings, so need to check for href as well.\r
165                         else if (  href && ( urlMatch = href.match( urlRegex ) ) )\r
166                         {\r
167                                 retval.type = 'url';\r
168                                 retval.url = {};\r
169                                 retval.url.protocol = urlMatch[1];\r
170                                 retval.url.url = urlMatch[2];\r
171                         }\r
172                         else\r
173                                 retval.type = 'url';\r
174                 }\r
175 \r
176                 // Load target and popup settings.\r
177                 if ( element )\r
178                 {\r
179                         var target = element.getAttribute( 'target' );\r
180                         retval.target = {};\r
181                         retval.adv = {};\r
182 \r
183                         // IE BUG: target attribute is an empty string instead of null in IE if it's not set.\r
184                         if ( !target )\r
185                         {\r
186                                 var onclick = element.getAttribute( '_cke_pa_onclick' ) || element.getAttribute( 'onclick' ),\r
187                                         onclickMatch = onclick && onclick.match( popupRegex );\r
188                                 if ( onclickMatch )\r
189                                 {\r
190                                         retval.target.type = 'popup';\r
191                                         retval.target.name = onclickMatch[1];\r
192 \r
193                                         var featureMatch;\r
194                                         while ( ( featureMatch = popupFeaturesRegex.exec( onclickMatch[2] ) ) )\r
195                                         {\r
196                                                 if ( featureMatch[2] == 'yes' || featureMatch[2] == '1' )\r
197                                                         retval.target[ featureMatch[1] ] = true;\r
198                                                 else if ( isFinite( featureMatch[2] ) )\r
199                                                         retval.target[ featureMatch[1] ] = featureMatch[2];\r
200                                         }\r
201                                 }\r
202                         }\r
203                         else\r
204                         {\r
205                                 var targetMatch = target.match( selectableTargets );\r
206                                 if ( targetMatch )\r
207                                         retval.target.type = retval.target.name = target;\r
208                                 else\r
209                                 {\r
210                                         retval.target.type = 'frame';\r
211                                         retval.target.name = target;\r
212                                 }\r
213                         }\r
214 \r
215                         var me = this;\r
216                         var advAttr = function( inputName, attrName )\r
217                         {\r
218                                 var value = element.getAttribute( attrName );\r
219                                 if ( value !== null )\r
220                                         retval.adv[ inputName ] = value || '';\r
221                         };\r
222                         advAttr( 'advId', 'id' );\r
223                         advAttr( 'advLangDir', 'dir' );\r
224                         advAttr( 'advAccessKey', 'accessKey' );\r
225                         advAttr( 'advName', 'name' );\r
226                         advAttr( 'advLangCode', 'lang' );\r
227                         advAttr( 'advTabIndex', 'tabindex' );\r
228                         advAttr( 'advTitle', 'title' );\r
229                         advAttr( 'advContentType', 'type' );\r
230                         advAttr( 'advCSSClasses', 'class' );\r
231                         advAttr( 'advCharset', 'charset' );\r
232                         advAttr( 'advStyles', 'style' );\r
233                 }\r
234 \r
235                 // Find out whether we have any anchors in the editor.\r
236                 // Get all IMG elements in CK document.\r
237                 var elements = editor.document.getElementsByTag( 'img' ),\r
238                         realAnchors = new CKEDITOR.dom.nodeList( editor.document.$.anchors ),\r
239                         anchors = retval.anchors = [];\r
240 \r
241                 for ( var i = 0; i < elements.count() ; i++ )\r
242                 {\r
243                         var item = elements.getItem( i );\r
244                         if ( item.getAttribute( '_cke_realelement' ) && item.getAttribute( '_cke_real_element_type' ) == 'anchor' )\r
245                         {\r
246                                 anchors.push( editor.restoreRealElement( item ) );\r
247                         }\r
248                 }\r
249 \r
250                 for ( i = 0 ; i < realAnchors.count() ; i++ )\r
251                         anchors.push( realAnchors.getItem( i ) );\r
252 \r
253                 for ( i = 0 ; i < anchors.length ; i++ )\r
254                 {\r
255                         item = anchors[ i ];\r
256                         anchors[ i ] = { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) };\r
257                 }\r
258 \r
259                 // Record down the selected element in the dialog.\r
260                 this._.selectedElement = element;\r
261 \r
262                 return retval;\r
263         };\r
264 \r
265         var setupParams = function( page, data )\r
266         {\r
267                 if ( data[page] )\r
268                         this.setValue( data[page][this.id] || '' );\r
269         };\r
270 \r
271         var setupPopupParams = function( data )\r
272         {\r
273                 return setupParams.call( this, 'target', data );\r
274         };\r
275 \r
276         var setupAdvParams = function( data )\r
277         {\r
278                 return setupParams.call( this, 'adv', data );\r
279         };\r
280 \r
281         var commitParams = function( page, data )\r
282         {\r
283                 if ( !data[page] )\r
284                         data[page] = {};\r
285 \r
286                 data[page][this.id] = this.getValue() || '';\r
287         };\r
288 \r
289         var commitPopupParams = function( data )\r
290         {\r
291                 return commitParams.call( this, 'target', data );\r
292         };\r
293 \r
294         var commitAdvParams = function( data )\r
295         {\r
296                 return commitParams.call( this, 'adv', data );\r
297         };\r
298 \r
299         function unescapeSingleQuote( str )\r
300         {\r
301                 return str.replace( /\\'/g, '\'' );\r
302         }\r
303 \r
304         function escapeSingleQuote( str )\r
305         {\r
306                 return str.replace( /'/g, '\\$&' );\r
307         }\r
308 \r
309         var emailProtection = editor.config.emailProtection || '';\r
310 \r
311         // Compile the protection function pattern.\r
312         if ( emailProtection && emailProtection != 'encode' )\r
313         {\r
314                 var compiledProtectionFunction = {};\r
315 \r
316                 emailProtection.replace( /^([^(]+)\(([^)]+)\)$/, function( match, funcName, params )\r
317                 {\r
318                         compiledProtectionFunction.name = funcName;\r
319                         compiledProtectionFunction.params = [];\r
320                         params.replace( /[^,\s]+/g, function( param )\r
321                         {\r
322                                 compiledProtectionFunction.params.push( param );\r
323                         } );\r
324                 } );\r
325         }\r
326 \r
327         function protectEmailLinkAsFunction( email )\r
328         {\r
329                 var retval,\r
330                         name = compiledProtectionFunction.name,\r
331                         params = compiledProtectionFunction.params,\r
332                         paramName,\r
333                         paramValue;\r
334 \r
335                 retval = [ name, '(' ];\r
336                 for ( var i = 0; i < params.length; i++ )\r
337                 {\r
338                         paramName = params[ i ].toLowerCase();\r
339                         paramValue = email[ paramName ];\r
340 \r
341                         i > 0 && retval.push( ',' );\r
342                         retval.push( '\'',\r
343                                                  paramValue ?\r
344                                                  escapeSingleQuote( encodeURIComponent( email[ paramName ] ) )\r
345                                                  : '',\r
346                                                  '\'');\r
347                 }\r
348                 retval.push( ')' );\r
349                 return retval.join( '' );\r
350         }\r
351 \r
352         function protectEmailAddressAsEncodedString( address )\r
353         {\r
354                 var charCode,\r
355                         length = address.length,\r
356                         encodedChars = [];\r
357                 for ( var i = 0; i < length; i++ )\r
358                 {\r
359                         charCode = address.charCodeAt( i );\r
360                         encodedChars.push( charCode );\r
361                 }\r
362                 return 'String.fromCharCode(' + encodedChars.join( ',' ) + ')';\r
363         }\r
364 \r
365         return {\r
366                 title : editor.lang.link.title,\r
367                 minWidth : 350,\r
368                 minHeight : 230,\r
369                 contents : [\r
370                         {\r
371                                 id : 'info',\r
372                                 label : editor.lang.link.info,\r
373                                 title : editor.lang.link.info,\r
374                                 elements :\r
375                                 [\r
376                                         {\r
377                                                 id : 'linkType',\r
378                                                 type : 'select',\r
379                                                 label : editor.lang.link.type,\r
380                                                 'default' : 'url',\r
381                                                 items :\r
382                                                 [\r
383                                                         [ editor.lang.link.toUrl, 'url' ],\r
384                                                         [ editor.lang.link.toAnchor, 'anchor' ],\r
385                                                         [ editor.lang.link.toEmail, 'email' ]\r
386                                                 ],\r
387                                                 onChange : linkTypeChanged,\r
388                                                 setup : function( data )\r
389                                                 {\r
390                                                         if ( data.type )\r
391                                                                 this.setValue( data.type );\r
392                                                 },\r
393                                                 commit : function( data )\r
394                                                 {\r
395                                                         data.type = this.getValue();\r
396                                                 }\r
397                                         },\r
398                                         {\r
399                                                 type : 'vbox',\r
400                                                 id : 'urlOptions',\r
401                                                 children :\r
402                                                 [\r
403                                                         {\r
404                                                                 type : 'hbox',\r
405                                                                 widths : [ '25%', '75%' ],\r
406                                                                 children :\r
407                                                                 [\r
408                                                                         {\r
409                                                                                 id : 'protocol',\r
410                                                                                 type : 'select',\r
411                                                                                 label : editor.lang.common.protocol,\r
412                                                                                 'default' : 'http://',\r
413                                                                                 style : 'width : 100%;',\r
414                                                                                 items :\r
415                                                                                 [\r
416                                                                                         [ 'http://' ],\r
417                                                                                         [ 'https://' ],\r
418                                                                                         [ 'ftp://' ],\r
419                                                                                         [ 'news://' ],\r
420                                                                                         [ '<other>', '' ]\r
421                                                                                 ],\r
422                                                                                 setup : function( data )\r
423                                                                                 {\r
424                                                                                         if ( data.url )\r
425                                                                                                 this.setValue( data.url.protocol || '' );\r
426                                                                                 },\r
427                                                                                 commit : function( data )\r
428                                                                                 {\r
429                                                                                         if ( !data.url )\r
430                                                                                                 data.url = {};\r
431 \r
432                                                                                         data.url.protocol = this.getValue();\r
433                                                                                 }\r
434                                                                         },\r
435                                                                         {\r
436                                                                                 type : 'text',\r
437                                                                                 id : 'url',\r
438                                                                                 label : editor.lang.common.url,\r
439                                                                                 required: true,\r
440                                                                                 onLoad : function ()\r
441                                                                                 {\r
442                                                                                         this.allowOnChange = true;\r
443                                                                                 },\r
444                                                                                 onKeyUp : function()\r
445                                                                                 {\r
446                                                                                         this.allowOnChange = false;\r
447                                                                                         var     protocolCmb = this.getDialog().getContentElement( 'info', 'protocol' ),\r
448                                                                                                 url = this.getValue(),\r
449                                                                                                 urlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/gi,\r
450                                                                                                 urlOnChangeTestOther = /^((javascript:)|[#\/\.])/gi;\r
451 \r
452                                                                                         var protocol = urlOnChangeProtocol.exec( url );\r
453                                                                                         if ( protocol )\r
454                                                                                         {\r
455                                                                                                 this.setValue( url.substr( protocol[ 0 ].length ) );\r
456                                                                                                 protocolCmb.setValue( protocol[ 0 ].toLowerCase() );\r
457                                                                                         }\r
458                                                                                         else if ( urlOnChangeTestOther.test( url ) )\r
459                                                                                                 protocolCmb.setValue( '' );\r
460 \r
461                                                                                         this.allowOnChange = true;\r
462                                                                                 },\r
463                                                                                 onChange : function()\r
464                                                                                 {\r
465                                                                                         if ( this.allowOnChange )               // Dont't call on dialog load.\r
466                                                                                                 this.onKeyUp();\r
467                                                                                 },\r
468                                                                                 validate : function()\r
469                                                                                 {\r
470                                                                                         var dialog = this.getDialog();\r
471 \r
472                                                                                         if ( dialog.getContentElement( 'info', 'linkType' ) &&\r
473                                                                                                         dialog.getValueOf( 'info', 'linkType' ) != 'url' )\r
474                                                                                                 return true;\r
475 \r
476                                                                                         if ( this.getDialog().fakeObj ) // Edit Anchor.\r
477                                                                                                 return true;\r
478 \r
479                                                                                         var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noUrl );\r
480                                                                                         return func.apply( this );\r
481                                                                                 },\r
482                                                                                 setup : function( data )\r
483                                                                                 {\r
484                                                                                         this.allowOnChange = false;\r
485                                                                                         if ( data.url )\r
486                                                                                                 this.setValue( data.url.url );\r
487                                                                                         this.allowOnChange = true;\r
488 \r
489                                                                                 },\r
490                                                                                 commit : function( data )\r
491                                                                                 {\r
492                                                                                         // IE will not trigger the onChange event if the mouse has been used\r
493                                                                                         // to carry all the operations #4724\r
494                                                                                         this.onChange();\r
495 \r
496                                                                                         if ( !data.url )\r
497                                                                                                 data.url = {};\r
498 \r
499                                                                                         data.url.url = this.getValue();\r
500                                                                                         this.allowOnChange = false;\r
501                                                                                 }\r
502                                                                         }\r
503                                                                 ],\r
504                                                                 setup : function( data )\r
505                                                                 {\r
506                                                                         if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )\r
507                                                                                 this.getElement().show();\r
508                                                                 }\r
509                                                         },\r
510                                                         {\r
511                                                                 type : 'button',\r
512                                                                 id : 'browse',\r
513                                                                 hidden : 'true',\r
514                                                                 filebrowser : 'info:url',\r
515                                                                 label : editor.lang.common.browseServer\r
516                                                         }\r
517                                                 ]\r
518                                         },\r
519                                         {\r
520                                                 type : 'vbox',\r
521                                                 id : 'anchorOptions',\r
522                                                 width : 260,\r
523                                                 align : 'center',\r
524                                                 padding : 0,\r
525                                                 children :\r
526                                                 [\r
527                                                         {\r
528                                                                 type : 'fieldset',\r
529                                                                 id : 'selectAnchorText',\r
530                                                                 label : editor.lang.link.selectAnchor,\r
531                                                                 setup : function( data )\r
532                                                                 {\r
533                                                                         if ( data.anchors.length > 0 )\r
534                                                                                 this.getElement().show();\r
535                                                                         else\r
536                                                                                 this.getElement().hide();\r
537                                                                 },\r
538                                                                 children :\r
539                                                                 [\r
540                                                                         {\r
541                                                                                 type : 'hbox',\r
542                                                                                 id : 'selectAnchor',\r
543                                                                                 children :\r
544                                                                                 [\r
545                                                                                         {\r
546                                                                                                 type : 'select',\r
547                                                                                                 id : 'anchorName',\r
548                                                                                                 'default' : '',\r
549                                                                                                 label : editor.lang.link.anchorName,\r
550                                                                                                 style : 'width: 100%;',\r
551                                                                                                 items :\r
552                                                                                                 [\r
553                                                                                                         [ '' ]\r
554                                                                                                 ],\r
555                                                                                                 setup : function( data )\r
556                                                                                                 {\r
557                                                                                                         this.clear();\r
558                                                                                                         this.add( '' );\r
559                                                                                                         for ( var i = 0 ; i < data.anchors.length ; i++ )\r
560                                                                                                         {\r
561                                                                                                                 if ( data.anchors[i].name )\r
562                                                                                                                         this.add( data.anchors[i].name );\r
563                                                                                                         }\r
564 \r
565                                                                                                         if ( data.anchor )\r
566                                                                                                                 this.setValue( data.anchor.name );\r
567 \r
568                                                                                                         var linkType = this.getDialog().getContentElement( 'info', 'linkType' );\r
569                                                                                                         if ( linkType && linkType.getValue() == 'email' )\r
570                                                                                                                 this.focus();\r
571                                                                                                 },\r
572                                                                                                 commit : function( data )\r
573                                                                                                 {\r
574                                                                                                         if ( !data.anchor )\r
575                                                                                                                 data.anchor = {};\r
576 \r
577                                                                                                         data.anchor.name = this.getValue();\r
578                                                                                                 }\r
579                                                                                         },\r
580                                                                                         {\r
581                                                                                                 type : 'select',\r
582                                                                                                 id : 'anchorId',\r
583                                                                                                 'default' : '',\r
584                                                                                                 label : editor.lang.link.anchorId,\r
585                                                                                                 style : 'width: 100%;',\r
586                                                                                                 items :\r
587                                                                                                 [\r
588                                                                                                         [ '' ]\r
589                                                                                                 ],\r
590                                                                                                 setup : function( data )\r
591                                                                                                 {\r
592                                                                                                         this.clear();\r
593                                                                                                         this.add( '' );\r
594                                                                                                         for ( var i = 0 ; i < data.anchors.length ; i++ )\r
595                                                                                                         {\r
596                                                                                                                 if ( data.anchors[i].id )\r
597                                                                                                                         this.add( data.anchors[i].id );\r
598                                                                                                         }\r
599 \r
600                                                                                                         if ( data.anchor )\r
601                                                                                                                 this.setValue( data.anchor.id );\r
602                                                                                                 },\r
603                                                                                                 commit : function( data )\r
604                                                                                                 {\r
605                                                                                                         if ( !data.anchor )\r
606                                                                                                                 data.anchor = {};\r
607 \r
608                                                                                                         data.anchor.id = this.getValue();\r
609                                                                                                 }\r
610                                                                                         }\r
611                                                                                 ],\r
612                                                                                 setup : function( data )\r
613                                                                                 {\r
614                                                                                         if ( data.anchors.length > 0 )\r
615                                                                                                 this.getElement().show();\r
616                                                                                         else\r
617                                                                                                 this.getElement().hide();\r
618                                                                                 }\r
619                                                                         }\r
620                                                                 ]\r
621                                                         },\r
622                                                         {\r
623                                                                 type : 'html',\r
624                                                                 id : 'noAnchors',\r
625                                                                 style : 'text-align: center;',\r
626                                                                 html : '<div role="label" tabIndex="-1">' + CKEDITOR.tools.htmlEncode( editor.lang.link.noAnchors ) + '</div>',\r
627                                                                 // Focus the first element defined in above html.\r
628                                                                 focus : true,\r
629                                                                 setup : function( data )\r
630                                                                 {\r
631                                                                         if ( data.anchors.length < 1 )\r
632                                                                                 this.getElement().show();\r
633                                                                         else\r
634                                                                                 this.getElement().hide();\r
635                                                                 }\r
636                                                         }\r
637                                                 ],\r
638                                                 setup : function( data )\r
639                                                 {\r
640                                                         if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )\r
641                                                                 this.getElement().hide();\r
642                                                 }\r
643                                         },\r
644                                         {\r
645                                                 type :  'vbox',\r
646                                                 id : 'emailOptions',\r
647                                                 padding : 1,\r
648                                                 children :\r
649                                                 [\r
650                                                         {\r
651                                                                 type : 'text',\r
652                                                                 id : 'emailAddress',\r
653                                                                 label : editor.lang.link.emailAddress,\r
654                                                                 required : true,\r
655                                                                 validate : function()\r
656                                                                 {\r
657                                                                         var dialog = this.getDialog();\r
658 \r
659                                                                         if ( !dialog.getContentElement( 'info', 'linkType' ) ||\r
660                                                                                         dialog.getValueOf( 'info', 'linkType' ) != 'email' )\r
661                                                                                 return true;\r
662 \r
663                                                                         var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noEmail );\r
664                                                                         return func.apply( this );\r
665                                                                 },\r
666                                                                 setup : function( data )\r
667                                                                 {\r
668                                                                         if ( data.email )\r
669                                                                                 this.setValue( data.email.address );\r
670 \r
671                                                                         var linkType = this.getDialog().getContentElement( 'info', 'linkType' );\r
672                                                                         if ( linkType && linkType.getValue() == 'email' )\r
673                                                                                 this.select();\r
674                                                                 },\r
675                                                                 commit : function( data )\r
676                                                                 {\r
677                                                                         if ( !data.email )\r
678                                                                                 data.email = {};\r
679 \r
680                                                                         data.email.address = this.getValue();\r
681                                                                 }\r
682                                                         },\r
683                                                         {\r
684                                                                 type : 'text',\r
685                                                                 id : 'emailSubject',\r
686                                                                 label : editor.lang.link.emailSubject,\r
687                                                                 setup : function( data )\r
688                                                                 {\r
689                                                                         if ( data.email )\r
690                                                                                 this.setValue( data.email.subject );\r
691                                                                 },\r
692                                                                 commit : function( data )\r
693                                                                 {\r
694                                                                         if ( !data.email )\r
695                                                                                 data.email = {};\r
696 \r
697                                                                         data.email.subject = this.getValue();\r
698                                                                 }\r
699                                                         },\r
700                                                         {\r
701                                                                 type : 'textarea',\r
702                                                                 id : 'emailBody',\r
703                                                                 label : editor.lang.link.emailBody,\r
704                                                                 rows : 3,\r
705                                                                 'default' : '',\r
706                                                                 setup : function( data )\r
707                                                                 {\r
708                                                                         if ( data.email )\r
709                                                                                 this.setValue( data.email.body );\r
710                                                                 },\r
711                                                                 commit : function( data )\r
712                                                                 {\r
713                                                                         if ( !data.email )\r
714                                                                                 data.email = {};\r
715 \r
716                                                                         data.email.body = this.getValue();\r
717                                                                 }\r
718                                                         }\r
719                                                 ],\r
720                                                 setup : function( data )\r
721                                                 {\r
722                                                         if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )\r
723                                                                 this.getElement().hide();\r
724                                                 }\r
725                                         }\r
726                                 ]\r
727                         },\r
728                         {\r
729                                 id : 'target',\r
730                                 label : editor.lang.link.target,\r
731                                 title : editor.lang.link.target,\r
732                                 elements :\r
733                                 [\r
734                                         {\r
735                                                 type : 'hbox',\r
736                                                 widths : [ '50%', '50%' ],\r
737                                                 children :\r
738                                                 [\r
739                                                         {\r
740                                                                 type : 'select',\r
741                                                                 id : 'linkTargetType',\r
742                                                                 label : editor.lang.common.target,\r
743                                                                 'default' : 'notSet',\r
744                                                                 style : 'width : 100%;',\r
745                                                                 'items' :\r
746                                                                 [\r
747                                                                         [ editor.lang.common.notSet, 'notSet' ],\r
748                                                                         [ editor.lang.link.targetFrame, 'frame' ],\r
749                                                                         [ editor.lang.link.targetPopup, 'popup' ],\r
750                                                                         [ editor.lang.common.targetNew, '_blank' ],\r
751                                                                         [ editor.lang.common.targetTop, '_top' ],\r
752                                                                         [ editor.lang.common.targetSelf, '_self' ],\r
753                                                                         [ editor.lang.common.targetParent, '_parent' ]\r
754                                                                 ],\r
755                                                                 onChange : targetChanged,\r
756                                                                 setup : function( data )\r
757                                                                 {\r
758                                                                         if ( data.target )\r
759                                                                                 this.setValue( data.target.type );\r
760                                                                 },\r
761                                                                 commit : function( data )\r
762                                                                 {\r
763                                                                         if ( !data.target )\r
764                                                                                 data.target = {};\r
765 \r
766                                                                         data.target.type = this.getValue();\r
767                                                                 }\r
768                                                         },\r
769                                                         {\r
770                                                                 type : 'text',\r
771                                                                 id : 'linkTargetName',\r
772                                                                 label : editor.lang.link.targetFrameName,\r
773                                                                 'default' : '',\r
774                                                                 setup : function( data )\r
775                                                                 {\r
776                                                                         if ( data.target )\r
777                                                                                 this.setValue( data.target.name );\r
778                                                                 },\r
779                                                                 commit : function( data )\r
780                                                                 {\r
781                                                                         if ( !data.target )\r
782                                                                                 data.target = {};\r
783 \r
784                                                                         data.target.name = this.getValue();\r
785                                                                 }\r
786                                                         }\r
787                                                 ]\r
788                                         },\r
789                                         {\r
790                                                 type : 'vbox',\r
791                                                 width : 260,\r
792                                                 align : 'center',\r
793                                                 padding : 2,\r
794                                                 id : 'popupFeatures',\r
795                                                 children :\r
796                                                 [\r
797                                                         {\r
798                                                                 type : 'fieldset',\r
799                                                                 label : editor.lang.link.popupFeatures,\r
800                                                                 children :\r
801                                                                 [\r
802                                                                         {\r
803                                                                                 type : 'hbox',\r
804                                                                                 children :\r
805                                                                                 [\r
806                                                                                         {\r
807                                                                                                 type : 'checkbox',\r
808                                                                                                 id : 'resizable',\r
809                                                                                                 label : editor.lang.link.popupResizable,\r
810                                                                                                 setup : setupPopupParams,\r
811                                                                                                 commit : commitPopupParams\r
812                                                                                         },\r
813                                                                                         {\r
814                                                                                                 type : 'checkbox',\r
815                                                                                                 id : 'status',\r
816                                                                                                 label : editor.lang.link.popupStatusBar,\r
817                                                                                                 setup : setupPopupParams,\r
818                                                                                                 commit : commitPopupParams\r
819 \r
820                                                                                         }\r
821                                                                                 ]\r
822                                                                         },\r
823                                                                         {\r
824                                                                                 type : 'hbox',\r
825                                                                                 children :\r
826                                                                                 [\r
827                                                                                         {\r
828                                                                                                 type : 'checkbox',\r
829                                                                                                 id : 'location',\r
830                                                                                                 label : editor.lang.link.popupLocationBar,\r
831                                                                                                 setup : setupPopupParams,\r
832                                                                                                 commit : commitPopupParams\r
833 \r
834                                                                                         },\r
835                                                                                         {\r
836                                                                                                 type : 'checkbox',\r
837                                                                                                 id : 'toolbar',\r
838                                                                                                 label : editor.lang.link.popupToolbar,\r
839                                                                                                 setup : setupPopupParams,\r
840                                                                                                 commit : commitPopupParams\r
841 \r
842                                                                                         }\r
843                                                                                 ]\r
844                                                                         },\r
845                                                                         {\r
846                                                                                 type : 'hbox',\r
847                                                                                 children :\r
848                                                                                 [\r
849                                                                                         {\r
850                                                                                                 type : 'checkbox',\r
851                                                                                                 id : 'menubar',\r
852                                                                                                 label : editor.lang.link.popupMenuBar,\r
853                                                                                                 setup : setupPopupParams,\r
854                                                                                                 commit : commitPopupParams\r
855 \r
856                                                                                         },\r
857                                                                                         {\r
858                                                                                                 type : 'checkbox',\r
859                                                                                                 id : 'fullscreen',\r
860                                                                                                 label : editor.lang.link.popupFullScreen,\r
861                                                                                                 setup : setupPopupParams,\r
862                                                                                                 commit : commitPopupParams\r
863 \r
864                                                                                         }\r
865                                                                                 ]\r
866                                                                         },\r
867                                                                         {\r
868                                                                                 type : 'hbox',\r
869                                                                                 children :\r
870                                                                                 [\r
871                                                                                         {\r
872                                                                                                 type : 'checkbox',\r
873                                                                                                 id : 'scrollbars',\r
874                                                                                                 label : editor.lang.link.popupScrollBars,\r
875                                                                                                 setup : setupPopupParams,\r
876                                                                                                 commit : commitPopupParams\r
877 \r
878                                                                                         },\r
879                                                                                         {\r
880                                                                                                 type : 'checkbox',\r
881                                                                                                 id : 'dependent',\r
882                                                                                                 label : editor.lang.link.popupDependent,\r
883                                                                                                 setup : setupPopupParams,\r
884                                                                                                 commit : commitPopupParams\r
885 \r
886                                                                                         }\r
887                                                                                 ]\r
888                                                                         },\r
889                                                                         {\r
890                                                                                 type : 'hbox',\r
891                                                                                 children :\r
892                                                                                 [\r
893                                                                                         {\r
894                                                                                                 type :  'text',\r
895                                                                                                 widths : [ '30%', '70%' ],\r
896                                                                                                 labelLayout : 'horizontal',\r
897                                                                                                 label : editor.lang.link.popupWidth,\r
898                                                                                                 id : 'width',\r
899                                                                                                 setup : setupPopupParams,\r
900                                                                                                 commit : commitPopupParams\r
901 \r
902                                                                                         },\r
903                                                                                         {\r
904                                                                                                 type :  'text',\r
905                                                                                                 labelLayout : 'horizontal',\r
906                                                                                                 widths : [ '55%', '45%' ],\r
907                                                                                                 label : editor.lang.link.popupLeft,\r
908                                                                                                 id : 'left',\r
909                                                                                                 setup : setupPopupParams,\r
910                                                                                                 commit : commitPopupParams\r
911 \r
912                                                                                         }\r
913                                                                                 ]\r
914                                                                         },\r
915                                                                         {\r
916                                                                                 type : 'hbox',\r
917                                                                                 children :\r
918                                                                                 [\r
919                                                                                         {\r
920                                                                                                 type :  'text',\r
921                                                                                                 labelLayout : 'horizontal',\r
922                                                                                                 widths : [ '30%', '70%' ],\r
923                                                                                                 label : editor.lang.link.popupHeight,\r
924                                                                                                 id : 'height',\r
925                                                                                                 setup : setupPopupParams,\r
926                                                                                                 commit : commitPopupParams\r
927 \r
928                                                                                         },\r
929                                                                                         {\r
930                                                                                                 type :  'text',\r
931                                                                                                 labelLayout : 'horizontal',\r
932                                                                                                 label : editor.lang.link.popupTop,\r
933                                                                                                 widths : [ '55%', '45%' ],\r
934                                                                                                 id : 'top',\r
935                                                                                                 setup : setupPopupParams,\r
936                                                                                                 commit : commitPopupParams\r
937 \r
938                                                                                         }\r
939                                                                                 ]\r
940                                                                         }\r
941                                                                 ]\r
942                                                         }\r
943                                                 ]\r
944                                         }\r
945                                 ]\r
946                         },\r
947                         {\r
948                                 id : 'upload',\r
949                                 label : editor.lang.link.upload,\r
950                                 title : editor.lang.link.upload,\r
951                                 hidden : true,\r
952                                 filebrowser : 'uploadButton',\r
953                                 elements :\r
954                                 [\r
955                                         {\r
956                                                 type : 'file',\r
957                                                 id : 'upload',\r
958                                                 label : editor.lang.common.upload,\r
959                                                 style: 'height:40px',\r
960                                                 size : 29\r
961                                         },\r
962                                         {\r
963                                                 type : 'fileButton',\r
964                                                 id : 'uploadButton',\r
965                                                 label : editor.lang.common.uploadSubmit,\r
966                                                 filebrowser : 'info:url',\r
967                                                 'for' : [ 'upload', 'upload' ]\r
968                                         }\r
969                                 ]\r
970                         },\r
971                         {\r
972                                 id : 'advanced',\r
973                                 label : editor.lang.link.advanced,\r
974                                 title : editor.lang.link.advanced,\r
975                                 elements :\r
976                                 [\r
977                                         {\r
978                                                 type : 'vbox',\r
979                                                 padding : 1,\r
980                                                 children :\r
981                                                 [\r
982                                                         {\r
983                                                                 type : 'hbox',\r
984                                                                 widths : [ '45%', '35%', '20%' ],\r
985                                                                 children :\r
986                                                                 [\r
987                                                                         {\r
988                                                                                 type : 'text',\r
989                                                                                 id : 'advId',\r
990                                                                                 label : editor.lang.link.id,\r
991                                                                                 setup : setupAdvParams,\r
992                                                                                 commit : commitAdvParams\r
993                                                                         },\r
994                                                                         {\r
995                                                                                 type : 'select',\r
996                                                                                 id : 'advLangDir',\r
997                                                                                 label : editor.lang.link.langDir,\r
998                                                                                 'default' : '',\r
999                                                                                 style : 'width:110px',\r
1000                                                                                 items :\r
1001                                                                                 [\r
1002                                                                                         [ editor.lang.common.notSet, '' ],\r
1003                                                                                         [ editor.lang.link.langDirLTR, 'ltr' ],\r
1004                                                                                         [ editor.lang.link.langDirRTL, 'rtl' ]\r
1005                                                                                 ],\r
1006                                                                                 setup : setupAdvParams,\r
1007                                                                                 commit : commitAdvParams\r
1008                                                                         },\r
1009                                                                         {\r
1010                                                                                 type : 'text',\r
1011                                                                                 id : 'advAccessKey',\r
1012                                                                                 width : '80px',\r
1013                                                                                 label : editor.lang.link.acccessKey,\r
1014                                                                                 maxLength : 1,\r
1015                                                                                 setup : setupAdvParams,\r
1016                                                                                 commit : commitAdvParams\r
1017 \r
1018                                                                         }\r
1019                                                                 ]\r
1020                                                         },\r
1021                                                         {\r
1022                                                                 type : 'hbox',\r
1023                                                                 widths : [ '45%', '35%', '20%' ],\r
1024                                                                 children :\r
1025                                                                 [\r
1026                                                                         {\r
1027                                                                                 type : 'text',\r
1028                                                                                 label : editor.lang.link.name,\r
1029                                                                                 id : 'advName',\r
1030                                                                                 setup : setupAdvParams,\r
1031                                                                                 commit : commitAdvParams\r
1032 \r
1033                                                                         },\r
1034                                                                         {\r
1035                                                                                 type : 'text',\r
1036                                                                                 label : editor.lang.link.langCode,\r
1037                                                                                 id : 'advLangCode',\r
1038                                                                                 width : '110px',\r
1039                                                                                 'default' : '',\r
1040                                                                                 setup : setupAdvParams,\r
1041                                                                                 commit : commitAdvParams\r
1042 \r
1043                                                                         },\r
1044                                                                         {\r
1045                                                                                 type : 'text',\r
1046                                                                                 label : editor.lang.link.tabIndex,\r
1047                                                                                 id : 'advTabIndex',\r
1048                                                                                 width : '80px',\r
1049                                                                                 maxLength : 5,\r
1050                                                                                 setup : setupAdvParams,\r
1051                                                                                 commit : commitAdvParams\r
1052 \r
1053                                                                         }\r
1054                                                                 ]\r
1055                                                         }\r
1056                                                 ]\r
1057                                         },\r
1058                                         {\r
1059                                                 type : 'vbox',\r
1060                                                 padding : 1,\r
1061                                                 children :\r
1062                                                 [\r
1063                                                         {\r
1064                                                                 type : 'hbox',\r
1065                                                                 widths : [ '45%', '55%' ],\r
1066                                                                 children :\r
1067                                                                 [\r
1068                                                                         {\r
1069                                                                                 type : 'text',\r
1070                                                                                 label : editor.lang.link.advisoryTitle,\r
1071                                                                                 'default' : '',\r
1072                                                                                 id : 'advTitle',\r
1073                                                                                 setup : setupAdvParams,\r
1074                                                                                 commit : commitAdvParams\r
1075 \r
1076                                                                         },\r
1077                                                                         {\r
1078                                                                                 type : 'text',\r
1079                                                                                 label : editor.lang.link.advisoryContentType,\r
1080                                                                                 'default' : '',\r
1081                                                                                 id : 'advContentType',\r
1082                                                                                 setup : setupAdvParams,\r
1083                                                                                 commit : commitAdvParams\r
1084 \r
1085                                                                         }\r
1086                                                                 ]\r
1087                                                         },\r
1088                                                         {\r
1089                                                                 type : 'hbox',\r
1090                                                                 widths : [ '45%', '55%' ],\r
1091                                                                 children :\r
1092                                                                 [\r
1093                                                                         {\r
1094                                                                                 type : 'text',\r
1095                                                                                 label : editor.lang.link.cssClasses,\r
1096                                                                                 'default' : '',\r
1097                                                                                 id : 'advCSSClasses',\r
1098                                                                                 setup : setupAdvParams,\r
1099                                                                                 commit : commitAdvParams\r
1100 \r
1101                                                                         },\r
1102                                                                         {\r
1103                                                                                 type : 'text',\r
1104                                                                                 label : editor.lang.link.charset,\r
1105                                                                                 'default' : '',\r
1106                                                                                 id : 'advCharset',\r
1107                                                                                 setup : setupAdvParams,\r
1108                                                                                 commit : commitAdvParams\r
1109 \r
1110                                                                         }\r
1111                                                                 ]\r
1112                                                         },\r
1113                                                         {\r
1114                                                                 type : 'hbox',\r
1115                                                                 children :\r
1116                                                                 [\r
1117                                                                         {\r
1118                                                                                 type : 'text',\r
1119                                                                                 label : editor.lang.link.styles,\r
1120                                                                                 'default' : '',\r
1121                                                                                 id : 'advStyles',\r
1122                                                                                 setup : setupAdvParams,\r
1123                                                                                 commit : commitAdvParams\r
1124 \r
1125                                                                         }\r
1126                                                                 ]\r
1127                                                         }\r
1128                                                 ]\r
1129                                         }\r
1130                                 ]\r
1131                         }\r
1132                 ],\r
1133                 onShow : function()\r
1134                 {\r
1135                         this.fakeObj = false;\r
1136 \r
1137                         var editor = this.getParentEditor(),\r
1138                                 selection = editor.getSelection(),\r
1139                                 ranges = selection.getRanges(),\r
1140                                 element = null,\r
1141                                 me = this;\r
1142                         // Fill in all the relevant fields if there's already one link selected.\r
1143                         if ( ranges.length == 1 )\r
1144                         {\r
1145 \r
1146                                 var rangeRoot = ranges[0].getCommonAncestor( true );\r
1147                                 element = rangeRoot.getAscendant( 'a', true );\r
1148                                 if ( element && element.getAttribute( 'href' ) )\r
1149                                 {\r
1150                                         selection.selectElement( element );\r
1151                                 }\r
1152                                 else if ( ( element = rangeRoot.getAscendant( 'img', true ) ) &&\r
1153                                                  element.getAttribute( '_cke_real_element_type' ) &&\r
1154                                                  element.getAttribute( '_cke_real_element_type' ) == 'anchor' )\r
1155                                 {\r
1156                                         this.fakeObj = element;\r
1157                                         element = editor.restoreRealElement( this.fakeObj );\r
1158                                         selection.selectElement( this.fakeObj );\r
1159                                 }\r
1160                                 else\r
1161                                         element = null;\r
1162                         }\r
1163 \r
1164                         this.setupContent( parseLink.apply( this, [ editor, element ] ) );\r
1165                 },\r
1166                 onOk : function()\r
1167                 {\r
1168                         var attributes = { href : 'javascript:void(0)/*' + CKEDITOR.tools.getNextNumber() + '*/' },\r
1169                                 removeAttributes = [],\r
1170                                 data = { href : attributes.href },\r
1171                                 me = this,\r
1172                                 editor = this.getParentEditor();\r
1173 \r
1174                         this.commitContent( data );\r
1175 \r
1176                         // Compose the URL.\r
1177                         switch ( data.type || 'url' )\r
1178                         {\r
1179                                 case 'url':\r
1180                                         var protocol = ( data.url && data.url.protocol != undefined ) ? data.url.protocol : 'http://',\r
1181                                                 url = ( data.url && data.url.url ) || '';\r
1182                                         attributes._cke_saved_href = ( url.indexOf( '/' ) === 0 ) ? url : protocol + url;\r
1183                                         break;\r
1184                                 case 'anchor':\r
1185                                         var name = ( data.anchor && data.anchor.name ),\r
1186                                                 id = ( data.anchor && data.anchor.id );\r
1187                                         attributes._cke_saved_href = '#' + ( name || id || '' );\r
1188                                         break;\r
1189                                 case 'email':\r
1190 \r
1191                                         var linkHref,\r
1192                                                 email = data.email,\r
1193                                                 address = email.address;\r
1194 \r
1195                                         switch( emailProtection )\r
1196                                         {\r
1197                                                 case '' :\r
1198                                                 case 'encode' :\r
1199                                                 {\r
1200                                                         var subject = encodeURIComponent( email.subject || '' ),\r
1201                                                                 body = encodeURIComponent( email.body || '' );\r
1202 \r
1203                                                         // Build the e-mail parameters first.\r
1204                                                         var argList = [];\r
1205                                                         subject && argList.push( 'subject=' + subject );\r
1206                                                         body && argList.push( 'body=' + body );\r
1207                                                         argList = argList.length ? '?' + argList.join( '&' ) : '';\r
1208 \r
1209                                                         if ( emailProtection == 'encode' )\r
1210                                                         {\r
1211                                                                 linkHref = [ 'javascript:void(location.href=\'mailto:\'+',\r
1212                                                                                          protectEmailAddressAsEncodedString( address ) ];\r
1213                                                                 // parameters are optional.\r
1214                                                                 argList && linkHref.push( '+\'', escapeSingleQuote( argList ), '\'' );\r
1215 \r
1216                                                                 linkHref.push( ')' );\r
1217                                                         }\r
1218                                                         else\r
1219                                                                 linkHref = [ 'mailto:', address, argList ];\r
1220 \r
1221                                                         break;\r
1222                                                 }\r
1223                                                 default :\r
1224                                                 {\r
1225                                                         // Separating name and domain.\r
1226                                                         var nameAndDomain = address.split( '@', 2 );\r
1227                                                         email.name = nameAndDomain[ 0 ];\r
1228                                                         email.domain = nameAndDomain[ 1 ];\r
1229 \r
1230                                                         linkHref = [ 'javascript:', protectEmailLinkAsFunction( email ) ];\r
1231                                                 }\r
1232                                         }\r
1233 \r
1234                                         attributes._cke_saved_href = linkHref.join( '' );\r
1235                                         break;\r
1236                         }\r
1237 \r
1238                         // Popups and target.\r
1239                         if ( data.target )\r
1240                         {\r
1241                                 if ( data.target.type == 'popup' )\r
1242                                 {\r
1243                                         var onclickList = [ 'window.open(this.href, \'',\r
1244                                                         data.target.name || '', '\', \'' ];\r
1245                                         var featureList = [ 'resizable', 'status', 'location', 'toolbar', 'menubar', 'fullscreen',\r
1246                                                         'scrollbars', 'dependent' ];\r
1247                                         var featureLength = featureList.length;\r
1248                                         var addFeature = function( featureName )\r
1249                                         {\r
1250                                                 if ( data.target[ featureName ] )\r
1251                                                         featureList.push( featureName + '=' + data.target[ featureName ] );\r
1252                                         };\r
1253 \r
1254                                         for ( var i = 0 ; i < featureLength ; i++ )\r
1255                                                 featureList[i] = featureList[i] + ( data.target[ featureList[i] ] ? '=yes' : '=no' ) ;\r
1256                                         addFeature( 'width' );\r
1257                                         addFeature( 'left' );\r
1258                                         addFeature( 'height' );\r
1259                                         addFeature( 'top' );\r
1260 \r
1261                                         onclickList.push( featureList.join( ',' ), '\'); return false;' );\r
1262                                         attributes[ '_cke_pa_onclick' ] = onclickList.join( '' );\r
1263                                 }\r
1264                                 else\r
1265                                 {\r
1266                                         if ( data.target.type != 'notSet' && data.target.name )\r
1267                                                 attributes.target = data.target.name;\r
1268                                         else\r
1269                                                 removeAttributes.push( 'target' );\r
1270 \r
1271                                         removeAttributes.push( '_cke_pa_onclick', 'onclick' );\r
1272                                 }\r
1273                         }\r
1274 \r
1275                         // Advanced attributes.\r
1276                         if ( data.adv )\r
1277                         {\r
1278                                 var advAttr = function( inputName, attrName )\r
1279                                 {\r
1280                                         var value = data.adv[ inputName ];\r
1281                                         if ( value )\r
1282                                                 attributes[attrName] = value;\r
1283                                         else\r
1284                                                 removeAttributes.push( attrName );\r
1285                                 };\r
1286 \r
1287                                 if ( this._.selectedElement )\r
1288                                         advAttr( 'advId', 'id' );\r
1289                                 advAttr( 'advLangDir', 'dir' );\r
1290                                 advAttr( 'advAccessKey', 'accessKey' );\r
1291                                 advAttr( 'advName', 'name' );\r
1292                                 advAttr( 'advLangCode', 'lang' );\r
1293                                 advAttr( 'advTabIndex', 'tabindex' );\r
1294                                 advAttr( 'advTitle', 'title' );\r
1295                                 advAttr( 'advContentType', 'type' );\r
1296                                 advAttr( 'advCSSClasses', 'class' );\r
1297                                 advAttr( 'advCharset', 'charset' );\r
1298                                 advAttr( 'advStyles', 'style' );\r
1299                         }\r
1300 \r
1301                         if ( !this._.selectedElement )\r
1302                         {\r
1303                                 // Create element if current selection is collapsed.\r
1304                                 var selection = editor.getSelection(),\r
1305                                         ranges = selection.getRanges();\r
1306                                 if ( ranges.length == 1 && ranges[0].collapsed )\r
1307                                 {\r
1308                                         var text = new CKEDITOR.dom.text( attributes._cke_saved_href, editor.document );\r
1309                                         ranges[0].insertNode( text );\r
1310                                         ranges[0].selectNodeContents( text );\r
1311                                         selection.selectRanges( ranges );\r
1312                                 }\r
1313 \r
1314                                 // Apply style.\r
1315                                 var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );\r
1316                                 style.type = CKEDITOR.STYLE_INLINE;             // need to override... dunno why.\r
1317                                 style.apply( editor.document );\r
1318 \r
1319                                 // Id. Apply only to the first link.\r
1320                                 if ( data.adv && data.adv.advId )\r
1321                                 {\r
1322                                         var links = this.getParentEditor().document.$.getElementsByTagName( 'a' );\r
1323                                         for ( i = 0 ; i < links.length ; i++ )\r
1324                                         {\r
1325                                                 if ( links[i].href == attributes.href )\r
1326                                                 {\r
1327                                                         links[i].id = data.adv.advId;\r
1328                                                         break;\r
1329                                                 }\r
1330                                         }\r
1331                                 }\r
1332                         }\r
1333                         else\r
1334                         {\r
1335                                 // We're only editing an existing link, so just overwrite the attributes.\r
1336                                 var element = this._.selectedElement,\r
1337                                         href = element.getAttribute( '_cke_saved_href' ),\r
1338                                         textView = element.getHtml();\r
1339 \r
1340                                 // IE BUG: Setting the name attribute to an existing link doesn't work.\r
1341                                 // Must re-create the link from weired syntax to workaround.\r
1342                                 if ( CKEDITOR.env.ie && attributes.name != element.getAttribute( 'name' ) )\r
1343                                 {\r
1344                                         var newElement = new CKEDITOR.dom.element( '<a name="' + CKEDITOR.tools.htmlEncode( attributes.name ) + '">',\r
1345                                                         editor.document );\r
1346 \r
1347                                         selection = editor.getSelection();\r
1348 \r
1349                                         element.moveChildren( newElement );\r
1350                                         element.copyAttributes( newElement, { name : 1 } );\r
1351                                         newElement.replace( element );\r
1352                                         element = newElement;\r
1353 \r
1354                                         selection.selectElement( element );\r
1355                                 }\r
1356 \r
1357                                 element.setAttributes( attributes );\r
1358                                 element.removeAttributes( removeAttributes );\r
1359                                 // Update text view when user changes protocol #4612.\r
1360                                 if (href == textView)\r
1361                                         element.setHtml( attributes._cke_saved_href );\r
1362                                 // Make the element display as an anchor if a name has been set.\r
1363                                 if ( element.getAttribute( 'name' ) )\r
1364                                         element.addClass( 'cke_anchor' );\r
1365                                 else\r
1366                                         element.removeClass( 'cke_anchor' );\r
1367 \r
1368                                 if ( this.fakeObj )\r
1369                                         editor.createFakeElement( element, 'cke_anchor', 'anchor' ).replace( this.fakeObj );\r
1370 \r
1371                                 delete this._.selectedElement;\r
1372                         }\r
1373                 },\r
1374                 onLoad : function()\r
1375                 {\r
1376                         if ( !editor.config.linkShowAdvancedTab )\r
1377                                 this.hidePage( 'advanced' );            //Hide Advanded tab.\r
1378 \r
1379                         if ( !editor.config.linkShowTargetTab )\r
1380                                 this.hidePage( 'target' );              //Hide Target tab.\r
1381 \r
1382                 },\r
1383                 // Inital focus on 'url' field if link is of type URL.\r
1384                 onFocus : function()\r
1385                 {\r
1386                         var linkType = this.getContentElement( 'info', 'linkType' ),\r
1387                                         urlField;\r
1388                         if ( linkType && linkType.getValue( ) == 'url' )\r
1389                         {\r
1390                                 urlField = this.getContentElement( 'info', 'url' );\r
1391                                 urlField.select();\r
1392                         }\r
1393                 }\r
1394         };\r
1395 });\r
1396 \r
1397 /**\r
1398  * The e-mail address anti-spam protection option. The protection will be\r
1399  * applied when creating or modifying e-mail links through the editor interface.<br>\r
1400  * Two methods of protection can be choosed:\r
1401  * <ol> <li>The e-mail parts (name, domain and any other query string) are\r
1402  *                      assembled into a function call pattern. Such function must be\r
1403  *                      provided by the developer in the pages that will use the contents.\r
1404  *              <li>Only the e-mail address is obfuscated into a special string that\r
1405  *                      has no meaning for humans or spam bots, but which is properly\r
1406  *                      rendered and accepted by the browser.</li></ol>\r
1407  * Both approaches require JavaScript to be enabled.\r
1408  * @name CKEDITOR.config.emailProtection\r
1409  * @since 3.1\r
1410  * @type String\r
1411  * @default '' (empty string = disabled)\r
1412  * @example\r
1413  * // href="mailto:tester@ckeditor.com?subject=subject&body=body"\r
1414  * config.emailProtection = '';\r
1415  * @example\r
1416  * // href="<a href=\"javascript:void(location.href=\'mailto:\'+String.fromCharCode(116,101,115,116,101,114,64,99,107,101,100,105,116,111,114,46,99,111,109)+\'?subject=subject&body=body\')\">e-mail</a>"\r
1417  * config.emailProtection = 'encode';\r
1418  * @example\r
1419  * // href="javascript:mt('tester','ckeditor.com','subject','body')"\r
1420  * config.emailProtection = 'mt(NAME,DOMAIN,SUBJECT,BODY)';\r
1421  */\r