2 Copyright (c) 2003-2011, 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 if ( featureMatch[2] == 'yes' || featureMatch[2] == '1' )
\r
200 retval.target[ featureMatch[1] ] = true;
\r
201 else if ( isFinite( featureMatch[2] ) )
\r
202 retval.target[ featureMatch[1] ] = featureMatch[2];
\r
208 var targetMatch = target.match( selectableTargets );
\r
210 retval.target.type = retval.target.name = target;
\r
213 retval.target.type = 'frame';
\r
214 retval.target.name = target;
\r
219 var advAttr = function( inputName, attrName )
\r
221 var value = element.getAttribute( attrName );
\r
222 if ( value !== null )
\r
223 retval.adv[ inputName ] = value || '';
\r
225 advAttr( 'advId', 'id' );
\r
226 advAttr( 'advLangDir', 'dir' );
\r
227 advAttr( 'advAccessKey', 'accessKey' );
\r
229 retval.adv.advName =
\r
230 element.data( 'cke-saved-name' )
\r
231 || element.getAttribute( 'name' )
\r
233 advAttr( 'advLangCode', 'lang' );
\r
234 advAttr( 'advTabIndex', 'tabindex' );
\r
235 advAttr( 'advTitle', 'title' );
\r
236 advAttr( 'advContentType', 'type' );
\r
237 advAttr( 'advCSSClasses', 'class' );
\r
238 advAttr( 'advCharset', 'charset' );
\r
239 advAttr( 'advStyles', 'style' );
\r
242 // Find out whether we have any anchors in the editor.
\r
243 // Get all IMG elements in CK document.
\r
244 var elements = editor.document.getElementsByTag( 'img' ),
\r
245 realAnchors = new CKEDITOR.dom.nodeList( editor.document.$.anchors ),
\r
246 anchors = retval.anchors = [];
\r
248 for ( var i = 0; i < elements.count() ; i++ )
\r
250 var item = elements.getItem( i );
\r
251 if ( item.data( 'cke-realelement' ) && item.data( 'cke-real-element-type' ) == 'anchor' )
\r
252 anchors.push( editor.restoreRealElement( item ) );
\r
255 for ( i = 0 ; i < realAnchors.count() ; i++ )
\r
256 anchors.push( realAnchors.getItem( i ) );
\r
258 for ( i = 0 ; i < anchors.length ; i++ )
\r
260 item = anchors[ i ];
\r
261 anchors[ i ] = { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) };
\r
264 // Record down the selected element in the dialog.
\r
265 this._.selectedElement = element;
\r
270 var setupParams = function( page, data )
\r
273 this.setValue( data[page][this.id] || '' );
\r
276 var setupPopupParams = function( data )
\r
278 return setupParams.call( this, 'target', data );
\r
281 var setupAdvParams = function( data )
\r
283 return setupParams.call( this, 'adv', data );
\r
286 var commitParams = function( page, data )
\r
291 data[page][this.id] = this.getValue() || '';
\r
294 var commitPopupParams = function( data )
\r
296 return commitParams.call( this, 'target', data );
\r
299 var commitAdvParams = function( data )
\r
301 return commitParams.call( this, 'adv', data );
\r
304 function unescapeSingleQuote( str )
\r
306 return str.replace( /\\'/g, '\'' );
\r
309 function escapeSingleQuote( str )
\r
311 return str.replace( /'/g, '\\$&' );
\r
314 var emailProtection = editor.config.emailProtection || '';
\r
316 // Compile the protection function pattern.
\r
317 if ( emailProtection && emailProtection != 'encode' )
\r
319 var compiledProtectionFunction = {};
\r
321 emailProtection.replace( /^([^(]+)\(([^)]+)\)$/, function( match, funcName, params )
\r
323 compiledProtectionFunction.name = funcName;
\r
324 compiledProtectionFunction.params = [];
\r
325 params.replace( /[^,\s]+/g, function( param )
\r
327 compiledProtectionFunction.params.push( param );
\r
332 function protectEmailLinkAsFunction( email )
\r
335 name = compiledProtectionFunction.name,
\r
336 params = compiledProtectionFunction.params,
\r
340 retval = [ name, '(' ];
\r
341 for ( var i = 0; i < params.length; i++ )
\r
343 paramName = params[ i ].toLowerCase();
\r
344 paramValue = email[ paramName ];
\r
346 i > 0 && retval.push( ',' );
\r
349 escapeSingleQuote( encodeURIComponent( email[ paramName ] ) )
\r
353 retval.push( ')' );
\r
354 return retval.join( '' );
\r
357 function protectEmailAddressAsEncodedString( address )
\r
360 length = address.length,
\r
362 for ( var i = 0; i < length; i++ )
\r
364 charCode = address.charCodeAt( i );
\r
365 encodedChars.push( charCode );
\r
367 return 'String.fromCharCode(' + encodedChars.join( ',' ) + ')';
\r
370 var commonLang = editor.lang.common,
\r
371 linkLang = editor.lang.link;
\r
374 title : linkLang.title,
\r
380 label : linkLang.info,
\r
381 title : linkLang.info,
\r
387 label : linkLang.type,
\r
391 [ linkLang.toUrl, 'url' ],
\r
392 [ linkLang.toAnchor, 'anchor' ],
\r
393 [ linkLang.toEmail, 'email' ]
\r
395 onChange : linkTypeChanged,
\r
396 setup : function( data )
\r
399 this.setValue( data.type );
\r
401 commit : function( data )
\r
403 data.type = this.getValue();
\r
413 widths : [ '25%', '75%' ],
\r
419 label : commonLang.protocol,
\r
420 'default' : 'http://',
\r
423 // Force 'ltr' for protocol names in BIDI. (#5433)
\r
424 [ 'http://\u200E', 'http://' ],
\r
425 [ 'https://\u200E', 'https://' ],
\r
426 [ 'ftp://\u200E', 'ftp://' ],
\r
427 [ 'news://\u200E', 'news://' ],
\r
428 [ linkLang.other , '' ]
\r
430 setup : function( data )
\r
433 this.setValue( data.url.protocol || '' );
\r
435 commit : function( data )
\r
440 data.url.protocol = this.getValue();
\r
446 label : commonLang.url,
\r
448 onLoad : function ()
\r
450 this.allowOnChange = true;
\r
452 onKeyUp : function()
\r
454 this.allowOnChange = false;
\r
455 var protocolCmb = this.getDialog().getContentElement( 'info', 'protocol' ),
\r
456 url = this.getValue(),
\r
457 urlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/i,
\r
458 urlOnChangeTestOther = /^((javascript:)|[#\/\.\?])/i;
\r
460 var protocol = urlOnChangeProtocol.exec( url );
\r
463 this.setValue( url.substr( protocol[ 0 ].length ) );
\r
464 protocolCmb.setValue( protocol[ 0 ].toLowerCase() );
\r
466 else if ( urlOnChangeTestOther.test( url ) )
\r
467 protocolCmb.setValue( '' );
\r
469 this.allowOnChange = true;
\r
471 onChange : function()
\r
473 if ( this.allowOnChange ) // Dont't call on dialog load.
\r
476 validate : function()
\r
478 var dialog = this.getDialog();
\r
480 if ( dialog.getContentElement( 'info', 'linkType' ) &&
\r
481 dialog.getValueOf( 'info', 'linkType' ) != 'url' )
\r
484 if ( this.getDialog().fakeObj ) // Edit Anchor.
\r
487 var func = CKEDITOR.dialog.validate.notEmpty( linkLang.noUrl );
\r
488 return func.apply( this );
\r
490 setup : function( data )
\r
492 this.allowOnChange = false;
\r
494 this.setValue( data.url.url );
\r
495 this.allowOnChange = true;
\r
498 commit : function( data )
\r
500 // IE will not trigger the onChange event if the mouse has been used
\r
501 // to carry all the operations #4724
\r
507 data.url.url = this.getValue();
\r
508 this.allowOnChange = false;
\r
512 setup : function( data )
\r
514 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
515 this.getElement().show();
\r
522 filebrowser : 'info:url',
\r
523 label : commonLang.browseServer
\r
529 id : 'anchorOptions',
\r
537 id : 'selectAnchorText',
\r
538 label : linkLang.selectAnchor,
\r
539 setup : function( data )
\r
541 if ( data.anchors.length > 0 )
\r
542 this.getElement().show();
\r
544 this.getElement().hide();
\r
550 id : 'selectAnchor',
\r
557 label : linkLang.anchorName,
\r
558 style : 'width: 100%;',
\r
563 setup : function( data )
\r
567 for ( var i = 0 ; i < data.anchors.length ; i++ )
\r
569 if ( data.anchors[i].name )
\r
570 this.add( data.anchors[i].name );
\r
574 this.setValue( data.anchor.name );
\r
576 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
577 if ( linkType && linkType.getValue() == 'email' )
\r
580 commit : function( data )
\r
582 if ( !data.anchor )
\r
585 data.anchor.name = this.getValue();
\r
592 label : linkLang.anchorId,
\r
593 style : 'width: 100%;',
\r
598 setup : function( data )
\r
602 for ( var i = 0 ; i < data.anchors.length ; i++ )
\r
604 if ( data.anchors[i].id )
\r
605 this.add( data.anchors[i].id );
\r
609 this.setValue( data.anchor.id );
\r
611 commit : function( data )
\r
613 if ( !data.anchor )
\r
616 data.anchor.id = this.getValue();
\r
620 setup : function( data )
\r
622 if ( data.anchors.length > 0 )
\r
623 this.getElement().show();
\r
625 this.getElement().hide();
\r
633 style : 'text-align: center;',
\r
634 html : '<div role="label" tabIndex="-1">' + CKEDITOR.tools.htmlEncode( linkLang.noAnchors ) + '</div>',
\r
635 // Focus the first element defined in above html.
\r
637 setup : function( data )
\r
639 if ( data.anchors.length < 1 )
\r
640 this.getElement().show();
\r
642 this.getElement().hide();
\r
646 setup : function( data )
\r
648 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
649 this.getElement().hide();
\r
654 id : 'emailOptions',
\r
660 id : 'emailAddress',
\r
661 label : linkLang.emailAddress,
\r
663 validate : function()
\r
665 var dialog = this.getDialog();
\r
667 if ( !dialog.getContentElement( 'info', 'linkType' ) ||
\r
668 dialog.getValueOf( 'info', 'linkType' ) != 'email' )
\r
671 var func = CKEDITOR.dialog.validate.notEmpty( linkLang.noEmail );
\r
672 return func.apply( this );
\r
674 setup : function( data )
\r
677 this.setValue( data.email.address );
\r
679 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
680 if ( linkType && linkType.getValue() == 'email' )
\r
683 commit : function( data )
\r
688 data.email.address = this.getValue();
\r
693 id : 'emailSubject',
\r
694 label : linkLang.emailSubject,
\r
695 setup : function( data )
\r
698 this.setValue( data.email.subject );
\r
700 commit : function( data )
\r
705 data.email.subject = this.getValue();
\r
711 label : linkLang.emailBody,
\r
714 setup : function( data )
\r
717 this.setValue( data.email.body );
\r
719 commit : function( data )
\r
724 data.email.body = this.getValue();
\r
728 setup : function( data )
\r
730 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
731 this.getElement().hide();
\r
738 label : linkLang.target,
\r
739 title : linkLang.target,
\r
744 widths : [ '50%', '50%' ],
\r
749 id : 'linkTargetType',
\r
750 label : commonLang.target,
\r
751 'default' : 'notSet',
\r
752 style : 'width : 100%;',
\r
755 [ commonLang.notSet, 'notSet' ],
\r
756 [ linkLang.targetFrame, 'frame' ],
\r
757 [ linkLang.targetPopup, 'popup' ],
\r
758 [ commonLang.targetNew, '_blank' ],
\r
759 [ commonLang.targetTop, '_top' ],
\r
760 [ commonLang.targetSelf, '_self' ],
\r
761 [ commonLang.targetParent, '_parent' ]
\r
763 onChange : targetChanged,
\r
764 setup : function( data )
\r
767 this.setValue( data.target.type || 'notSet' );
\r
768 targetChanged.call( this );
\r
770 commit : function( data )
\r
772 if ( !data.target )
\r
775 data.target.type = this.getValue();
\r
780 id : 'linkTargetName',
\r
781 label : linkLang.targetFrameName,
\r
783 setup : function( data )
\r
786 this.setValue( data.target.name );
\r
788 commit : function( data )
\r
790 if ( !data.target )
\r
793 data.target.name = this.getValue().replace(/\W/gi, '');
\r
803 id : 'popupFeatures',
\r
808 label : linkLang.popupFeatures,
\r
818 label : linkLang.popupResizable,
\r
819 setup : setupPopupParams,
\r
820 commit : commitPopupParams
\r
825 label : linkLang.popupStatusBar,
\r
826 setup : setupPopupParams,
\r
827 commit : commitPopupParams
\r
839 label : linkLang.popupLocationBar,
\r
840 setup : setupPopupParams,
\r
841 commit : commitPopupParams
\r
847 label : linkLang.popupToolbar,
\r
848 setup : setupPopupParams,
\r
849 commit : commitPopupParams
\r
861 label : linkLang.popupMenuBar,
\r
862 setup : setupPopupParams,
\r
863 commit : commitPopupParams
\r
869 label : linkLang.popupFullScreen,
\r
870 setup : setupPopupParams,
\r
871 commit : commitPopupParams
\r
883 label : linkLang.popupScrollBars,
\r
884 setup : setupPopupParams,
\r
885 commit : commitPopupParams
\r
891 label : linkLang.popupDependent,
\r
892 setup : setupPopupParams,
\r
893 commit : commitPopupParams
\r
904 widths : [ '50%', '50%' ],
\r
905 labelLayout : 'horizontal',
\r
906 label : commonLang.width,
\r
908 setup : setupPopupParams,
\r
909 commit : commitPopupParams
\r
914 labelLayout : 'horizontal',
\r
915 widths : [ '50%', '50%' ],
\r
916 label : linkLang.popupLeft,
\r
918 setup : setupPopupParams,
\r
919 commit : commitPopupParams
\r
930 labelLayout : 'horizontal',
\r
931 widths : [ '50%', '50%' ],
\r
932 label : commonLang.height,
\r
934 setup : setupPopupParams,
\r
935 commit : commitPopupParams
\r
940 labelLayout : 'horizontal',
\r
941 label : linkLang.popupTop,
\r
942 widths : [ '50%', '50%' ],
\r
944 setup : setupPopupParams,
\r
945 commit : commitPopupParams
\r
958 label : linkLang.upload,
\r
959 title : linkLang.upload,
\r
961 filebrowser : 'uploadButton',
\r
967 label : commonLang.upload,
\r
968 style: 'height:40px',
\r
972 type : 'fileButton',
\r
973 id : 'uploadButton',
\r
974 label : commonLang.uploadSubmit,
\r
975 filebrowser : 'info:url',
\r
976 'for' : [ 'upload', 'upload' ]
\r
982 label : linkLang.advanced,
\r
983 title : linkLang.advanced,
\r
993 widths : [ '45%', '35%', '20%' ],
\r
999 label : linkLang.id,
\r
1000 setup : setupAdvParams,
\r
1001 commit : commitAdvParams
\r
1005 id : 'advLangDir',
\r
1006 label : linkLang.langDir,
\r
1008 style : 'width:110px',
\r
1011 [ commonLang.notSet, '' ],
\r
1012 [ linkLang.langDirLTR, 'ltr' ],
\r
1013 [ linkLang.langDirRTL, 'rtl' ]
\r
1015 setup : setupAdvParams,
\r
1016 commit : commitAdvParams
\r
1020 id : 'advAccessKey',
\r
1022 label : linkLang.acccessKey,
\r
1024 setup : setupAdvParams,
\r
1025 commit : commitAdvParams
\r
1032 widths : [ '45%', '35%', '20%' ],
\r
1037 label : linkLang.name,
\r
1039 setup : setupAdvParams,
\r
1040 commit : commitAdvParams
\r
1045 label : linkLang.langCode,
\r
1046 id : 'advLangCode',
\r
1049 setup : setupAdvParams,
\r
1050 commit : commitAdvParams
\r
1055 label : linkLang.tabIndex,
\r
1056 id : 'advTabIndex',
\r
1059 setup : setupAdvParams,
\r
1060 commit : commitAdvParams
\r
1074 widths : [ '45%', '55%' ],
\r
1079 label : linkLang.advisoryTitle,
\r
1082 setup : setupAdvParams,
\r
1083 commit : commitAdvParams
\r
1088 label : linkLang.advisoryContentType,
\r
1090 id : 'advContentType',
\r
1091 setup : setupAdvParams,
\r
1092 commit : commitAdvParams
\r
1099 widths : [ '45%', '55%' ],
\r
1104 label : linkLang.cssClasses,
\r
1106 id : 'advCSSClasses',
\r
1107 setup : setupAdvParams,
\r
1108 commit : commitAdvParams
\r
1113 label : linkLang.charset,
\r
1115 id : 'advCharset',
\r
1116 setup : setupAdvParams,
\r
1117 commit : commitAdvParams
\r
1128 label : linkLang.styles,
\r
1131 setup : setupAdvParams,
\r
1132 commit : commitAdvParams
\r
1142 onShow : function()
\r
1144 this.fakeObj = false;
\r
1146 var editor = this.getParentEditor(),
\r
1147 selection = editor.getSelection(),
\r
1150 // Fill in all the relevant fields if there's already one link selected.
\r
1151 if ( ( element = plugin.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) )
\r
1152 selection.selectElement( element );
\r
1153 else if ( ( element = selection.getSelectedElement() ) && element.is( 'img' )
\r
1154 && element.data( 'cke-real-element-type' )
\r
1155 && element.data( 'cke-real-element-type' ) == 'anchor' )
\r
1157 this.fakeObj = element;
\r
1158 element = editor.restoreRealElement( this.fakeObj );
\r
1159 selection.selectElement( this.fakeObj );
\r
1164 this.setupContent( parseLink.apply( this, [ editor, element ] ) );
\r
1168 var attributes = {},
\r
1169 removeAttributes = [],
\r
1172 editor = this.getParentEditor();
\r
1174 this.commitContent( data );
\r
1176 // Compose the URL.
\r
1177 switch ( data.type || 'url' )
\r
1180 var protocol = ( data.url && data.url.protocol != undefined ) ? data.url.protocol : 'http://',
\r
1181 url = ( data.url && data.url.url ) || '';
\r
1182 attributes[ 'data-cke-saved-href' ] = ( url.indexOf( '/' ) === 0 ) ? url : protocol + url;
\r
1185 var name = ( data.anchor && data.anchor.name ),
\r
1186 id = ( data.anchor && data.anchor.id );
\r
1187 attributes[ 'data-cke-saved-href' ] = '#' + ( name || id || '' );
\r
1192 email = data.email,
\r
1193 address = email.address;
\r
1195 switch( emailProtection )
\r
1200 var subject = encodeURIComponent( email.subject || '' ),
\r
1201 body = encodeURIComponent( email.body || '' );
\r
1203 // Build the e-mail parameters first.
\r
1205 subject && argList.push( 'subject=' + subject );
\r
1206 body && argList.push( 'body=' + body );
\r
1207 argList = argList.length ? '?' + argList.join( '&' ) : '';
\r
1209 if ( emailProtection == 'encode' )
\r
1211 linkHref = [ 'javascript:void(location.href=\'mailto:\'+',
\r
1212 protectEmailAddressAsEncodedString( address ) ];
\r
1213 // parameters are optional.
\r
1214 argList && linkHref.push( '+\'', escapeSingleQuote( argList ), '\'' );
\r
1216 linkHref.push( ')' );
\r
1219 linkHref = [ 'mailto:', address, argList ];
\r
1225 // Separating name and domain.
\r
1226 var nameAndDomain = address.split( '@', 2 );
\r
1227 email.name = nameAndDomain[ 0 ];
\r
1228 email.domain = nameAndDomain[ 1 ];
\r
1230 linkHref = [ 'javascript:', protectEmailLinkAsFunction( email ) ];
\r
1234 attributes[ 'data-cke-saved-href' ] = linkHref.join( '' );
\r
1238 // Popups and target.
\r
1239 if ( data.target )
\r
1241 if ( data.target.type == 'popup' )
\r
1243 var onclickList = [ 'window.open(this.href, \'',
\r
1244 data.target.name || '', '\', \'' ];
\r
1245 var featureList = [ 'resizable', 'status', 'location', 'toolbar', 'menubar', 'fullscreen',
\r
1246 'scrollbars', 'dependent' ];
\r
1247 var featureLength = featureList.length;
\r
1248 var addFeature = function( featureName )
\r
1250 if ( data.target[ featureName ] )
\r
1251 featureList.push( featureName + '=' + data.target[ featureName ] );
\r
1254 for ( var i = 0 ; i < featureLength ; i++ )
\r
1255 featureList[i] = featureList[i] + ( data.target[ featureList[i] ] ? '=yes' : '=no' ) ;
\r
1256 addFeature( 'width' );
\r
1257 addFeature( 'left' );
\r
1258 addFeature( 'height' );
\r
1259 addFeature( 'top' );
\r
1261 onclickList.push( featureList.join( ',' ), '\'); return false;' );
\r
1262 attributes[ 'data-cke-pa-onclick' ] = onclickList.join( '' );
\r
1264 // Add the "target" attribute. (#5074)
\r
1265 removeAttributes.push( 'target' );
\r
1269 if ( data.target.type != 'notSet' && data.target.name )
\r
1270 attributes.target = data.target.name;
\r
1272 removeAttributes.push( 'target' );
\r
1274 removeAttributes.push( 'data-cke-pa-onclick', 'onclick' );
\r
1278 // Advanced attributes.
\r
1281 var advAttr = function( inputName, attrName )
\r
1283 var value = data.adv[ inputName ];
\r
1285 attributes[attrName] = value;
\r
1287 removeAttributes.push( attrName );
\r
1290 advAttr( 'advId', 'id' );
\r
1291 advAttr( 'advLangDir', 'dir' );
\r
1292 advAttr( 'advAccessKey', 'accessKey' );
\r
1294 if ( data.adv[ 'advName' ] )
\r
1296 attributes[ 'name' ] = attributes[ 'data-cke-saved-name' ] = data.adv[ 'advName' ];
\r
1297 attributes[ 'class' ] = ( attributes[ 'class' ] ? attributes[ 'class' ] + ' ' : '' ) + 'cke_anchor';
\r
1300 removeAttributes = removeAttributes.concat( [ 'data-cke-saved-name', 'name' ] );
\r
1302 advAttr( 'advLangCode', 'lang' );
\r
1303 advAttr( 'advTabIndex', 'tabindex' );
\r
1304 advAttr( 'advTitle', 'title' );
\r
1305 advAttr( 'advContentType', 'type' );
\r
1306 advAttr( 'advCSSClasses', 'class' );
\r
1307 advAttr( 'advCharset', 'charset' );
\r
1308 advAttr( 'advStyles', 'style' );
\r
1312 // Browser need the "href" fro copy/paste link to work. (#6641)
\r
1313 attributes.href = attributes[ 'data-cke-saved-href' ];
\r
1315 if ( !this._.selectedElement )
\r
1317 // Create element if current selection is collapsed.
\r
1318 var selection = editor.getSelection(),
\r
1319 ranges = selection.getRanges( true );
\r
1320 if ( ranges.length == 1 && ranges[0].collapsed )
\r
1322 // Short mailto link text view (#5736).
\r
1323 var text = new CKEDITOR.dom.text( data.type == 'email' ?
\r
1324 data.email.address : attributes[ 'data-cke-saved-href' ], editor.document );
\r
1325 ranges[0].insertNode( text );
\r
1326 ranges[0].selectNodeContents( text );
\r
1327 selection.selectRanges( ranges );
\r
1331 var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
\r
1332 style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why.
\r
1333 style.apply( editor.document );
\r
1337 // We're only editing an existing link, so just overwrite the attributes.
\r
1338 var element = this._.selectedElement,
\r
1339 href = element.data( 'cke-saved-href' ),
\r
1340 textView = element.getHtml();
\r
1342 // IE BUG: Setting the name attribute to an existing link doesn't work.
\r
1343 // Must re-create the link from weired syntax to workaround.
\r
1344 if ( CKEDITOR.env.ie && attributes.name != element.getAttribute( 'name' ) )
\r
1346 var newElement = new CKEDITOR.dom.element( '<a name="' + CKEDITOR.tools.htmlEncode( attributes.name ) + '">',
\r
1347 editor.document );
\r
1349 selection = editor.getSelection();
\r
1351 element.copyAttributes( newElement, { name : 1 } );
\r
1352 element.moveChildren( newElement );
\r
1353 newElement.replace( element );
\r
1354 element = newElement;
\r
1356 selection.selectElement( element );
\r
1359 element.setAttributes( attributes );
\r
1360 element.removeAttributes( removeAttributes );
\r
1361 // Update text view when user changes protocol (#4612).
\r
1362 if ( href == textView || data.type == 'email' && textView.indexOf( '@' ) != -1 )
\r
1364 // Short mailto link text view (#5736).
\r
1365 element.setHtml( data.type == 'email' ?
\r
1366 data.email.address : attributes[ 'data-cke-saved-href' ] );
\r
1368 // Make the element display as an anchor if a name has been set.
\r
1369 if ( element.getAttribute( 'name' ) )
\r
1370 element.addClass( 'cke_anchor' );
\r
1372 element.removeClass( 'cke_anchor' );
\r
1374 if ( this.fakeObj )
\r
1375 editor.createFakeElement( element, 'cke_anchor', 'anchor' ).replace( this.fakeObj );
\r
1377 delete this._.selectedElement;
\r
1380 onLoad : function()
\r
1382 if ( !editor.config.linkShowAdvancedTab )
\r
1383 this.hidePage( 'advanced' ); //Hide Advanded tab.
\r
1385 if ( !editor.config.linkShowTargetTab )
\r
1386 this.hidePage( 'target' ); //Hide Target tab.
\r
1389 // Inital focus on 'url' field if link is of type URL.
\r
1390 onFocus : function()
\r
1392 var linkType = this.getContentElement( 'info', 'linkType' ),
\r
1394 if ( linkType && linkType.getValue() == 'url' )
\r
1396 urlField = this.getContentElement( 'info', 'url' );
\r
1397 urlField.select();
\r
1404 * The e-mail address anti-spam protection option. The protection will be
\r
1405 * applied when creating or modifying e-mail links through the editor interface.<br>
\r
1406 * Two methods of protection can be choosed:
\r
1407 * <ol> <li>The e-mail parts (name, domain and any other query string) are
\r
1408 * assembled into a function call pattern. Such function must be
\r
1409 * provided by the developer in the pages that will use the contents.
\r
1410 * <li>Only the e-mail address is obfuscated into a special string that
\r
1411 * has no meaning for humans or spam bots, but which is properly
\r
1412 * rendered and accepted by the browser.</li></ol>
\r
1413 * Both approaches require JavaScript to be enabled.
\r
1414 * @name CKEDITOR.config.emailProtection
\r
1417 * @default '' (empty string = disabled)
\r
1419 * // href="mailto:tester@ckeditor.com?subject=subject&body=body"
\r
1420 * config.emailProtection = '';
\r
1422 * // 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
1423 * config.emailProtection = 'encode';
\r
1425 * // href="javascript:mt('tester','ckeditor.com','subject','body')"
\r
1426 * config.emailProtection = 'mt(NAME,DOMAIN,SUBJECT,BODY)';
\r