]> git.immae.eu Git - perso/Immae/Projets/packagist/piedsjaloux-ckeditor-component.git/blame - sources/plugins/link/dialogs/link.js
Initial commit
[perso/Immae/Projets/packagist/piedsjaloux-ckeditor-component.git] / sources / plugins / link / dialogs / link.js
CommitLineData
3332bebe
IB
1/**\r
2 * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.\r
3 * For licensing, see LICENSE.md or http://ckeditor.com/license\r
4 */\r
5\r
6'use strict';\r
7\r
8( function() {\r
9 CKEDITOR.dialog.add( 'link', function( editor ) {\r
10 var plugin = CKEDITOR.plugins.link;\r
11\r
12 // Handles the event when the "Target" selection box is changed.\r
13 var targetChanged = function() {\r
14 var dialog = this.getDialog(),\r
15 popupFeatures = dialog.getContentElement( 'target', 'popupFeatures' ),\r
16 targetName = dialog.getContentElement( 'target', 'linkTargetName' ),\r
17 value = this.getValue();\r
18\r
19 if ( !popupFeatures || !targetName )\r
20 return;\r
21\r
22 popupFeatures = popupFeatures.getElement();\r
23 popupFeatures.hide();\r
24 targetName.setValue( '' );\r
25\r
26 switch ( value ) {\r
27 case 'frame':\r
28 targetName.setLabel( editor.lang.link.targetFrameName );\r
29 targetName.getElement().show();\r
30 break;\r
31 case 'popup':\r
32 popupFeatures.show();\r
33 targetName.setLabel( editor.lang.link.targetPopupName );\r
34 targetName.getElement().show();\r
35 break;\r
36 default:\r
37 targetName.setValue( value );\r
38 targetName.getElement().hide();\r
39 break;\r
40 }\r
41\r
42 };\r
43\r
44 // Handles the event when the "Type" selection box is changed.\r
45 var linkTypeChanged = function() {\r
46 var dialog = this.getDialog(),\r
47 partIds = [ 'urlOptions', 'anchorOptions', 'emailOptions' ],\r
48 typeValue = this.getValue(),\r
49 uploadTab = dialog.definition.getContents( 'upload' ),\r
50 uploadInitiallyHidden = uploadTab && uploadTab.hidden;\r
51\r
52 if ( typeValue == 'url' ) {\r
53 if ( editor.config.linkShowTargetTab )\r
54 dialog.showPage( 'target' );\r
55 if ( !uploadInitiallyHidden )\r
56 dialog.showPage( 'upload' );\r
57 } else {\r
58 dialog.hidePage( 'target' );\r
59 if ( !uploadInitiallyHidden )\r
60 dialog.hidePage( 'upload' );\r
61 }\r
62\r
63 for ( var i = 0; i < partIds.length; i++ ) {\r
64 var element = dialog.getContentElement( 'info', partIds[ i ] );\r
65 if ( !element )\r
66 continue;\r
67\r
68 element = element.getElement().getParent().getParent();\r
69 if ( partIds[ i ] == typeValue + 'Options' )\r
70 element.show();\r
71 else\r
72 element.hide();\r
73 }\r
74\r
75 dialog.layout();\r
76 };\r
77\r
78 var setupParams = function( page, data ) {\r
79 if ( data[ page ] )\r
80 this.setValue( data[ page ][ this.id ] || '' );\r
81 };\r
82\r
83 var setupPopupParams = function( data ) {\r
84 return setupParams.call( this, 'target', data );\r
85 };\r
86\r
87 var setupAdvParams = function( data ) {\r
88 return setupParams.call( this, 'advanced', data );\r
89 };\r
90\r
91 var commitParams = function( page, data ) {\r
92 if ( !data[ page ] )\r
93 data[ page ] = {};\r
94\r
95 data[ page ][ this.id ] = this.getValue() || '';\r
96 };\r
97\r
98 var commitPopupParams = function( data ) {\r
99 return commitParams.call( this, 'target', data );\r
100 };\r
101\r
102 var commitAdvParams = function( data ) {\r
103 return commitParams.call( this, 'advanced', data );\r
104 };\r
105\r
106 var commonLang = editor.lang.common,\r
107 linkLang = editor.lang.link,\r
108 anchors;\r
109\r
110 return {\r
111 title: linkLang.title,\r
112 minWidth: 350,\r
113 minHeight: 230,\r
114 contents: [ {\r
115 id: 'info',\r
116 label: linkLang.info,\r
117 title: linkLang.info,\r
118 elements: [ {\r
119 id: 'linkType',\r
120 type: 'select',\r
121 label: linkLang.type,\r
122 'default': 'url',\r
123 items: [\r
124 [ linkLang.toUrl, 'url' ],\r
125 [ linkLang.toAnchor, 'anchor' ],\r
126 [ linkLang.toEmail, 'email' ]\r
127 ],\r
128 onChange: linkTypeChanged,\r
129 setup: function( data ) {\r
130 this.setValue( data.type || 'url' );\r
131 },\r
132 commit: function( data ) {\r
133 data.type = this.getValue();\r
134 }\r
135 },\r
136 {\r
137 type: 'vbox',\r
138 id: 'urlOptions',\r
139 children: [ {\r
140 type: 'hbox',\r
141 widths: [ '25%', '75%' ],\r
142 children: [ {\r
143 id: 'protocol',\r
144 type: 'select',\r
145 label: commonLang.protocol,\r
146 'default': 'http://',\r
147 items: [\r
148 // Force 'ltr' for protocol names in BIDI. (#5433)\r
149 [ 'http://\u200E', 'http://' ],\r
150 [ 'https://\u200E', 'https://' ],\r
151 [ 'ftp://\u200E', 'ftp://' ],\r
152 [ 'news://\u200E', 'news://' ],\r
153 [ linkLang.other, '' ]\r
154 ],\r
155 setup: function( data ) {\r
156 if ( data.url )\r
157 this.setValue( data.url.protocol || '' );\r
158 },\r
159 commit: function( data ) {\r
160 if ( !data.url )\r
161 data.url = {};\r
162\r
163 data.url.protocol = this.getValue();\r
164 }\r
165 },\r
166 {\r
167 type: 'text',\r
168 id: 'url',\r
169 label: commonLang.url,\r
170 required: true,\r
171 onLoad: function() {\r
172 this.allowOnChange = true;\r
173 },\r
174 onKeyUp: function() {\r
175 this.allowOnChange = false;\r
176 var protocolCmb = this.getDialog().getContentElement( 'info', 'protocol' ),\r
177 url = this.getValue(),\r
178 urlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/i,\r
179 urlOnChangeTestOther = /^((javascript:)|[#\/\.\?])/i;\r
180\r
181 var protocol = urlOnChangeProtocol.exec( url );\r
182 if ( protocol ) {\r
183 this.setValue( url.substr( protocol[ 0 ].length ) );\r
184 protocolCmb.setValue( protocol[ 0 ].toLowerCase() );\r
185 } else if ( urlOnChangeTestOther.test( url ) ) {\r
186 protocolCmb.setValue( '' );\r
187 }\r
188\r
189 this.allowOnChange = true;\r
190 },\r
191 onChange: function() {\r
192 if ( this.allowOnChange ) // Dont't call on dialog load.\r
193 this.onKeyUp();\r
194 },\r
195 validate: function() {\r
196 var dialog = this.getDialog();\r
197\r
198 if ( dialog.getContentElement( 'info', 'linkType' ) && dialog.getValueOf( 'info', 'linkType' ) != 'url' )\r
199 return true;\r
200\r
201 if ( !editor.config.linkJavaScriptLinksAllowed && ( /javascript\:/ ).test( this.getValue() ) ) {\r
202 alert( commonLang.invalidValue ); // jshint ignore:line\r
203 return false;\r
204 }\r
205\r
206 if ( this.getDialog().fakeObj ) // Edit Anchor.\r
207 return true;\r
208\r
209 var func = CKEDITOR.dialog.validate.notEmpty( linkLang.noUrl );\r
210 return func.apply( this );\r
211 },\r
212 setup: function( data ) {\r
213 this.allowOnChange = false;\r
214 if ( data.url )\r
215 this.setValue( data.url.url );\r
216 this.allowOnChange = true;\r
217\r
218 },\r
219 commit: function( data ) {\r
220 // IE will not trigger the onChange event if the mouse has been used\r
221 // to carry all the operations #4724\r
222 this.onChange();\r
223\r
224 if ( !data.url )\r
225 data.url = {};\r
226\r
227 data.url.url = this.getValue();\r
228 this.allowOnChange = false;\r
229 }\r
230 } ],\r
231 setup: function() {\r
232 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )\r
233 this.getElement().show();\r
234 }\r
235 },\r
236 {\r
237 type: 'button',\r
238 id: 'browse',\r
239 hidden: 'true',\r
240 filebrowser: 'info:url',\r
241 label: commonLang.browseServer\r
242 } ]\r
243 },\r
244 {\r
245 type: 'vbox',\r
246 id: 'anchorOptions',\r
247 width: 260,\r
248 align: 'center',\r
249 padding: 0,\r
250 children: [ {\r
251 type: 'fieldset',\r
252 id: 'selectAnchorText',\r
253 label: linkLang.selectAnchor,\r
254 setup: function() {\r
255 anchors = plugin.getEditorAnchors( editor );\r
256\r
257 this.getElement()[ anchors && anchors.length ? 'show' : 'hide' ]();\r
258 },\r
259 children: [ {\r
260 type: 'hbox',\r
261 id: 'selectAnchor',\r
262 children: [ {\r
263 type: 'select',\r
264 id: 'anchorName',\r
265 'default': '',\r
266 label: linkLang.anchorName,\r
267 style: 'width: 100%;',\r
268 items: [\r
269 [ '' ]\r
270 ],\r
271 setup: function( data ) {\r
272 this.clear();\r
273 this.add( '' );\r
274\r
275 if ( anchors ) {\r
276 for ( var i = 0; i < anchors.length; i++ ) {\r
277 if ( anchors[ i ].name )\r
278 this.add( anchors[ i ].name );\r
279 }\r
280 }\r
281\r
282 if ( data.anchor )\r
283 this.setValue( data.anchor.name );\r
284\r
285 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );\r
286 if ( linkType && linkType.getValue() == 'email' )\r
287 this.focus();\r
288 },\r
289 commit: function( data ) {\r
290 if ( !data.anchor )\r
291 data.anchor = {};\r
292\r
293 data.anchor.name = this.getValue();\r
294 }\r
295 },\r
296 {\r
297 type: 'select',\r
298 id: 'anchorId',\r
299 'default': '',\r
300 label: linkLang.anchorId,\r
301 style: 'width: 100%;',\r
302 items: [\r
303 [ '' ]\r
304 ],\r
305 setup: function( data ) {\r
306 this.clear();\r
307 this.add( '' );\r
308\r
309 if ( anchors ) {\r
310 for ( var i = 0; i < anchors.length; i++ ) {\r
311 if ( anchors[ i ].id )\r
312 this.add( anchors[ i ].id );\r
313 }\r
314 }\r
315\r
316 if ( data.anchor )\r
317 this.setValue( data.anchor.id );\r
318 },\r
319 commit: function( data ) {\r
320 if ( !data.anchor )\r
321 data.anchor = {};\r
322\r
323 data.anchor.id = this.getValue();\r
324 }\r
325 } ],\r
326 setup: function() {\r
327 this.getElement()[ anchors && anchors.length ? 'show' : 'hide' ]();\r
328 }\r
329 } ]\r
330 },\r
331 {\r
332 type: 'html',\r
333 id: 'noAnchors',\r
334 style: 'text-align: center;',\r
335 html: '<div role="note" tabIndex="-1">' + CKEDITOR.tools.htmlEncode( linkLang.noAnchors ) + '</div>',\r
336 // Focus the first element defined in above html.\r
337 focus: true,\r
338 setup: function() {\r
339 this.getElement()[ anchors && anchors.length ? 'hide' : 'show' ]();\r
340 }\r
341 } ],\r
342 setup: function() {\r
343 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )\r
344 this.getElement().hide();\r
345 }\r
346 },\r
347 {\r
348 type: 'vbox',\r
349 id: 'emailOptions',\r
350 padding: 1,\r
351 children: [ {\r
352 type: 'text',\r
353 id: 'emailAddress',\r
354 label: linkLang.emailAddress,\r
355 required: true,\r
356 validate: function() {\r
357 var dialog = this.getDialog();\r
358\r
359 if ( !dialog.getContentElement( 'info', 'linkType' ) || dialog.getValueOf( 'info', 'linkType' ) != 'email' )\r
360 return true;\r
361\r
362 var func = CKEDITOR.dialog.validate.notEmpty( linkLang.noEmail );\r
363 return func.apply( this );\r
364 },\r
365 setup: function( data ) {\r
366 if ( data.email )\r
367 this.setValue( data.email.address );\r
368\r
369 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );\r
370 if ( linkType && linkType.getValue() == 'email' )\r
371 this.select();\r
372 },\r
373 commit: function( data ) {\r
374 if ( !data.email )\r
375 data.email = {};\r
376\r
377 data.email.address = this.getValue();\r
378 }\r
379 },\r
380 {\r
381 type: 'text',\r
382 id: 'emailSubject',\r
383 label: linkLang.emailSubject,\r
384 setup: function( data ) {\r
385 if ( data.email )\r
386 this.setValue( data.email.subject );\r
387 },\r
388 commit: function( data ) {\r
389 if ( !data.email )\r
390 data.email = {};\r
391\r
392 data.email.subject = this.getValue();\r
393 }\r
394 },\r
395 {\r
396 type: 'textarea',\r
397 id: 'emailBody',\r
398 label: linkLang.emailBody,\r
399 rows: 3,\r
400 'default': '',\r
401 setup: function( data ) {\r
402 if ( data.email )\r
403 this.setValue( data.email.body );\r
404 },\r
405 commit: function( data ) {\r
406 if ( !data.email )\r
407 data.email = {};\r
408\r
409 data.email.body = this.getValue();\r
410 }\r
411 } ],\r
412 setup: function() {\r
413 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )\r
414 this.getElement().hide();\r
415 }\r
416 } ]\r
417 },\r
418 {\r
419 id: 'target',\r
420 requiredContent: 'a[target]', // This is not fully correct, because some target option requires JS.\r
421 label: linkLang.target,\r
422 title: linkLang.target,\r
423 elements: [ {\r
424 type: 'hbox',\r
425 widths: [ '50%', '50%' ],\r
426 children: [ {\r
427 type: 'select',\r
428 id: 'linkTargetType',\r
429 label: commonLang.target,\r
430 'default': 'notSet',\r
431 style: 'width : 100%;',\r
432 'items': [\r
433 [ commonLang.notSet, 'notSet' ],\r
434 [ linkLang.targetFrame, 'frame' ],\r
435 [ linkLang.targetPopup, 'popup' ],\r
436 [ commonLang.targetNew, '_blank' ],\r
437 [ commonLang.targetTop, '_top' ],\r
438 [ commonLang.targetSelf, '_self' ],\r
439 [ commonLang.targetParent, '_parent' ]\r
440 ],\r
441 onChange: targetChanged,\r
442 setup: function( data ) {\r
443 if ( data.target )\r
444 this.setValue( data.target.type || 'notSet' );\r
445 targetChanged.call( this );\r
446 },\r
447 commit: function( data ) {\r
448 if ( !data.target )\r
449 data.target = {};\r
450\r
451 data.target.type = this.getValue();\r
452 }\r
453 },\r
454 {\r
455 type: 'text',\r
456 id: 'linkTargetName',\r
457 label: linkLang.targetFrameName,\r
458 'default': '',\r
459 setup: function( data ) {\r
460 if ( data.target )\r
461 this.setValue( data.target.name );\r
462 },\r
463 commit: function( data ) {\r
464 if ( !data.target )\r
465 data.target = {};\r
466\r
467 data.target.name = this.getValue().replace( /([^\x00-\x7F]|\s)/gi, '' );\r
468 }\r
469 } ]\r
470 },\r
471 {\r
472 type: 'vbox',\r
473 width: '100%',\r
474 align: 'center',\r
475 padding: 2,\r
476 id: 'popupFeatures',\r
477 children: [ {\r
478 type: 'fieldset',\r
479 label: linkLang.popupFeatures,\r
480 children: [ {\r
481 type: 'hbox',\r
482 children: [ {\r
483 type: 'checkbox',\r
484 id: 'resizable',\r
485 label: linkLang.popupResizable,\r
486 setup: setupPopupParams,\r
487 commit: commitPopupParams\r
488 },\r
489 {\r
490 type: 'checkbox',\r
491 id: 'status',\r
492 label: linkLang.popupStatusBar,\r
493 setup: setupPopupParams,\r
494 commit: commitPopupParams\r
495\r
496 } ]\r
497 },\r
498 {\r
499 type: 'hbox',\r
500 children: [ {\r
501 type: 'checkbox',\r
502 id: 'location',\r
503 label: linkLang.popupLocationBar,\r
504 setup: setupPopupParams,\r
505 commit: commitPopupParams\r
506\r
507 },\r
508 {\r
509 type: 'checkbox',\r
510 id: 'toolbar',\r
511 label: linkLang.popupToolbar,\r
512 setup: setupPopupParams,\r
513 commit: commitPopupParams\r
514\r
515 } ]\r
516 },\r
517 {\r
518 type: 'hbox',\r
519 children: [ {\r
520 type: 'checkbox',\r
521 id: 'menubar',\r
522 label: linkLang.popupMenuBar,\r
523 setup: setupPopupParams,\r
524 commit: commitPopupParams\r
525\r
526 },\r
527 {\r
528 type: 'checkbox',\r
529 id: 'fullscreen',\r
530 label: linkLang.popupFullScreen,\r
531 setup: setupPopupParams,\r
532 commit: commitPopupParams\r
533\r
534 } ]\r
535 },\r
536 {\r
537 type: 'hbox',\r
538 children: [ {\r
539 type: 'checkbox',\r
540 id: 'scrollbars',\r
541 label: linkLang.popupScrollBars,\r
542 setup: setupPopupParams,\r
543 commit: commitPopupParams\r
544\r
545 },\r
546 {\r
547 type: 'checkbox',\r
548 id: 'dependent',\r
549 label: linkLang.popupDependent,\r
550 setup: setupPopupParams,\r
551 commit: commitPopupParams\r
552\r
553 } ]\r
554 },\r
555 {\r
556 type: 'hbox',\r
557 children: [ {\r
558 type: 'text',\r
559 widths: [ '50%', '50%' ],\r
560 labelLayout: 'horizontal',\r
561 label: commonLang.width,\r
562 id: 'width',\r
563 setup: setupPopupParams,\r
564 commit: commitPopupParams\r
565\r
566 },\r
567 {\r
568 type: 'text',\r
569 labelLayout: 'horizontal',\r
570 widths: [ '50%', '50%' ],\r
571 label: linkLang.popupLeft,\r
572 id: 'left',\r
573 setup: setupPopupParams,\r
574 commit: commitPopupParams\r
575\r
576 } ]\r
577 },\r
578 {\r
579 type: 'hbox',\r
580 children: [ {\r
581 type: 'text',\r
582 labelLayout: 'horizontal',\r
583 widths: [ '50%', '50%' ],\r
584 label: commonLang.height,\r
585 id: 'height',\r
586 setup: setupPopupParams,\r
587 commit: commitPopupParams\r
588\r
589 },\r
590 {\r
591 type: 'text',\r
592 labelLayout: 'horizontal',\r
593 label: linkLang.popupTop,\r
594 widths: [ '50%', '50%' ],\r
595 id: 'top',\r
596 setup: setupPopupParams,\r
597 commit: commitPopupParams\r
598\r
599 } ]\r
600 } ]\r
601 } ]\r
602 } ]\r
603 },\r
604 {\r
605 id: 'upload',\r
606 label: linkLang.upload,\r
607 title: linkLang.upload,\r
608 hidden: true,\r
609 filebrowser: 'uploadButton',\r
610 elements: [ {\r
611 type: 'file',\r
612 id: 'upload',\r
613 label: commonLang.upload,\r
614 style: 'height:40px',\r
615 size: 29\r
616 },\r
617 {\r
618 type: 'fileButton',\r
619 id: 'uploadButton',\r
620 label: commonLang.uploadSubmit,\r
621 filebrowser: 'info:url',\r
622 'for': [ 'upload', 'upload' ]\r
623 } ]\r
624 },\r
625 {\r
626 id: 'advanced',\r
627 label: linkLang.advanced,\r
628 title: linkLang.advanced,\r
629 elements: [ {\r
630 type: 'vbox',\r
631 padding: 1,\r
632 children: [ {\r
633 type: 'hbox',\r
634 widths: [ '45%', '35%', '20%' ],\r
635 children: [ {\r
636 type: 'text',\r
637 id: 'advId',\r
638 requiredContent: 'a[id]',\r
639 label: linkLang.id,\r
640 setup: setupAdvParams,\r
641 commit: commitAdvParams\r
642 },\r
643 {\r
644 type: 'select',\r
645 id: 'advLangDir',\r
646 requiredContent: 'a[dir]',\r
647 label: linkLang.langDir,\r
648 'default': '',\r
649 style: 'width:110px',\r
650 items: [\r
651 [ commonLang.notSet, '' ],\r
652 [ linkLang.langDirLTR, 'ltr' ],\r
653 [ linkLang.langDirRTL, 'rtl' ]\r
654 ],\r
655 setup: setupAdvParams,\r
656 commit: commitAdvParams\r
657 },\r
658 {\r
659 type: 'text',\r
660 id: 'advAccessKey',\r
661 requiredContent: 'a[accesskey]',\r
662 width: '80px',\r
663 label: linkLang.acccessKey,\r
664 maxLength: 1,\r
665 setup: setupAdvParams,\r
666 commit: commitAdvParams\r
667\r
668 } ]\r
669 },\r
670 {\r
671 type: 'hbox',\r
672 widths: [ '45%', '35%', '20%' ],\r
673 children: [ {\r
674 type: 'text',\r
675 label: linkLang.name,\r
676 id: 'advName',\r
677 requiredContent: 'a[name]',\r
678 setup: setupAdvParams,\r
679 commit: commitAdvParams\r
680\r
681 },\r
682 {\r
683 type: 'text',\r
684 label: linkLang.langCode,\r
685 id: 'advLangCode',\r
686 requiredContent: 'a[lang]',\r
687 width: '110px',\r
688 'default': '',\r
689 setup: setupAdvParams,\r
690 commit: commitAdvParams\r
691\r
692 },\r
693 {\r
694 type: 'text',\r
695 label: linkLang.tabIndex,\r
696 id: 'advTabIndex',\r
697 requiredContent: 'a[tabindex]',\r
698 width: '80px',\r
699 maxLength: 5,\r
700 setup: setupAdvParams,\r
701 commit: commitAdvParams\r
702\r
703 } ]\r
704 } ]\r
705 },\r
706 {\r
707 type: 'vbox',\r
708 padding: 1,\r
709 children: [ {\r
710 type: 'hbox',\r
711 widths: [ '45%', '55%' ],\r
712 children: [ {\r
713 type: 'text',\r
714 label: linkLang.advisoryTitle,\r
715 requiredContent: 'a[title]',\r
716 'default': '',\r
717 id: 'advTitle',\r
718 setup: setupAdvParams,\r
719 commit: commitAdvParams\r
720\r
721 },\r
722 {\r
723 type: 'text',\r
724 label: linkLang.advisoryContentType,\r
725 requiredContent: 'a[type]',\r
726 'default': '',\r
727 id: 'advContentType',\r
728 setup: setupAdvParams,\r
729 commit: commitAdvParams\r
730\r
731 } ]\r
732 },\r
733 {\r
734 type: 'hbox',\r
735 widths: [ '45%', '55%' ],\r
736 children: [ {\r
737 type: 'text',\r
738 label: linkLang.cssClasses,\r
739 requiredContent: 'a(cke-xyz)', // Random text like 'xyz' will check if all are allowed.\r
740 'default': '',\r
741 id: 'advCSSClasses',\r
742 setup: setupAdvParams,\r
743 commit: commitAdvParams\r
744\r
745 },\r
746 {\r
747 type: 'text',\r
748 label: linkLang.charset,\r
749 requiredContent: 'a[charset]',\r
750 'default': '',\r
751 id: 'advCharset',\r
752 setup: setupAdvParams,\r
753 commit: commitAdvParams\r
754\r
755 } ]\r
756 },\r
757 {\r
758 type: 'hbox',\r
759 widths: [ '45%', '55%' ],\r
760 children: [ {\r
761 type: 'text',\r
762 label: linkLang.rel,\r
763 requiredContent: 'a[rel]',\r
764 'default': '',\r
765 id: 'advRel',\r
766 setup: setupAdvParams,\r
767 commit: commitAdvParams\r
768 },\r
769 {\r
770 type: 'text',\r
771 label: linkLang.styles,\r
772 requiredContent: 'a{cke-xyz}', // Random text like 'xyz' will check if all are allowed.\r
773 'default': '',\r
774 id: 'advStyles',\r
775 validate: CKEDITOR.dialog.validate.inlineStyle( editor.lang.common.invalidInlineStyle ),\r
776 setup: setupAdvParams,\r
777 commit: commitAdvParams\r
778 } ]\r
779 } ]\r
780 } ]\r
781 } ],\r
782 onShow: function() {\r
783 var editor = this.getParentEditor(),\r
784 selection = editor.getSelection(),\r
785 element = null;\r
786\r
787 // Fill in all the relevant fields if there's already one link selected.\r
788 if ( ( element = plugin.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) ) {\r
789 // Don't change selection if some element is already selected.\r
790 // For example - don't destroy fake selection.\r
791 if ( !selection.getSelectedElement() )\r
792 selection.selectElement( element );\r
793 } else {\r
794 element = null;\r
795 }\r
796\r
797 var data = plugin.parseLinkAttributes( editor, element );\r
798\r
799 // Record down the selected element in the dialog.\r
800 this._.selectedElement = element;\r
801\r
802 this.setupContent( data );\r
803 },\r
804 onOk: function() {\r
805 var data = {};\r
806\r
807 // Collect data from fields.\r
808 this.commitContent( data );\r
809\r
810 var selection = editor.getSelection(),\r
811 attributes = plugin.getLinkAttributes( editor, data );\r
812\r
813 if ( !this._.selectedElement ) {\r
814 var range = selection.getRanges()[ 0 ];\r
815\r
816 // Use link URL as text with a collapsed cursor.\r
817 if ( range.collapsed ) {\r
818 // Short mailto link text view (#5736).\r
819 var text = new CKEDITOR.dom.text( data.type == 'email' ?\r
820 data.email.address : attributes.set[ 'data-cke-saved-href' ], editor.document );\r
821 range.insertNode( text );\r
822 range.selectNodeContents( text );\r
823 }\r
824\r
825 // Apply style.\r
826 var style = new CKEDITOR.style( {\r
827 element: 'a',\r
828 attributes: attributes.set\r
829 } );\r
830\r
831 style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why.\r
832 style.applyToRange( range, editor );\r
833 range.select();\r
834 } else {\r
835 // We're only editing an existing link, so just overwrite the attributes.\r
836 var element = this._.selectedElement,\r
837 href = element.data( 'cke-saved-href' ),\r
838 textView = element.getHtml();\r
839\r
840 element.setAttributes( attributes.set );\r
841 element.removeAttributes( attributes.removed );\r
842\r
843 // Update text view when user changes protocol (#4612).\r
844 if ( href == textView || data.type == 'email' && textView.indexOf( '@' ) != -1 ) {\r
845 // Short mailto link text view (#5736).\r
846 element.setHtml( data.type == 'email' ?\r
847 data.email.address : attributes.set[ 'data-cke-saved-href' ] );\r
848\r
849 // We changed the content, so need to select it again.\r
850 selection.selectElement( element );\r
851 }\r
852\r
853 delete this._.selectedElement;\r
854 }\r
855 },\r
856 onLoad: function() {\r
857 if ( !editor.config.linkShowAdvancedTab )\r
858 this.hidePage( 'advanced' ); //Hide Advanded tab.\r
859\r
860 if ( !editor.config.linkShowTargetTab )\r
861 this.hidePage( 'target' ); //Hide Target tab.\r
862 },\r
863 // Inital focus on 'url' field if link is of type URL.\r
864 onFocus: function() {\r
865 var linkType = this.getContentElement( 'info', 'linkType' ),\r
866 urlField;\r
867\r
868 if ( linkType && linkType.getValue() == 'url' ) {\r
869 urlField = this.getContentElement( 'info', 'url' );\r
870 urlField.select();\r
871 }\r
872 }\r
873 };\r
874 } );\r
875} )();\r
876// jscs:disable maximumLineLength\r
877/**\r
878 * The e-mail address anti-spam protection option. The protection will be\r
879 * applied when creating or modifying e-mail links through the editor interface.\r
880 *\r
881 * Two methods of protection can be chosen:\r
882 *\r
883 * 1. The e-mail parts (name, domain, and any other query string) are\r
884 * assembled into a function call pattern. Such function must be\r
885 * provided by the developer in the pages that will use the contents.\r
886 * 2. Only the e-mail address is obfuscated into a special string that\r
887 * has no meaning for humans or spam bots, but which is properly\r
888 * rendered and accepted by the browser.\r
889 *\r
890 * Both approaches require JavaScript to be enabled.\r
891 *\r
892 * // href="mailto:tester@ckeditor.com?subject=subject&body=body"\r
893 * config.emailProtection = '';\r
894 *\r
895 * // 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
896 * config.emailProtection = 'encode';\r
897 *\r
898 * // href="javascript:mt('tester','ckeditor.com','subject','body')"\r
899 * config.emailProtection = 'mt(NAME,DOMAIN,SUBJECT,BODY)';\r
900 *\r
901 * @since 3.1\r
902 * @cfg {String} [emailProtection='' (empty string = disabled)]\r
903 * @member CKEDITOR.config\r
904 */\r