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