2 Copyright (c) 2003-2010, 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
80 // Loads the parameters in a selected link to the link dialog fields.
\r
81 var javascriptProtocolRegex = /^javascript:/,
\r
82 emailRegex = /^mailto:([^?]+)(?:\?(.+))?$/,
\r
83 emailSubjectRegex = /subject=([^;?:@&=$,\/]*)/,
\r
84 emailBodyRegex = /body=([^;?:@&=$,\/]*)/,
\r
85 anchorRegex = /^#(.*)$/,
\r
86 urlRegex = /^((?:http|https|ftp|news):\/\/)?(.*)$/,
\r
87 selectableTargets = /^(_(?:self|top|parent|blank))$/,
\r
88 encodedEmailLinkRegex = /^javascript:void\(location\.href='mailto:'\+String\.fromCharCode\(([^)]+)\)(?:\+'(.*)')?\)$/,
\r
89 functionCallProtectedEmailLinkRegex = /^javascript:([^(]+)\(([^)]+)\)$/;
\r
92 /\s*window.open\(\s*this\.href\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*/;
\r
93 var popupFeaturesRegex = /(?:^|,)([^=]+)=(\d+|yes|no)/gi;
\r
95 var parseLink = function( editor, element )
\r
97 var href = ( element && ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) ) || '',
\r
104 if ( ( javascriptMatch = href.match( javascriptProtocolRegex ) ) )
\r
106 if ( emailProtection == 'encode' )
\r
108 href = href.replace( encodedEmailLinkRegex,
\r
109 function ( match, protectedAddress, rest )
\r
112 String.fromCharCode.apply( String, protectedAddress.split( ',' ) ) +
\r
113 ( rest && unescapeSingleQuote( rest ) );
\r
116 // Protected email link as function call.
\r
117 else if ( emailProtection )
\r
119 href.replace( functionCallProtectedEmailLinkRegex, function( match, funcName, funcArgs )
\r
121 if ( funcName == compiledProtectionFunction.name )
\r
123 retval.type = 'email';
\r
124 var email = retval.email = {};
\r
126 var paramRegex = /[^,\s]+/g,
\r
127 paramQuoteRegex = /(^')|('$)/g,
\r
128 paramsMatch = funcArgs.match( paramRegex ),
\r
129 paramsMatchLength = paramsMatch.length,
\r
133 for ( var i = 0; i < paramsMatchLength; i++ )
\r
135 paramVal = decodeURIComponent( unescapeSingleQuote( paramsMatch[ i ].replace( paramQuoteRegex, '' ) ) );
\r
136 paramName = compiledProtectionFunction.params[ i ].toLowerCase();
\r
137 email[ paramName ] = paramVal;
\r
139 email.address = [ email.name, email.domain ].join( '@' );
\r
145 if ( !retval.type )
\r
147 if ( ( anchorMatch = href.match( anchorRegex ) ) )
\r
149 retval.type = 'anchor';
\r
150 retval.anchor = {};
\r
151 retval.anchor.name = retval.anchor.id = anchorMatch[1];
\r
153 // Protected email link as encoded string.
\r
154 else if ( ( emailMatch = href.match( emailRegex ) ) )
\r
156 var subjectMatch = href.match( emailSubjectRegex ),
\r
157 bodyMatch = href.match( emailBodyRegex );
\r
159 retval.type = 'email';
\r
160 var email = ( retval.email = {} );
\r
161 email.address = emailMatch[ 1 ];
\r
162 subjectMatch && ( email.subject = decodeURIComponent( subjectMatch[ 1 ] ) );
\r
163 bodyMatch && ( email.body = decodeURIComponent( bodyMatch[ 1 ] ) );
\r
165 // urlRegex matches empty strings, so need to check for href as well.
\r
166 else if ( href && ( urlMatch = href.match( urlRegex ) ) )
\r
168 retval.type = 'url';
\r
170 retval.url.protocol = urlMatch[1];
\r
171 retval.url.url = urlMatch[2];
\r
174 retval.type = 'url';
\r
177 // Load target and popup settings.
\r
180 var target = element.getAttribute( 'target' );
\r
181 retval.target = {};
\r
184 // IE BUG: target attribute is an empty string instead of null in IE if it's not set.
\r
187 var onclick = element.getAttribute( '_cke_pa_onclick' ) || element.getAttribute( 'onclick' ),
\r
188 onclickMatch = onclick && onclick.match( popupRegex );
\r
189 if ( onclickMatch )
\r
191 retval.target.type = 'popup';
\r
192 retval.target.name = onclickMatch[1];
\r
195 while ( ( featureMatch = popupFeaturesRegex.exec( onclickMatch[2] ) ) )
\r
197 if ( featureMatch[2] == 'yes' || featureMatch[2] == '1' )
\r
198 retval.target[ featureMatch[1] ] = true;
\r
199 else if ( isFinite( featureMatch[2] ) )
\r
200 retval.target[ featureMatch[1] ] = featureMatch[2];
\r
206 var targetMatch = target.match( selectableTargets );
\r
208 retval.target.type = retval.target.name = target;
\r
211 retval.target.type = 'frame';
\r
212 retval.target.name = target;
\r
217 var advAttr = function( inputName, attrName )
\r
219 var value = element.getAttribute( attrName );
\r
220 if ( value !== null )
\r
221 retval.adv[ inputName ] = value || '';
\r
223 advAttr( 'advId', 'id' );
\r
224 advAttr( 'advLangDir', 'dir' );
\r
225 advAttr( 'advAccessKey', 'accessKey' );
\r
226 advAttr( 'advName', 'name' );
\r
227 advAttr( 'advLangCode', 'lang' );
\r
228 advAttr( 'advTabIndex', 'tabindex' );
\r
229 advAttr( 'advTitle', 'title' );
\r
230 advAttr( 'advContentType', 'type' );
\r
231 advAttr( 'advCSSClasses', 'class' );
\r
232 advAttr( 'advCharset', 'charset' );
\r
233 advAttr( 'advStyles', 'style' );
\r
236 // Find out whether we have any anchors in the editor.
\r
237 // Get all IMG elements in CK document.
\r
238 var elements = editor.document.getElementsByTag( 'img' ),
\r
239 realAnchors = new CKEDITOR.dom.nodeList( editor.document.$.anchors ),
\r
240 anchors = retval.anchors = [];
\r
242 for ( var i = 0; i < elements.count() ; i++ )
\r
244 var item = elements.getItem( i );
\r
245 if ( item.getAttribute( '_cke_realelement' ) && item.getAttribute( '_cke_real_element_type' ) == 'anchor' )
\r
246 anchors.push( editor.restoreRealElement( item ) );
\r
249 for ( i = 0 ; i < realAnchors.count() ; i++ )
\r
250 anchors.push( realAnchors.getItem( i ) );
\r
252 for ( i = 0 ; i < anchors.length ; i++ )
\r
254 item = anchors[ i ];
\r
255 anchors[ i ] = { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) };
\r
258 // Record down the selected element in the dialog.
\r
259 this._.selectedElement = element;
\r
264 var setupParams = function( page, data )
\r
267 this.setValue( data[page][this.id] || '' );
\r
270 var setupPopupParams = function( data )
\r
272 return setupParams.call( this, 'target', data );
\r
275 var setupAdvParams = function( data )
\r
277 return setupParams.call( this, 'adv', data );
\r
280 var commitParams = function( page, data )
\r
285 data[page][this.id] = this.getValue() || '';
\r
288 var commitPopupParams = function( data )
\r
290 return commitParams.call( this, 'target', data );
\r
293 var commitAdvParams = function( data )
\r
295 return commitParams.call( this, 'adv', data );
\r
298 function unescapeSingleQuote( str )
\r
300 return str.replace( /\\'/g, '\'' );
\r
303 function escapeSingleQuote( str )
\r
305 return str.replace( /'/g, '\\$&' );
\r
308 var emailProtection = editor.config.emailProtection || '';
\r
310 // Compile the protection function pattern.
\r
311 if ( emailProtection && emailProtection != 'encode' )
\r
313 var compiledProtectionFunction = {};
\r
315 emailProtection.replace( /^([^(]+)\(([^)]+)\)$/, function( match, funcName, params )
\r
317 compiledProtectionFunction.name = funcName;
\r
318 compiledProtectionFunction.params = [];
\r
319 params.replace( /[^,\s]+/g, function( param )
\r
321 compiledProtectionFunction.params.push( param );
\r
326 function protectEmailLinkAsFunction( email )
\r
329 name = compiledProtectionFunction.name,
\r
330 params = compiledProtectionFunction.params,
\r
334 retval = [ name, '(' ];
\r
335 for ( var i = 0; i < params.length; i++ )
\r
337 paramName = params[ i ].toLowerCase();
\r
338 paramValue = email[ paramName ];
\r
340 i > 0 && retval.push( ',' );
\r
343 escapeSingleQuote( encodeURIComponent( email[ paramName ] ) )
\r
347 retval.push( ')' );
\r
348 return retval.join( '' );
\r
351 function protectEmailAddressAsEncodedString( address )
\r
354 length = address.length,
\r
356 for ( var i = 0; i < length; i++ )
\r
358 charCode = address.charCodeAt( i );
\r
359 encodedChars.push( charCode );
\r
361 return 'String.fromCharCode(' + encodedChars.join( ',' ) + ')';
\r
364 var commonLang = editor.lang.common,
\r
365 linkLang = editor.lang.link;
\r
368 title : linkLang.title,
\r
374 label : linkLang.info,
\r
375 title : linkLang.info,
\r
381 label : linkLang.type,
\r
385 [ linkLang.toUrl, 'url' ],
\r
386 [ linkLang.toAnchor, 'anchor' ],
\r
387 [ linkLang.toEmail, 'email' ]
\r
389 onChange : linkTypeChanged,
\r
390 setup : function( data )
\r
393 this.setValue( data.type );
\r
395 commit : function( data )
\r
397 data.type = this.getValue();
\r
407 widths : [ '25%', '75%' ],
\r
413 label : commonLang.protocol,
\r
414 'default' : 'http://',
\r
417 // Force 'ltr' for protocol names in BIDI. (#5433)
\r
418 [ 'http://\u200E', 'http://' ],
\r
419 [ 'https://\u200E', 'https://' ],
\r
420 [ 'ftp://\u200E', 'ftp://' ],
\r
421 [ 'news://\u200E', 'news://' ],
\r
422 [ linkLang.other , '' ]
\r
424 setup : function( data )
\r
427 this.setValue( data.url.protocol || '' );
\r
429 commit : function( data )
\r
434 data.url.protocol = this.getValue();
\r
440 label : commonLang.url,
\r
442 onLoad : function ()
\r
444 this.allowOnChange = true;
\r
446 onKeyUp : function()
\r
448 this.allowOnChange = false;
\r
449 var protocolCmb = this.getDialog().getContentElement( 'info', 'protocol' ),
\r
450 url = this.getValue(),
\r
451 urlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/gi,
\r
452 urlOnChangeTestOther = /^((javascript:)|[#\/\.\?])/gi;
\r
454 var protocol = urlOnChangeProtocol.exec( url );
\r
457 this.setValue( url.substr( protocol[ 0 ].length ) );
\r
458 protocolCmb.setValue( protocol[ 0 ].toLowerCase() );
\r
460 else if ( urlOnChangeTestOther.test( url ) )
\r
461 protocolCmb.setValue( '' );
\r
463 this.allowOnChange = true;
\r
465 onChange : function()
\r
467 if ( this.allowOnChange ) // Dont't call on dialog load.
\r
470 validate : function()
\r
472 var dialog = this.getDialog();
\r
474 if ( dialog.getContentElement( 'info', 'linkType' ) &&
\r
475 dialog.getValueOf( 'info', 'linkType' ) != 'url' )
\r
478 if ( this.getDialog().fakeObj ) // Edit Anchor.
\r
481 var func = CKEDITOR.dialog.validate.notEmpty( linkLang.noUrl );
\r
482 return func.apply( this );
\r
484 setup : function( data )
\r
486 this.allowOnChange = false;
\r
488 this.setValue( data.url.url );
\r
489 this.allowOnChange = true;
\r
492 commit : function( data )
\r
494 // IE will not trigger the onChange event if the mouse has been used
\r
495 // to carry all the operations #4724
\r
501 data.url.url = this.getValue();
\r
502 this.allowOnChange = false;
\r
506 setup : function( data )
\r
508 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
509 this.getElement().show();
\r
516 filebrowser : 'info:url',
\r
517 label : commonLang.browseServer
\r
523 id : 'anchorOptions',
\r
531 id : 'selectAnchorText',
\r
532 label : linkLang.selectAnchor,
\r
533 setup : function( data )
\r
535 if ( data.anchors.length > 0 )
\r
536 this.getElement().show();
\r
538 this.getElement().hide();
\r
544 id : 'selectAnchor',
\r
551 label : linkLang.anchorName,
\r
552 style : 'width: 100%;',
\r
557 setup : function( data )
\r
561 for ( var i = 0 ; i < data.anchors.length ; i++ )
\r
563 if ( data.anchors[i].name )
\r
564 this.add( data.anchors[i].name );
\r
568 this.setValue( data.anchor.name );
\r
570 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
571 if ( linkType && linkType.getValue() == 'email' )
\r
574 commit : function( data )
\r
576 if ( !data.anchor )
\r
579 data.anchor.name = this.getValue();
\r
586 label : linkLang.anchorId,
\r
587 style : 'width: 100%;',
\r
592 setup : function( data )
\r
596 for ( var i = 0 ; i < data.anchors.length ; i++ )
\r
598 if ( data.anchors[i].id )
\r
599 this.add( data.anchors[i].id );
\r
603 this.setValue( data.anchor.id );
\r
605 commit : function( data )
\r
607 if ( !data.anchor )
\r
610 data.anchor.id = this.getValue();
\r
614 setup : function( data )
\r
616 if ( data.anchors.length > 0 )
\r
617 this.getElement().show();
\r
619 this.getElement().hide();
\r
627 style : 'text-align: center;',
\r
628 html : '<div role="label" tabIndex="-1">' + CKEDITOR.tools.htmlEncode( linkLang.noAnchors ) + '</div>',
\r
629 // Focus the first element defined in above html.
\r
631 setup : function( data )
\r
633 if ( data.anchors.length < 1 )
\r
634 this.getElement().show();
\r
636 this.getElement().hide();
\r
640 setup : function( data )
\r
642 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
643 this.getElement().hide();
\r
648 id : 'emailOptions',
\r
654 id : 'emailAddress',
\r
655 label : linkLang.emailAddress,
\r
657 validate : function()
\r
659 var dialog = this.getDialog();
\r
661 if ( !dialog.getContentElement( 'info', 'linkType' ) ||
\r
662 dialog.getValueOf( 'info', 'linkType' ) != 'email' )
\r
665 var func = CKEDITOR.dialog.validate.notEmpty( linkLang.noEmail );
\r
666 return func.apply( this );
\r
668 setup : function( data )
\r
671 this.setValue( data.email.address );
\r
673 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
674 if ( linkType && linkType.getValue() == 'email' )
\r
677 commit : function( data )
\r
682 data.email.address = this.getValue();
\r
687 id : 'emailSubject',
\r
688 label : linkLang.emailSubject,
\r
689 setup : function( data )
\r
692 this.setValue( data.email.subject );
\r
694 commit : function( data )
\r
699 data.email.subject = this.getValue();
\r
705 label : linkLang.emailBody,
\r
708 setup : function( data )
\r
711 this.setValue( data.email.body );
\r
713 commit : function( data )
\r
718 data.email.body = this.getValue();
\r
722 setup : function( data )
\r
724 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
725 this.getElement().hide();
\r
732 label : linkLang.target,
\r
733 title : linkLang.target,
\r
738 widths : [ '50%', '50%' ],
\r
743 id : 'linkTargetType',
\r
744 label : commonLang.target,
\r
745 'default' : 'notSet',
\r
746 style : 'width : 100%;',
\r
749 [ commonLang.notSet, 'notSet' ],
\r
750 [ linkLang.targetFrame, 'frame' ],
\r
751 [ linkLang.targetPopup, 'popup' ],
\r
752 [ commonLang.targetNew, '_blank' ],
\r
753 [ commonLang.targetTop, '_top' ],
\r
754 [ commonLang.targetSelf, '_self' ],
\r
755 [ commonLang.targetParent, '_parent' ]
\r
757 onChange : targetChanged,
\r
758 setup : function( data )
\r
761 this.setValue( data.target.type );
\r
762 targetChanged.call( this );
\r
764 commit : function( data )
\r
766 if ( !data.target )
\r
769 data.target.type = this.getValue();
\r
774 id : 'linkTargetName',
\r
775 label : linkLang.targetFrameName,
\r
777 setup : function( data )
\r
780 this.setValue( data.target.name );
\r
782 commit : function( data )
\r
784 if ( !data.target )
\r
787 data.target.name = this.getValue().replace(/\W/gi, '');
\r
797 id : 'popupFeatures',
\r
802 label : linkLang.popupFeatures,
\r
812 label : linkLang.popupResizable,
\r
813 setup : setupPopupParams,
\r
814 commit : commitPopupParams
\r
819 label : linkLang.popupStatusBar,
\r
820 setup : setupPopupParams,
\r
821 commit : commitPopupParams
\r
833 label : linkLang.popupLocationBar,
\r
834 setup : setupPopupParams,
\r
835 commit : commitPopupParams
\r
841 label : linkLang.popupToolbar,
\r
842 setup : setupPopupParams,
\r
843 commit : commitPopupParams
\r
855 label : linkLang.popupMenuBar,
\r
856 setup : setupPopupParams,
\r
857 commit : commitPopupParams
\r
863 label : linkLang.popupFullScreen,
\r
864 setup : setupPopupParams,
\r
865 commit : commitPopupParams
\r
877 label : linkLang.popupScrollBars,
\r
878 setup : setupPopupParams,
\r
879 commit : commitPopupParams
\r
885 label : linkLang.popupDependent,
\r
886 setup : setupPopupParams,
\r
887 commit : commitPopupParams
\r
898 widths : [ '30%', '70%' ],
\r
899 labelLayout : 'horizontal',
\r
900 label : linkLang.popupWidth,
\r
902 setup : setupPopupParams,
\r
903 commit : commitPopupParams
\r
908 labelLayout : 'horizontal',
\r
909 widths : [ '55%', '45%' ],
\r
910 label : linkLang.popupLeft,
\r
912 setup : setupPopupParams,
\r
913 commit : commitPopupParams
\r
924 labelLayout : 'horizontal',
\r
925 widths : [ '30%', '70%' ],
\r
926 label : linkLang.popupHeight,
\r
928 setup : setupPopupParams,
\r
929 commit : commitPopupParams
\r
934 labelLayout : 'horizontal',
\r
935 label : linkLang.popupTop,
\r
936 widths : [ '55%', '45%' ],
\r
938 setup : setupPopupParams,
\r
939 commit : commitPopupParams
\r
952 label : linkLang.upload,
\r
953 title : linkLang.upload,
\r
955 filebrowser : 'uploadButton',
\r
961 label : commonLang.upload,
\r
962 style: 'height:40px',
\r
966 type : 'fileButton',
\r
967 id : 'uploadButton',
\r
968 label : commonLang.uploadSubmit,
\r
969 filebrowser : 'info:url',
\r
970 'for' : [ 'upload', 'upload' ]
\r
976 label : linkLang.advanced,
\r
977 title : linkLang.advanced,
\r
987 widths : [ '45%', '35%', '20%' ],
\r
993 label : linkLang.id,
\r
994 setup : setupAdvParams,
\r
995 commit : commitAdvParams
\r
1000 label : linkLang.langDir,
\r
1002 style : 'width:110px',
\r
1005 [ commonLang.notSet, '' ],
\r
1006 [ linkLang.langDirLTR, 'ltr' ],
\r
1007 [ linkLang.langDirRTL, 'rtl' ]
\r
1009 setup : setupAdvParams,
\r
1010 commit : commitAdvParams
\r
1014 id : 'advAccessKey',
\r
1016 label : linkLang.acccessKey,
\r
1018 setup : setupAdvParams,
\r
1019 commit : commitAdvParams
\r
1026 widths : [ '45%', '35%', '20%' ],
\r
1031 label : linkLang.name,
\r
1033 setup : setupAdvParams,
\r
1034 commit : commitAdvParams
\r
1039 label : linkLang.langCode,
\r
1040 id : 'advLangCode',
\r
1043 setup : setupAdvParams,
\r
1044 commit : commitAdvParams
\r
1049 label : linkLang.tabIndex,
\r
1050 id : 'advTabIndex',
\r
1053 setup : setupAdvParams,
\r
1054 commit : commitAdvParams
\r
1068 widths : [ '45%', '55%' ],
\r
1073 label : linkLang.advisoryTitle,
\r
1076 setup : setupAdvParams,
\r
1077 commit : commitAdvParams
\r
1082 label : linkLang.advisoryContentType,
\r
1084 id : 'advContentType',
\r
1085 setup : setupAdvParams,
\r
1086 commit : commitAdvParams
\r
1093 widths : [ '45%', '55%' ],
\r
1098 label : linkLang.cssClasses,
\r
1100 id : 'advCSSClasses',
\r
1101 setup : setupAdvParams,
\r
1102 commit : commitAdvParams
\r
1107 label : linkLang.charset,
\r
1109 id : 'advCharset',
\r
1110 setup : setupAdvParams,
\r
1111 commit : commitAdvParams
\r
1122 label : linkLang.styles,
\r
1125 setup : setupAdvParams,
\r
1126 commit : commitAdvParams
\r
1136 onShow : function()
\r
1138 this.fakeObj = false;
\r
1140 var editor = this.getParentEditor(),
\r
1141 selection = editor.getSelection(),
\r
1144 // Fill in all the relevant fields if there's already one link selected.
\r
1145 if ( ( element = plugin.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) )
\r
1146 selection.selectElement( element );
\r
1147 else if ( ( element = selection.getSelectedElement() ) && element.is( 'img' )
\r
1148 && element.getAttribute( '_cke_real_element_type' )
\r
1149 && element.getAttribute( '_cke_real_element_type' ) == 'anchor' )
\r
1151 this.fakeObj = element;
\r
1152 element = editor.restoreRealElement( this.fakeObj );
\r
1153 selection.selectElement( this.fakeObj );
\r
1158 this.setupContent( parseLink.apply( this, [ editor, element ] ) );
\r
1162 var attributes = { href : 'javascript:void(0)/*' + CKEDITOR.tools.getNextNumber() + '*/' },
\r
1163 removeAttributes = [],
\r
1164 data = { href : attributes.href },
\r
1166 editor = this.getParentEditor();
\r
1168 this.commitContent( data );
\r
1170 // Compose the URL.
\r
1171 switch ( data.type || 'url' )
\r
1174 var protocol = ( data.url && data.url.protocol != undefined ) ? data.url.protocol : 'http://',
\r
1175 url = ( data.url && data.url.url ) || '';
\r
1176 attributes._cke_saved_href = ( url.indexOf( '/' ) === 0 ) ? url : protocol + url;
\r
1179 var name = ( data.anchor && data.anchor.name ),
\r
1180 id = ( data.anchor && data.anchor.id );
\r
1181 attributes._cke_saved_href = '#' + ( name || id || '' );
\r
1186 email = data.email,
\r
1187 address = email.address;
\r
1189 switch( emailProtection )
\r
1194 var subject = encodeURIComponent( email.subject || '' ),
\r
1195 body = encodeURIComponent( email.body || '' );
\r
1197 // Build the e-mail parameters first.
\r
1199 subject && argList.push( 'subject=' + subject );
\r
1200 body && argList.push( 'body=' + body );
\r
1201 argList = argList.length ? '?' + argList.join( '&' ) : '';
\r
1203 if ( emailProtection == 'encode' )
\r
1205 linkHref = [ 'javascript:void(location.href=\'mailto:\'+',
\r
1206 protectEmailAddressAsEncodedString( address ) ];
\r
1207 // parameters are optional.
\r
1208 argList && linkHref.push( '+\'', escapeSingleQuote( argList ), '\'' );
\r
1210 linkHref.push( ')' );
\r
1213 linkHref = [ 'mailto:', address, argList ];
\r
1219 // Separating name and domain.
\r
1220 var nameAndDomain = address.split( '@', 2 );
\r
1221 email.name = nameAndDomain[ 0 ];
\r
1222 email.domain = nameAndDomain[ 1 ];
\r
1224 linkHref = [ 'javascript:', protectEmailLinkAsFunction( email ) ];
\r
1228 attributes._cke_saved_href = linkHref.join( '' );
\r
1232 // Popups and target.
\r
1233 if ( data.target )
\r
1235 if ( data.target.type == 'popup' )
\r
1237 var onclickList = [ 'window.open(this.href, \'',
\r
1238 data.target.name || '', '\', \'' ];
\r
1239 var featureList = [ 'resizable', 'status', 'location', 'toolbar', 'menubar', 'fullscreen',
\r
1240 'scrollbars', 'dependent' ];
\r
1241 var featureLength = featureList.length;
\r
1242 var addFeature = function( featureName )
\r
1244 if ( data.target[ featureName ] )
\r
1245 featureList.push( featureName + '=' + data.target[ featureName ] );
\r
1248 for ( var i = 0 ; i < featureLength ; i++ )
\r
1249 featureList[i] = featureList[i] + ( data.target[ featureList[i] ] ? '=yes' : '=no' ) ;
\r
1250 addFeature( 'width' );
\r
1251 addFeature( 'left' );
\r
1252 addFeature( 'height' );
\r
1253 addFeature( 'top' );
\r
1255 onclickList.push( featureList.join( ',' ), '\'); return false;' );
\r
1256 attributes[ '_cke_pa_onclick' ] = onclickList.join( '' );
\r
1258 // Add the "target" attribute. (#5074)
\r
1259 removeAttributes.push( 'target' );
\r
1263 if ( data.target.type != 'notSet' && data.target.name )
\r
1264 attributes.target = data.target.name;
\r
1266 removeAttributes.push( 'target' );
\r
1268 removeAttributes.push( '_cke_pa_onclick', 'onclick' );
\r
1272 // Advanced attributes.
\r
1275 var advAttr = function( inputName, attrName )
\r
1277 var value = data.adv[ inputName ];
\r
1279 attributes[attrName] = value;
\r
1281 removeAttributes.push( attrName );
\r
1284 if ( this._.selectedElement )
\r
1285 advAttr( 'advId', 'id' );
\r
1286 advAttr( 'advLangDir', 'dir' );
\r
1287 advAttr( 'advAccessKey', 'accessKey' );
\r
1288 advAttr( 'advName', 'name' );
\r
1289 advAttr( 'advLangCode', 'lang' );
\r
1290 advAttr( 'advTabIndex', 'tabindex' );
\r
1291 advAttr( 'advTitle', 'title' );
\r
1292 advAttr( 'advContentType', 'type' );
\r
1293 advAttr( 'advCSSClasses', 'class' );
\r
1294 advAttr( 'advCharset', 'charset' );
\r
1295 advAttr( 'advStyles', 'style' );
\r
1298 if ( !this._.selectedElement )
\r
1300 // Create element if current selection is collapsed.
\r
1301 var selection = editor.getSelection(),
\r
1302 ranges = selection.getRanges( true );
\r
1303 if ( ranges.length == 1 && ranges[0].collapsed )
\r
1305 // Short mailto link text view (#5736).
\r
1306 var text = new CKEDITOR.dom.text( data.type == 'email' ?
\r
1307 data.email.address : attributes._cke_saved_href, editor.document );
\r
1308 ranges[0].insertNode( text );
\r
1309 ranges[0].selectNodeContents( text );
\r
1310 selection.selectRanges( ranges );
\r
1314 var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
\r
1315 style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why.
\r
1316 style.apply( editor.document );
\r
1318 // Id. Apply only to the first link.
\r
1319 if ( data.adv && data.adv.advId )
\r
1321 var links = this.getParentEditor().document.$.getElementsByTagName( 'a' );
\r
1322 for ( i = 0 ; i < links.length ; i++ )
\r
1324 if ( links[i].href == attributes.href )
\r
1326 links[i].id = data.adv.advId;
\r
1334 // We're only editing an existing link, so just overwrite the attributes.
\r
1335 var element = this._.selectedElement,
\r
1336 href = element.getAttribute( '_cke_saved_href' ),
\r
1337 textView = element.getHtml();
\r
1339 // IE BUG: Setting the name attribute to an existing link doesn't work.
\r
1340 // Must re-create the link from weired syntax to workaround.
\r
1341 if ( CKEDITOR.env.ie && attributes.name != element.getAttribute( 'name' ) )
\r
1343 var newElement = new CKEDITOR.dom.element( '<a name="' + CKEDITOR.tools.htmlEncode( attributes.name ) + '">',
\r
1344 editor.document );
\r
1346 selection = editor.getSelection();
\r
1348 element.moveChildren( newElement );
\r
1349 element.copyAttributes( newElement, { name : 1 } );
\r
1350 newElement.replace( element );
\r
1351 element = newElement;
\r
1353 selection.selectElement( element );
\r
1356 element.setAttributes( attributes );
\r
1357 element.removeAttributes( removeAttributes );
\r
1358 // Update text view when user changes protocol (#4612).
\r
1359 if ( href == textView || data.type == 'email' && textView.indexOf( '@' ) != -1 )
\r
1361 // Short mailto link text view (#5736).
\r
1362 element.setHtml( data.type == 'email' ?
\r
1363 data.email.address : attributes._cke_saved_href );
\r
1365 // Make the element display as an anchor if a name has been set.
\r
1366 if ( element.getAttribute( 'name' ) )
\r
1367 element.addClass( 'cke_anchor' );
\r
1369 element.removeClass( 'cke_anchor' );
\r
1371 if ( this.fakeObj )
\r
1372 editor.createFakeElement( element, 'cke_anchor', 'anchor' ).replace( this.fakeObj );
\r
1374 delete this._.selectedElement;
\r
1377 onLoad : function()
\r
1379 if ( !editor.config.linkShowAdvancedTab )
\r
1380 this.hidePage( 'advanced' ); //Hide Advanded tab.
\r
1382 if ( !editor.config.linkShowTargetTab )
\r
1383 this.hidePage( 'target' ); //Hide Target tab.
\r
1386 // Inital focus on 'url' field if link is of type URL.
\r
1387 onFocus : function()
\r
1389 var linkType = this.getContentElement( 'info', 'linkType' ),
\r
1391 if ( linkType && linkType.getValue() == 'url' )
\r
1393 urlField = this.getContentElement( 'info', 'url' );
\r
1394 urlField.select();
\r
1401 * The e-mail address anti-spam protection option. The protection will be
\r
1402 * applied when creating or modifying e-mail links through the editor interface.<br>
\r
1403 * Two methods of protection can be choosed:
\r
1404 * <ol> <li>The e-mail parts (name, domain and any other query string) are
\r
1405 * assembled into a function call pattern. Such function must be
\r
1406 * provided by the developer in the pages that will use the contents.
\r
1407 * <li>Only the e-mail address is obfuscated into a special string that
\r
1408 * has no meaning for humans or spam bots, but which is properly
\r
1409 * rendered and accepted by the browser.</li></ol>
\r
1410 * Both approaches require JavaScript to be enabled.
\r
1411 * @name CKEDITOR.config.emailProtection
\r
1414 * @default '' (empty string = disabled)
\r
1416 * // href="mailto:tester@ckeditor.com?subject=subject&body=body"
\r
1417 * config.emailProtection = '';
\r
1419 * // 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
1420 * config.emailProtection = 'encode';
\r
1422 * // href="javascript:mt('tester','ckeditor.com','subject','body')"
\r
1423 * config.emailProtection = 'mt(NAME,DOMAIN,SUBJECT,BODY)';
\r