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