2 Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 CKEDITOR.dialog.add( 'link', function( editor )
\r
8 var plugin = CKEDITOR.plugins.link;
\r
9 // Handles the event when the "Target" selection box is changed.
\r
10 var targetChanged = function()
\r
12 var dialog = this.getDialog(),
\r
13 popupFeatures = dialog.getContentElement( 'target', 'popupFeatures' ),
\r
14 targetName = dialog.getContentElement( 'target', 'linkTargetName' ),
\r
15 value = this.getValue();
\r
17 if ( !popupFeatures || !targetName )
\r
20 popupFeatures = popupFeatures.getElement();
\r
21 popupFeatures.hide();
\r
22 targetName.setValue( '' );
\r
27 targetName.setLabel( editor.lang.link.targetFrameName );
\r
28 targetName.getElement().show();
\r
31 popupFeatures.show();
\r
32 targetName.setLabel( editor.lang.link.targetPopupName );
\r
33 targetName.getElement().show();
\r
36 targetName.setValue( value );
\r
37 targetName.getElement().hide();
\r
43 // Handles the event when the "Type" selection box is changed.
\r
44 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
52 if ( typeValue == 'url' )
\r
54 if ( editor.config.linkShowTargetTab )
\r
55 dialog.showPage( 'target' );
\r
56 if ( !uploadInitiallyHidden )
\r
57 dialog.showPage( 'upload' );
\r
61 dialog.hidePage( 'target' );
\r
62 if ( !uploadInitiallyHidden )
\r
63 dialog.hidePage( 'upload' );
\r
66 for ( var i = 0 ; i < partIds.length ; i++ )
\r
68 var element = dialog.getContentElement( 'info', partIds[i] );
\r
72 element = element.getElement().getParent().getParent();
\r
73 if ( partIds[i] == typeValue + 'Options' )
\r
82 // Loads the parameters in a selected link to the link dialog fields.
\r
83 var javascriptProtocolRegex = /^javascript:/,
\r
84 emailRegex = /^mailto:([^?]+)(?:\?(.+))?$/,
\r
85 emailSubjectRegex = /subject=([^;?:@&=$,\/]*)/,
\r
86 emailBodyRegex = /body=([^;?:@&=$,\/]*)/,
\r
87 anchorRegex = /^#(.*)$/,
\r
88 urlRegex = /^((?:http|https|ftp|news):\/\/)?(.*)$/,
\r
89 selectableTargets = /^(_(?:self|top|parent|blank))$/,
\r
90 encodedEmailLinkRegex = /^javascript:void\(location\.href='mailto:'\+String\.fromCharCode\(([^)]+)\)(?:\+'(.*)')?\)$/,
\r
91 functionCallProtectedEmailLinkRegex = /^javascript:([^(]+)\(([^)]+)\)$/;
\r
94 /\s*window.open\(\s*this\.href\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*/;
\r
95 var popupFeaturesRegex = /(?:^|,)([^=]+)=(\d+|yes|no)/gi;
\r
97 var parseLink = function( editor, element )
\r
99 var href = ( element && ( element.data( 'cke-saved-href' ) || element.getAttribute( 'href' ) ) ) || '',
\r
106 if ( ( javascriptMatch = href.match( javascriptProtocolRegex ) ) )
\r
108 if ( emailProtection == 'encode' )
\r
110 href = href.replace( encodedEmailLinkRegex,
\r
111 function ( match, protectedAddress, rest )
\r
114 String.fromCharCode.apply( String, protectedAddress.split( ',' ) ) +
\r
115 ( rest && unescapeSingleQuote( rest ) );
\r
118 // Protected email link as function call.
\r
119 else if ( emailProtection )
\r
121 href.replace( functionCallProtectedEmailLinkRegex, function( match, funcName, funcArgs )
\r
123 if ( funcName == compiledProtectionFunction.name )
\r
125 retval.type = 'email';
\r
126 var email = retval.email = {};
\r
128 var paramRegex = /[^,\s]+/g,
\r
129 paramQuoteRegex = /(^')|('$)/g,
\r
130 paramsMatch = funcArgs.match( paramRegex ),
\r
131 paramsMatchLength = paramsMatch.length,
\r
135 for ( var i = 0; i < paramsMatchLength; i++ )
\r
137 paramVal = decodeURIComponent( unescapeSingleQuote( paramsMatch[ i ].replace( paramQuoteRegex, '' ) ) );
\r
138 paramName = compiledProtectionFunction.params[ i ].toLowerCase();
\r
139 email[ paramName ] = paramVal;
\r
141 email.address = [ email.name, email.domain ].join( '@' );
\r
147 if ( !retval.type )
\r
149 if ( ( anchorMatch = href.match( anchorRegex ) ) )
\r
151 retval.type = 'anchor';
\r
152 retval.anchor = {};
\r
153 retval.anchor.name = retval.anchor.id = anchorMatch[1];
\r
155 // Protected email link as encoded string.
\r
156 else if ( ( emailMatch = href.match( emailRegex ) ) )
\r
158 var subjectMatch = href.match( emailSubjectRegex ),
\r
159 bodyMatch = href.match( emailBodyRegex );
\r
161 retval.type = 'email';
\r
162 var email = ( retval.email = {} );
\r
163 email.address = emailMatch[ 1 ];
\r
164 subjectMatch && ( email.subject = decodeURIComponent( subjectMatch[ 1 ] ) );
\r
165 bodyMatch && ( email.body = decodeURIComponent( bodyMatch[ 1 ] ) );
\r
167 // urlRegex matches empty strings, so need to check for href as well.
\r
168 else if ( href && ( urlMatch = href.match( urlRegex ) ) )
\r
170 retval.type = 'url';
\r
172 retval.url.protocol = urlMatch[1];
\r
173 retval.url.url = urlMatch[2];
\r
176 retval.type = 'url';
\r
179 // Load target and popup settings.
\r
182 var target = element.getAttribute( 'target' );
\r
183 retval.target = {};
\r
186 // IE BUG: target attribute is an empty string instead of null in IE if it's not set.
\r
189 var onclick = element.data( 'cke-pa-onclick' ) || element.getAttribute( 'onclick' ),
\r
190 onclickMatch = onclick && onclick.match( popupRegex );
\r
191 if ( onclickMatch )
\r
193 retval.target.type = 'popup';
\r
194 retval.target.name = onclickMatch[1];
\r
197 while ( ( featureMatch = popupFeaturesRegex.exec( onclickMatch[2] ) ) )
\r
199 // Some values should remain numbers (#7300)
\r
200 if ( ( featureMatch[2] == 'yes' || featureMatch[2] == '1' ) && !( featureMatch[1] in { height:1, width:1, top:1, left:1 } ) )
\r
201 retval.target[ featureMatch[1] ] = true;
\r
202 else if ( isFinite( featureMatch[2] ) )
\r
203 retval.target[ featureMatch[1] ] = featureMatch[2];
\r
209 var targetMatch = target.match( selectableTargets );
\r
211 retval.target.type = retval.target.name = target;
\r
214 retval.target.type = 'frame';
\r
215 retval.target.name = target;
\r
220 var advAttr = function( inputName, attrName )
\r
222 var value = element.getAttribute( attrName );
\r
223 if ( value !== null )
\r
224 retval.adv[ inputName ] = value || '';
\r
226 advAttr( 'advId', 'id' );
\r
227 advAttr( 'advLangDir', 'dir' );
\r
228 advAttr( 'advAccessKey', 'accessKey' );
\r
230 retval.adv.advName =
\r
231 element.data( 'cke-saved-name' )
\r
232 || element.getAttribute( 'name' )
\r
234 advAttr( 'advLangCode', 'lang' );
\r
235 advAttr( 'advTabIndex', 'tabindex' );
\r
236 advAttr( 'advTitle', 'title' );
\r
237 advAttr( 'advContentType', 'type' );
\r
238 CKEDITOR.plugins.link.synAnchorSelector ?
\r
239 retval.adv.advCSSClasses = getLinkClass( element )
\r
240 : advAttr( 'advCSSClasses', 'class' );
\r
241 advAttr( 'advCharset', 'charset' );
\r
242 advAttr( 'advStyles', 'style' );
\r
243 advAttr( 'advRel', 'rel' );
\r
246 // Find out whether we have any anchors in the editor.
\r
247 var anchors = retval.anchors = [],
\r
250 // For some browsers we set contenteditable="false" on anchors, making document.anchors not to include them, so we must traverse the links manually (#7893).
\r
251 if ( CKEDITOR.plugins.link.emptyAnchorFix )
\r
253 var links = editor.document.getElementsByTag( 'a' );
\r
254 for ( i = 0, count = links.count(); i < count; i++ )
\r
256 item = links.getItem( i );
\r
257 if ( item.data( 'cke-saved-name' ) || item.hasAttribute( 'name' ) )
\r
258 anchors.push( { name : item.data( 'cke-saved-name' ) || item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) } );
\r
263 var anchorList = new CKEDITOR.dom.nodeList( editor.document.$.anchors );
\r
264 for ( i = 0, count = anchorList.count(); i < count; i++ )
\r
266 item = anchorList.getItem( i );
\r
267 anchors[ i ] = { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) };
\r
271 if ( CKEDITOR.plugins.link.fakeAnchor )
\r
273 var imgs = editor.document.getElementsByTag( 'img' );
\r
274 for ( i = 0, count = imgs.count(); i < count; i++ )
\r
276 if ( ( item = CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, imgs.getItem( i ) ) ) )
\r
277 anchors.push( { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) } );
\r
281 // Record down the selected element in the dialog.
\r
282 this._.selectedElement = element;
\r
286 var setupParams = function( page, data )
\r
289 this.setValue( data[page][this.id] || '' );
\r
292 var setupPopupParams = function( data )
\r
294 return setupParams.call( this, 'target', data );
\r
297 var setupAdvParams = function( data )
\r
299 return setupParams.call( this, 'adv', data );
\r
302 var commitParams = function( page, data )
\r
307 data[page][this.id] = this.getValue() || '';
\r
310 var commitPopupParams = function( data )
\r
312 return commitParams.call( this, 'target', data );
\r
315 var commitAdvParams = function( data )
\r
317 return commitParams.call( this, 'adv', data );
\r
320 function unescapeSingleQuote( str )
\r
322 return str.replace( /\\'/g, '\'' );
\r
325 function escapeSingleQuote( str )
\r
327 return str.replace( /'/g, '\\$&' );
\r
330 var emailProtection = editor.config.emailProtection || '';
\r
332 // Compile the protection function pattern.
\r
333 if ( emailProtection && emailProtection != 'encode' )
\r
335 var compiledProtectionFunction = {};
\r
337 emailProtection.replace( /^([^(]+)\(([^)]+)\)$/, function( match, funcName, params )
\r
339 compiledProtectionFunction.name = funcName;
\r
340 compiledProtectionFunction.params = [];
\r
341 params.replace( /[^,\s]+/g, function( param )
\r
343 compiledProtectionFunction.params.push( param );
\r
348 function protectEmailLinkAsFunction( email )
\r
351 name = compiledProtectionFunction.name,
\r
352 params = compiledProtectionFunction.params,
\r
356 retval = [ name, '(' ];
\r
357 for ( var i = 0; i < params.length; i++ )
\r
359 paramName = params[ i ].toLowerCase();
\r
360 paramValue = email[ paramName ];
\r
362 i > 0 && retval.push( ',' );
\r
365 escapeSingleQuote( encodeURIComponent( email[ paramName ] ) )
\r
369 retval.push( ')' );
\r
370 return retval.join( '' );
\r
373 function protectEmailAddressAsEncodedString( address )
\r
376 length = address.length,
\r
378 for ( var i = 0; i < length; i++ )
\r
380 charCode = address.charCodeAt( i );
\r
381 encodedChars.push( charCode );
\r
383 return 'String.fromCharCode(' + encodedChars.join( ',' ) + ')';
\r
386 function getLinkClass( ele )
\r
388 var className = ele.getAttribute( 'class' );
\r
389 return className ? className.replace( /\s*(?:cke_anchor_empty|cke_anchor)(?:\s*$)?/g, '' ) : '';
\r
392 var commonLang = editor.lang.common,
\r
393 linkLang = editor.lang.link;
\r
396 title : linkLang.title,
\r
402 label : linkLang.info,
\r
403 title : linkLang.info,
\r
409 label : linkLang.type,
\r
413 [ linkLang.toUrl, 'url' ],
\r
414 [ linkLang.toAnchor, 'anchor' ],
\r
415 [ linkLang.toEmail, 'email' ]
\r
417 onChange : linkTypeChanged,
\r
418 setup : function( data )
\r
421 this.setValue( data.type );
\r
423 commit : function( data )
\r
425 data.type = this.getValue();
\r
435 widths : [ '25%', '75%' ],
\r
441 label : commonLang.protocol,
\r
442 'default' : 'http://',
\r
445 // Force 'ltr' for protocol names in BIDI. (#5433)
\r
446 [ 'http://\u200E', 'http://' ],
\r
447 [ 'https://\u200E', 'https://' ],
\r
448 [ 'ftp://\u200E', 'ftp://' ],
\r
449 [ 'news://\u200E', 'news://' ],
\r
450 [ linkLang.other , '' ]
\r
452 setup : function( data )
\r
455 this.setValue( data.url.protocol || '' );
\r
457 commit : function( data )
\r
462 data.url.protocol = this.getValue();
\r
468 label : commonLang.url,
\r
470 onLoad : function ()
\r
472 this.allowOnChange = true;
\r
474 onKeyUp : function()
\r
476 this.allowOnChange = false;
\r
477 var protocolCmb = this.getDialog().getContentElement( 'info', 'protocol' ),
\r
478 url = this.getValue(),
\r
479 urlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/i,
\r
480 urlOnChangeTestOther = /^((javascript:)|[#\/\.\?])/i;
\r
482 var protocol = urlOnChangeProtocol.exec( url );
\r
485 this.setValue( url.substr( protocol[ 0 ].length ) );
\r
486 protocolCmb.setValue( protocol[ 0 ].toLowerCase() );
\r
488 else if ( urlOnChangeTestOther.test( url ) )
\r
489 protocolCmb.setValue( '' );
\r
491 this.allowOnChange = true;
\r
493 onChange : function()
\r
495 if ( this.allowOnChange ) // Dont't call on dialog load.
\r
498 validate : function()
\r
500 var dialog = this.getDialog();
\r
502 if ( dialog.getContentElement( 'info', 'linkType' ) &&
\r
503 dialog.getValueOf( 'info', 'linkType' ) != 'url' )
\r
506 if ( (/javascript\:/).test( this.getValue() ) ) {
\r
507 alert( commonLang.invalidValue );
\r
511 if ( this.getDialog().fakeObj ) // Edit Anchor.
\r
514 var func = CKEDITOR.dialog.validate.notEmpty( linkLang.noUrl );
\r
515 return func.apply( this );
\r
517 setup : function( data )
\r
519 this.allowOnChange = false;
\r
521 this.setValue( data.url.url );
\r
522 this.allowOnChange = true;
\r
525 commit : function( data )
\r
527 // IE will not trigger the onChange event if the mouse has been used
\r
528 // to carry all the operations #4724
\r
534 data.url.url = this.getValue();
\r
535 this.allowOnChange = false;
\r
539 setup : function( data )
\r
541 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
542 this.getElement().show();
\r
549 filebrowser : 'info:url',
\r
550 label : commonLang.browseServer
\r
556 id : 'anchorOptions',
\r
564 id : 'selectAnchorText',
\r
565 label : linkLang.selectAnchor,
\r
566 setup : function( data )
\r
568 if ( data.anchors.length > 0 )
\r
569 this.getElement().show();
\r
571 this.getElement().hide();
\r
577 id : 'selectAnchor',
\r
584 label : linkLang.anchorName,
\r
585 style : 'width: 100%;',
\r
590 setup : function( data )
\r
594 for ( var i = 0 ; i < data.anchors.length ; i++ )
\r
596 if ( data.anchors[i].name )
\r
597 this.add( data.anchors[i].name );
\r
601 this.setValue( data.anchor.name );
\r
603 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
604 if ( linkType && linkType.getValue() == 'email' )
\r
607 commit : function( data )
\r
609 if ( !data.anchor )
\r
612 data.anchor.name = this.getValue();
\r
619 label : linkLang.anchorId,
\r
620 style : 'width: 100%;',
\r
625 setup : function( data )
\r
629 for ( var i = 0 ; i < data.anchors.length ; i++ )
\r
631 if ( data.anchors[i].id )
\r
632 this.add( data.anchors[i].id );
\r
636 this.setValue( data.anchor.id );
\r
638 commit : function( data )
\r
640 if ( !data.anchor )
\r
643 data.anchor.id = this.getValue();
\r
647 setup : function( data )
\r
649 if ( data.anchors.length > 0 )
\r
650 this.getElement().show();
\r
652 this.getElement().hide();
\r
660 style : 'text-align: center;',
\r
661 html : '<div role="note" tabIndex="-1">' + CKEDITOR.tools.htmlEncode( linkLang.noAnchors ) + '</div>',
\r
662 // Focus the first element defined in above html.
\r
664 setup : function( data )
\r
666 if ( data.anchors.length < 1 )
\r
667 this.getElement().show();
\r
669 this.getElement().hide();
\r
673 setup : function( data )
\r
675 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
676 this.getElement().hide();
\r
681 id : 'emailOptions',
\r
687 id : 'emailAddress',
\r
688 label : linkLang.emailAddress,
\r
690 validate : function()
\r
692 var dialog = this.getDialog();
\r
694 if ( !dialog.getContentElement( 'info', 'linkType' ) ||
\r
695 dialog.getValueOf( 'info', 'linkType' ) != 'email' )
\r
698 var func = CKEDITOR.dialog.validate.notEmpty( linkLang.noEmail );
\r
699 return func.apply( this );
\r
701 setup : function( data )
\r
704 this.setValue( data.email.address );
\r
706 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
707 if ( linkType && linkType.getValue() == 'email' )
\r
710 commit : function( data )
\r
715 data.email.address = this.getValue();
\r
720 id : 'emailSubject',
\r
721 label : linkLang.emailSubject,
\r
722 setup : function( data )
\r
725 this.setValue( data.email.subject );
\r
727 commit : function( data )
\r
732 data.email.subject = this.getValue();
\r
738 label : linkLang.emailBody,
\r
741 setup : function( data )
\r
744 this.setValue( data.email.body );
\r
746 commit : function( data )
\r
751 data.email.body = this.getValue();
\r
755 setup : function( data )
\r
757 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
758 this.getElement().hide();
\r
765 label : linkLang.target,
\r
766 title : linkLang.target,
\r
771 widths : [ '50%', '50%' ],
\r
776 id : 'linkTargetType',
\r
777 label : commonLang.target,
\r
778 'default' : 'notSet',
\r
779 style : 'width : 100%;',
\r
782 [ commonLang.notSet, 'notSet' ],
\r
783 [ linkLang.targetFrame, 'frame' ],
\r
784 [ linkLang.targetPopup, 'popup' ],
\r
785 [ commonLang.targetNew, '_blank' ],
\r
786 [ commonLang.targetTop, '_top' ],
\r
787 [ commonLang.targetSelf, '_self' ],
\r
788 [ commonLang.targetParent, '_parent' ]
\r
790 onChange : targetChanged,
\r
791 setup : function( data )
\r
794 this.setValue( data.target.type || 'notSet' );
\r
795 targetChanged.call( this );
\r
797 commit : function( data )
\r
799 if ( !data.target )
\r
802 data.target.type = this.getValue();
\r
807 id : 'linkTargetName',
\r
808 label : linkLang.targetFrameName,
\r
810 setup : function( data )
\r
813 this.setValue( data.target.name );
\r
815 commit : function( data )
\r
817 if ( !data.target )
\r
820 data.target.name = this.getValue().replace(/\W/gi, '');
\r
830 id : 'popupFeatures',
\r
835 label : linkLang.popupFeatures,
\r
845 label : linkLang.popupResizable,
\r
846 setup : setupPopupParams,
\r
847 commit : commitPopupParams
\r
852 label : linkLang.popupStatusBar,
\r
853 setup : setupPopupParams,
\r
854 commit : commitPopupParams
\r
866 label : linkLang.popupLocationBar,
\r
867 setup : setupPopupParams,
\r
868 commit : commitPopupParams
\r
874 label : linkLang.popupToolbar,
\r
875 setup : setupPopupParams,
\r
876 commit : commitPopupParams
\r
888 label : linkLang.popupMenuBar,
\r
889 setup : setupPopupParams,
\r
890 commit : commitPopupParams
\r
896 label : linkLang.popupFullScreen,
\r
897 setup : setupPopupParams,
\r
898 commit : commitPopupParams
\r
910 label : linkLang.popupScrollBars,
\r
911 setup : setupPopupParams,
\r
912 commit : commitPopupParams
\r
918 label : linkLang.popupDependent,
\r
919 setup : setupPopupParams,
\r
920 commit : commitPopupParams
\r
931 widths : [ '50%', '50%' ],
\r
932 labelLayout : 'horizontal',
\r
933 label : commonLang.width,
\r
935 setup : setupPopupParams,
\r
936 commit : commitPopupParams
\r
941 labelLayout : 'horizontal',
\r
942 widths : [ '50%', '50%' ],
\r
943 label : linkLang.popupLeft,
\r
945 setup : setupPopupParams,
\r
946 commit : commitPopupParams
\r
957 labelLayout : 'horizontal',
\r
958 widths : [ '50%', '50%' ],
\r
959 label : commonLang.height,
\r
961 setup : setupPopupParams,
\r
962 commit : commitPopupParams
\r
967 labelLayout : 'horizontal',
\r
968 label : linkLang.popupTop,
\r
969 widths : [ '50%', '50%' ],
\r
971 setup : setupPopupParams,
\r
972 commit : commitPopupParams
\r
985 label : linkLang.upload,
\r
986 title : linkLang.upload,
\r
988 filebrowser : 'uploadButton',
\r
994 label : commonLang.upload,
\r
995 style: 'height:40px',
\r
999 type : 'fileButton',
\r
1000 id : 'uploadButton',
\r
1001 label : commonLang.uploadSubmit,
\r
1002 filebrowser : 'info:url',
\r
1003 'for' : [ 'upload', 'upload' ]
\r
1009 label : linkLang.advanced,
\r
1010 title : linkLang.advanced,
\r
1020 widths : [ '45%', '35%', '20%' ],
\r
1026 label : linkLang.id,
\r
1027 setup : setupAdvParams,
\r
1028 commit : commitAdvParams
\r
1032 id : 'advLangDir',
\r
1033 label : linkLang.langDir,
\r
1035 style : 'width:110px',
\r
1038 [ commonLang.notSet, '' ],
\r
1039 [ linkLang.langDirLTR, 'ltr' ],
\r
1040 [ linkLang.langDirRTL, 'rtl' ]
\r
1042 setup : setupAdvParams,
\r
1043 commit : commitAdvParams
\r
1047 id : 'advAccessKey',
\r
1049 label : linkLang.acccessKey,
\r
1051 setup : setupAdvParams,
\r
1052 commit : commitAdvParams
\r
1059 widths : [ '45%', '35%', '20%' ],
\r
1064 label : linkLang.name,
\r
1066 setup : setupAdvParams,
\r
1067 commit : commitAdvParams
\r
1072 label : linkLang.langCode,
\r
1073 id : 'advLangCode',
\r
1076 setup : setupAdvParams,
\r
1077 commit : commitAdvParams
\r
1082 label : linkLang.tabIndex,
\r
1083 id : 'advTabIndex',
\r
1086 setup : setupAdvParams,
\r
1087 commit : commitAdvParams
\r
1101 widths : [ '45%', '55%' ],
\r
1106 label : linkLang.advisoryTitle,
\r
1109 setup : setupAdvParams,
\r
1110 commit : commitAdvParams
\r
1115 label : linkLang.advisoryContentType,
\r
1117 id : 'advContentType',
\r
1118 setup : setupAdvParams,
\r
1119 commit : commitAdvParams
\r
1126 widths : [ '45%', '55%' ],
\r
1131 label : linkLang.cssClasses,
\r
1133 id : 'advCSSClasses',
\r
1134 setup : setupAdvParams,
\r
1135 commit : commitAdvParams
\r
1140 label : linkLang.charset,
\r
1142 id : 'advCharset',
\r
1143 setup : setupAdvParams,
\r
1144 commit : commitAdvParams
\r
1151 widths : [ '45%', '55%' ],
\r
1156 label : linkLang.rel,
\r
1159 setup : setupAdvParams,
\r
1160 commit : commitAdvParams
\r
1164 label : linkLang.styles,
\r
1167 validate : CKEDITOR.dialog.validate.inlineStyle( editor.lang.common.invalidInlineStyle ),
\r
1168 setup : setupAdvParams,
\r
1169 commit : commitAdvParams
\r
1178 onShow : function()
\r
1180 var editor = this.getParentEditor(),
\r
1181 selection = editor.getSelection(),
\r
1184 // Fill in all the relevant fields if there's already one link selected.
\r
1185 if ( ( element = plugin.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) )
\r
1186 selection.selectElement( element );
\r
1190 this.setupContent( parseLink.apply( this, [ editor, element ] ) );
\r
1194 var attributes = {},
\r
1195 removeAttributes = [],
\r
1198 editor = this.getParentEditor();
\r
1200 this.commitContent( data );
\r
1202 // Compose the URL.
\r
1203 switch ( data.type || 'url' )
\r
1206 var protocol = ( data.url && data.url.protocol != undefined ) ? data.url.protocol : 'http://',
\r
1207 url = ( data.url && CKEDITOR.tools.trim( data.url.url ) ) || '';
\r
1208 attributes[ 'data-cke-saved-href' ] = ( url.indexOf( '/' ) === 0 ) ? url : protocol + url;
\r
1211 var name = ( data.anchor && data.anchor.name ),
\r
1212 id = ( data.anchor && data.anchor.id );
\r
1213 attributes[ 'data-cke-saved-href' ] = '#' + ( name || id || '' );
\r
1218 email = data.email,
\r
1219 address = email.address;
\r
1221 switch( emailProtection )
\r
1226 var subject = encodeURIComponent( email.subject || '' ),
\r
1227 body = encodeURIComponent( email.body || '' );
\r
1229 // Build the e-mail parameters first.
\r
1231 subject && argList.push( 'subject=' + subject );
\r
1232 body && argList.push( 'body=' + body );
\r
1233 argList = argList.length ? '?' + argList.join( '&' ) : '';
\r
1235 if ( emailProtection == 'encode' )
\r
1237 linkHref = [ 'javascript:void(location.href=\'mailto:\'+',
\r
1238 protectEmailAddressAsEncodedString( address ) ];
\r
1239 // parameters are optional.
\r
1240 argList && linkHref.push( '+\'', escapeSingleQuote( argList ), '\'' );
\r
1242 linkHref.push( ')' );
\r
1245 linkHref = [ 'mailto:', address, argList ];
\r
1251 // Separating name and domain.
\r
1252 var nameAndDomain = address.split( '@', 2 );
\r
1253 email.name = nameAndDomain[ 0 ];
\r
1254 email.domain = nameAndDomain[ 1 ];
\r
1256 linkHref = [ 'javascript:', protectEmailLinkAsFunction( email ) ];
\r
1260 attributes[ 'data-cke-saved-href' ] = linkHref.join( '' );
\r
1264 // Popups and target.
\r
1265 if ( data.target )
\r
1267 if ( data.target.type == 'popup' )
\r
1269 var onclickList = [ 'window.open(this.href, \'',
\r
1270 data.target.name || '', '\', \'' ];
\r
1271 var featureList = [ 'resizable', 'status', 'location', 'toolbar', 'menubar', 'fullscreen',
\r
1272 'scrollbars', 'dependent' ];
\r
1273 var featureLength = featureList.length;
\r
1274 var addFeature = function( featureName )
\r
1276 if ( data.target[ featureName ] )
\r
1277 featureList.push( featureName + '=' + data.target[ featureName ] );
\r
1280 for ( var i = 0 ; i < featureLength ; i++ )
\r
1281 featureList[i] = featureList[i] + ( data.target[ featureList[i] ] ? '=yes' : '=no' ) ;
\r
1282 addFeature( 'width' );
\r
1283 addFeature( 'left' );
\r
1284 addFeature( 'height' );
\r
1285 addFeature( 'top' );
\r
1287 onclickList.push( featureList.join( ',' ), '\'); return false;' );
\r
1288 attributes[ 'data-cke-pa-onclick' ] = onclickList.join( '' );
\r
1290 // Add the "target" attribute. (#5074)
\r
1291 removeAttributes.push( 'target' );
\r
1295 if ( data.target.type != 'notSet' && data.target.name )
\r
1296 attributes.target = data.target.name;
\r
1298 removeAttributes.push( 'target' );
\r
1300 removeAttributes.push( 'data-cke-pa-onclick', 'onclick' );
\r
1304 // Advanced attributes.
\r
1307 var advAttr = function( inputName, attrName )
\r
1309 var value = data.adv[ inputName ];
\r
1311 attributes[attrName] = value;
\r
1313 removeAttributes.push( attrName );
\r
1316 advAttr( 'advId', 'id' );
\r
1317 advAttr( 'advLangDir', 'dir' );
\r
1318 advAttr( 'advAccessKey', 'accessKey' );
\r
1320 if ( data.adv[ 'advName' ] )
\r
1321 attributes[ 'name' ] = attributes[ 'data-cke-saved-name' ] = data.adv[ 'advName' ];
\r
1323 removeAttributes = removeAttributes.concat( [ 'data-cke-saved-name', 'name' ] );
\r
1325 advAttr( 'advLangCode', 'lang' );
\r
1326 advAttr( 'advTabIndex', 'tabindex' );
\r
1327 advAttr( 'advTitle', 'title' );
\r
1328 advAttr( 'advContentType', 'type' );
\r
1329 advAttr( 'advCSSClasses', 'class' );
\r
1330 advAttr( 'advCharset', 'charset' );
\r
1331 advAttr( 'advStyles', 'style' );
\r
1332 advAttr( 'advRel', 'rel' );
\r
1336 var selection = editor.getSelection();
\r
1338 // Browser need the "href" fro copy/paste link to work. (#6641)
\r
1339 attributes.href = attributes[ 'data-cke-saved-href' ];
\r
1341 if ( !this._.selectedElement )
\r
1343 // Create element if current selection is collapsed.
\r
1344 var ranges = selection.getRanges( true );
\r
1345 if ( ranges.length == 1 && ranges[0].collapsed )
\r
1347 // Short mailto link text view (#5736).
\r
1348 var text = new CKEDITOR.dom.text( data.type == 'email' ?
\r
1349 data.email.address : attributes[ 'data-cke-saved-href' ], editor.document );
\r
1350 ranges[0].insertNode( text );
\r
1351 ranges[0].selectNodeContents( text );
\r
1352 selection.selectRanges( ranges );
\r
1356 var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
\r
1357 style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why.
\r
1358 style.apply( editor.document );
\r
1362 // We're only editing an existing link, so just overwrite the attributes.
\r
1363 var element = this._.selectedElement,
\r
1364 href = element.data( 'cke-saved-href' ),
\r
1365 textView = element.getHtml();
\r
1367 element.setAttributes( attributes );
\r
1368 element.removeAttributes( removeAttributes );
\r
1370 if ( data.adv && data.adv.advName && CKEDITOR.plugins.link.synAnchorSelector )
\r
1371 element.addClass( element.getChildCount() ? 'cke_anchor' : 'cke_anchor_empty' );
\r
1373 // Update text view when user changes protocol (#4612).
\r
1374 if ( href == textView || data.type == 'email' && textView.indexOf( '@' ) != -1 )
\r
1376 // Short mailto link text view (#5736).
\r
1377 element.setHtml( data.type == 'email' ?
\r
1378 data.email.address : attributes[ 'data-cke-saved-href' ] );
\r
1381 selection.selectElement( element );
\r
1382 delete this._.selectedElement;
\r
1385 onLoad : function()
\r
1387 if ( !editor.config.linkShowAdvancedTab )
\r
1388 this.hidePage( 'advanced' ); //Hide Advanded tab.
\r
1390 if ( !editor.config.linkShowTargetTab )
\r
1391 this.hidePage( 'target' ); //Hide Target tab.
\r
1394 // Inital focus on 'url' field if link is of type URL.
\r
1395 onFocus : function()
\r
1397 var linkType = this.getContentElement( 'info', 'linkType' ),
\r
1399 if ( linkType && linkType.getValue() == 'url' )
\r
1401 urlField = this.getContentElement( 'info', 'url' );
\r
1402 urlField.select();
\r
1409 * The e-mail address anti-spam protection option. The protection will be
\r
1410 * applied when creating or modifying e-mail links through the editor interface.<br>
\r
1411 * Two methods of protection can be choosed:
\r
1412 * <ol> <li>The e-mail parts (name, domain and any other query string) are
\r
1413 * assembled into a function call pattern. Such function must be
\r
1414 * provided by the developer in the pages that will use the contents.
\r
1415 * <li>Only the e-mail address is obfuscated into a special string that
\r
1416 * has no meaning for humans or spam bots, but which is properly
\r
1417 * rendered and accepted by the browser.</li></ol>
\r
1418 * Both approaches require JavaScript to be enabled.
\r
1419 * @name CKEDITOR.config.emailProtection
\r
1422 * @default '' (empty string = disabled)
\r
1424 * // href="mailto:tester@ckeditor.com?subject=subject&body=body"
\r
1425 * config.emailProtection = '';
\r
1427 * // 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
1428 * config.emailProtection = 'encode';
\r
1430 * // href="javascript:mt('tester','ckeditor.com','subject','body')"
\r
1431 * config.emailProtection = 'mt(NAME,DOMAIN,SUBJECT,BODY)';
\r