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
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
228 advAttr( 'advName', 'name' );
\r
229 advAttr( 'advLangCode', 'lang' );
\r
230 advAttr( 'advTabIndex', 'tabindex' );
\r
231 advAttr( 'advTitle', 'title' );
\r
232 advAttr( 'advContentType', 'type' );
\r
233 advAttr( 'advCSSClasses', 'class' );
\r
234 advAttr( 'advCharset', 'charset' );
\r
235 advAttr( 'advStyles', 'style' );
\r
238 // Find out whether we have any anchors in the editor.
\r
239 // Get all IMG elements in CK document.
\r
240 var elements = editor.document.getElementsByTag( 'img' ),
\r
241 realAnchors = new CKEDITOR.dom.nodeList( editor.document.$.anchors ),
\r
242 anchors = retval.anchors = [];
\r
244 for ( var i = 0; i < elements.count() ; i++ )
\r
246 var item = elements.getItem( i );
\r
247 if ( item.data( 'cke-realelement' ) && item.data( 'cke-real-element-type' ) == 'anchor' )
\r
248 anchors.push( editor.restoreRealElement( item ) );
\r
251 for ( i = 0 ; i < realAnchors.count() ; i++ )
\r
252 anchors.push( realAnchors.getItem( i ) );
\r
254 for ( i = 0 ; i < anchors.length ; i++ )
\r
256 item = anchors[ i ];
\r
257 anchors[ i ] = { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) };
\r
260 // Record down the selected element in the dialog.
\r
261 this._.selectedElement = element;
\r
266 var setupParams = function( page, data )
\r
269 this.setValue( data[page][this.id] || '' );
\r
272 var setupPopupParams = function( data )
\r
274 return setupParams.call( this, 'target', data );
\r
277 var setupAdvParams = function( data )
\r
279 return setupParams.call( this, 'adv', data );
\r
282 var commitParams = function( page, data )
\r
287 data[page][this.id] = this.getValue() || '';
\r
290 var commitPopupParams = function( data )
\r
292 return commitParams.call( this, 'target', data );
\r
295 var commitAdvParams = function( data )
\r
297 return commitParams.call( this, 'adv', data );
\r
300 function unescapeSingleQuote( str )
\r
302 return str.replace( /\\'/g, '\'' );
\r
305 function escapeSingleQuote( str )
\r
307 return str.replace( /'/g, '\\$&' );
\r
310 var emailProtection = editor.config.emailProtection || '';
\r
312 // Compile the protection function pattern.
\r
313 if ( emailProtection && emailProtection != 'encode' )
\r
315 var compiledProtectionFunction = {};
\r
317 emailProtection.replace( /^([^(]+)\(([^)]+)\)$/, function( match, funcName, params )
\r
319 compiledProtectionFunction.name = funcName;
\r
320 compiledProtectionFunction.params = [];
\r
321 params.replace( /[^,\s]+/g, function( param )
\r
323 compiledProtectionFunction.params.push( param );
\r
328 function protectEmailLinkAsFunction( email )
\r
331 name = compiledProtectionFunction.name,
\r
332 params = compiledProtectionFunction.params,
\r
336 retval = [ name, '(' ];
\r
337 for ( var i = 0; i < params.length; i++ )
\r
339 paramName = params[ i ].toLowerCase();
\r
340 paramValue = email[ paramName ];
\r
342 i > 0 && retval.push( ',' );
\r
345 escapeSingleQuote( encodeURIComponent( email[ paramName ] ) )
\r
349 retval.push( ')' );
\r
350 return retval.join( '' );
\r
353 function protectEmailAddressAsEncodedString( address )
\r
356 length = address.length,
\r
358 for ( var i = 0; i < length; i++ )
\r
360 charCode = address.charCodeAt( i );
\r
361 encodedChars.push( charCode );
\r
363 return 'String.fromCharCode(' + encodedChars.join( ',' ) + ')';
\r
366 var commonLang = editor.lang.common,
\r
367 linkLang = editor.lang.link;
\r
370 title : linkLang.title,
\r
376 label : linkLang.info,
\r
377 title : linkLang.info,
\r
383 label : linkLang.type,
\r
387 [ linkLang.toUrl, 'url' ],
\r
388 [ linkLang.toAnchor, 'anchor' ],
\r
389 [ linkLang.toEmail, 'email' ]
\r
391 onChange : linkTypeChanged,
\r
392 setup : function( data )
\r
395 this.setValue( data.type );
\r
397 commit : function( data )
\r
399 data.type = this.getValue();
\r
409 widths : [ '25%', '75%' ],
\r
415 label : commonLang.protocol,
\r
416 'default' : 'http://',
\r
419 // Force 'ltr' for protocol names in BIDI. (#5433)
\r
420 [ 'http://\u200E', 'http://' ],
\r
421 [ 'https://\u200E', 'https://' ],
\r
422 [ 'ftp://\u200E', 'ftp://' ],
\r
423 [ 'news://\u200E', 'news://' ],
\r
424 [ linkLang.other , '' ]
\r
426 setup : function( data )
\r
429 this.setValue( data.url.protocol || '' );
\r
431 commit : function( data )
\r
436 data.url.protocol = this.getValue();
\r
442 label : commonLang.url,
\r
444 onLoad : function ()
\r
446 this.allowOnChange = true;
\r
448 onKeyUp : function()
\r
450 this.allowOnChange = false;
\r
451 var protocolCmb = this.getDialog().getContentElement( 'info', 'protocol' ),
\r
452 url = this.getValue(),
\r
453 urlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/gi,
\r
454 urlOnChangeTestOther = /^((javascript:)|[#\/\.\?])/gi;
\r
456 var protocol = urlOnChangeProtocol.exec( url );
\r
459 this.setValue( url.substr( protocol[ 0 ].length ) );
\r
460 protocolCmb.setValue( protocol[ 0 ].toLowerCase() );
\r
462 else if ( urlOnChangeTestOther.test( url ) )
\r
463 protocolCmb.setValue( '' );
\r
465 this.allowOnChange = true;
\r
467 onChange : function()
\r
469 if ( this.allowOnChange ) // Dont't call on dialog load.
\r
472 validate : function()
\r
474 var dialog = this.getDialog();
\r
476 if ( dialog.getContentElement( 'info', 'linkType' ) &&
\r
477 dialog.getValueOf( 'info', 'linkType' ) != 'url' )
\r
480 if ( this.getDialog().fakeObj ) // Edit Anchor.
\r
483 var func = CKEDITOR.dialog.validate.notEmpty( linkLang.noUrl );
\r
484 return func.apply( this );
\r
486 setup : function( data )
\r
488 this.allowOnChange = false;
\r
490 this.setValue( data.url.url );
\r
491 this.allowOnChange = true;
\r
494 commit : function( data )
\r
496 // IE will not trigger the onChange event if the mouse has been used
\r
497 // to carry all the operations #4724
\r
503 data.url.url = this.getValue();
\r
504 this.allowOnChange = false;
\r
508 setup : function( data )
\r
510 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
511 this.getElement().show();
\r
518 filebrowser : 'info:url',
\r
519 label : commonLang.browseServer
\r
525 id : 'anchorOptions',
\r
533 id : 'selectAnchorText',
\r
534 label : linkLang.selectAnchor,
\r
535 setup : function( data )
\r
537 if ( data.anchors.length > 0 )
\r
538 this.getElement().show();
\r
540 this.getElement().hide();
\r
546 id : 'selectAnchor',
\r
553 label : linkLang.anchorName,
\r
554 style : 'width: 100%;',
\r
559 setup : function( data )
\r
563 for ( var i = 0 ; i < data.anchors.length ; i++ )
\r
565 if ( data.anchors[i].name )
\r
566 this.add( data.anchors[i].name );
\r
570 this.setValue( data.anchor.name );
\r
572 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
573 if ( linkType && linkType.getValue() == 'email' )
\r
576 commit : function( data )
\r
578 if ( !data.anchor )
\r
581 data.anchor.name = this.getValue();
\r
588 label : linkLang.anchorId,
\r
589 style : 'width: 100%;',
\r
594 setup : function( data )
\r
598 for ( var i = 0 ; i < data.anchors.length ; i++ )
\r
600 if ( data.anchors[i].id )
\r
601 this.add( data.anchors[i].id );
\r
605 this.setValue( data.anchor.id );
\r
607 commit : function( data )
\r
609 if ( !data.anchor )
\r
612 data.anchor.id = this.getValue();
\r
616 setup : function( data )
\r
618 if ( data.anchors.length > 0 )
\r
619 this.getElement().show();
\r
621 this.getElement().hide();
\r
629 style : 'text-align: center;',
\r
630 html : '<div role="label" tabIndex="-1">' + CKEDITOR.tools.htmlEncode( linkLang.noAnchors ) + '</div>',
\r
631 // Focus the first element defined in above html.
\r
633 setup : function( data )
\r
635 if ( data.anchors.length < 1 )
\r
636 this.getElement().show();
\r
638 this.getElement().hide();
\r
642 setup : function( data )
\r
644 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
645 this.getElement().hide();
\r
650 id : 'emailOptions',
\r
656 id : 'emailAddress',
\r
657 label : linkLang.emailAddress,
\r
659 validate : function()
\r
661 var dialog = this.getDialog();
\r
663 if ( !dialog.getContentElement( 'info', 'linkType' ) ||
\r
664 dialog.getValueOf( 'info', 'linkType' ) != 'email' )
\r
667 var func = CKEDITOR.dialog.validate.notEmpty( linkLang.noEmail );
\r
668 return func.apply( this );
\r
670 setup : function( data )
\r
673 this.setValue( data.email.address );
\r
675 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
676 if ( linkType && linkType.getValue() == 'email' )
\r
679 commit : function( data )
\r
684 data.email.address = this.getValue();
\r
689 id : 'emailSubject',
\r
690 label : linkLang.emailSubject,
\r
691 setup : function( data )
\r
694 this.setValue( data.email.subject );
\r
696 commit : function( data )
\r
701 data.email.subject = this.getValue();
\r
707 label : linkLang.emailBody,
\r
710 setup : function( data )
\r
713 this.setValue( data.email.body );
\r
715 commit : function( data )
\r
720 data.email.body = this.getValue();
\r
724 setup : function( data )
\r
726 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
727 this.getElement().hide();
\r
734 label : linkLang.target,
\r
735 title : linkLang.target,
\r
740 widths : [ '50%', '50%' ],
\r
745 id : 'linkTargetType',
\r
746 label : commonLang.target,
\r
747 'default' : 'notSet',
\r
748 style : 'width : 100%;',
\r
751 [ commonLang.notSet, 'notSet' ],
\r
752 [ linkLang.targetFrame, 'frame' ],
\r
753 [ linkLang.targetPopup, 'popup' ],
\r
754 [ commonLang.targetNew, '_blank' ],
\r
755 [ commonLang.targetTop, '_top' ],
\r
756 [ commonLang.targetSelf, '_self' ],
\r
757 [ commonLang.targetParent, '_parent' ]
\r
759 onChange : targetChanged,
\r
760 setup : function( data )
\r
763 this.setValue( data.target.type );
\r
764 targetChanged.call( this );
\r
766 commit : function( data )
\r
768 if ( !data.target )
\r
771 data.target.type = this.getValue();
\r
776 id : 'linkTargetName',
\r
777 label : linkLang.targetFrameName,
\r
779 setup : function( data )
\r
782 this.setValue( data.target.name );
\r
784 commit : function( data )
\r
786 if ( !data.target )
\r
789 data.target.name = this.getValue().replace(/\W/gi, '');
\r
799 id : 'popupFeatures',
\r
804 label : linkLang.popupFeatures,
\r
814 label : linkLang.popupResizable,
\r
815 setup : setupPopupParams,
\r
816 commit : commitPopupParams
\r
821 label : linkLang.popupStatusBar,
\r
822 setup : setupPopupParams,
\r
823 commit : commitPopupParams
\r
835 label : linkLang.popupLocationBar,
\r
836 setup : setupPopupParams,
\r
837 commit : commitPopupParams
\r
843 label : linkLang.popupToolbar,
\r
844 setup : setupPopupParams,
\r
845 commit : commitPopupParams
\r
857 label : linkLang.popupMenuBar,
\r
858 setup : setupPopupParams,
\r
859 commit : commitPopupParams
\r
865 label : linkLang.popupFullScreen,
\r
866 setup : setupPopupParams,
\r
867 commit : commitPopupParams
\r
879 label : linkLang.popupScrollBars,
\r
880 setup : setupPopupParams,
\r
881 commit : commitPopupParams
\r
887 label : linkLang.popupDependent,
\r
888 setup : setupPopupParams,
\r
889 commit : commitPopupParams
\r
900 widths : [ '50%', '50%' ],
\r
901 labelLayout : 'horizontal',
\r
902 label : commonLang.width,
\r
904 setup : setupPopupParams,
\r
905 commit : commitPopupParams
\r
910 labelLayout : 'horizontal',
\r
911 widths : [ '50%', '50%' ],
\r
912 label : linkLang.popupLeft,
\r
914 setup : setupPopupParams,
\r
915 commit : commitPopupParams
\r
926 labelLayout : 'horizontal',
\r
927 widths : [ '50%', '50%' ],
\r
928 label : commonLang.height,
\r
930 setup : setupPopupParams,
\r
931 commit : commitPopupParams
\r
936 labelLayout : 'horizontal',
\r
937 label : linkLang.popupTop,
\r
938 widths : [ '50%', '50%' ],
\r
940 setup : setupPopupParams,
\r
941 commit : commitPopupParams
\r
954 label : linkLang.upload,
\r
955 title : linkLang.upload,
\r
957 filebrowser : 'uploadButton',
\r
963 label : commonLang.upload,
\r
964 style: 'height:40px',
\r
968 type : 'fileButton',
\r
969 id : 'uploadButton',
\r
970 label : commonLang.uploadSubmit,
\r
971 filebrowser : 'info:url',
\r
972 'for' : [ 'upload', 'upload' ]
\r
978 label : linkLang.advanced,
\r
979 title : linkLang.advanced,
\r
989 widths : [ '45%', '35%', '20%' ],
\r
995 label : linkLang.id,
\r
996 setup : setupAdvParams,
\r
997 commit : commitAdvParams
\r
1001 id : 'advLangDir',
\r
1002 label : linkLang.langDir,
\r
1004 style : 'width:110px',
\r
1007 [ commonLang.notSet, '' ],
\r
1008 [ linkLang.langDirLTR, 'ltr' ],
\r
1009 [ linkLang.langDirRTL, 'rtl' ]
\r
1011 setup : setupAdvParams,
\r
1012 commit : commitAdvParams
\r
1016 id : 'advAccessKey',
\r
1018 label : linkLang.acccessKey,
\r
1020 setup : setupAdvParams,
\r
1021 commit : commitAdvParams
\r
1028 widths : [ '45%', '35%', '20%' ],
\r
1033 label : linkLang.name,
\r
1035 setup : setupAdvParams,
\r
1036 commit : commitAdvParams
\r
1041 label : linkLang.langCode,
\r
1042 id : 'advLangCode',
\r
1045 setup : setupAdvParams,
\r
1046 commit : commitAdvParams
\r
1051 label : linkLang.tabIndex,
\r
1052 id : 'advTabIndex',
\r
1055 setup : setupAdvParams,
\r
1056 commit : commitAdvParams
\r
1070 widths : [ '45%', '55%' ],
\r
1075 label : linkLang.advisoryTitle,
\r
1078 setup : setupAdvParams,
\r
1079 commit : commitAdvParams
\r
1084 label : linkLang.advisoryContentType,
\r
1086 id : 'advContentType',
\r
1087 setup : setupAdvParams,
\r
1088 commit : commitAdvParams
\r
1095 widths : [ '45%', '55%' ],
\r
1100 label : linkLang.cssClasses,
\r
1102 id : 'advCSSClasses',
\r
1103 setup : setupAdvParams,
\r
1104 commit : commitAdvParams
\r
1109 label : linkLang.charset,
\r
1111 id : 'advCharset',
\r
1112 setup : setupAdvParams,
\r
1113 commit : commitAdvParams
\r
1124 label : linkLang.styles,
\r
1127 setup : setupAdvParams,
\r
1128 commit : commitAdvParams
\r
1138 onShow : function()
\r
1140 this.fakeObj = false;
\r
1142 var editor = this.getParentEditor(),
\r
1143 selection = editor.getSelection(),
\r
1146 // Fill in all the relevant fields if there's already one link selected.
\r
1147 if ( ( element = plugin.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) )
\r
1148 selection.selectElement( element );
\r
1149 else if ( ( element = selection.getSelectedElement() ) && element.is( 'img' )
\r
1150 && element.data( 'cke-real-element-type' )
\r
1151 && element.data( 'cke-real-element-type' ) == 'anchor' )
\r
1153 this.fakeObj = element;
\r
1154 element = editor.restoreRealElement( this.fakeObj );
\r
1155 selection.selectElement( this.fakeObj );
\r
1160 this.setupContent( parseLink.apply( this, [ editor, element ] ) );
\r
1164 var attributes = { href : 'javascript:void(0)/*' + CKEDITOR.tools.getNextNumber() + '*/' },
\r
1165 removeAttributes = [],
\r
1166 data = { href : attributes.href },
\r
1168 editor = this.getParentEditor();
\r
1170 this.commitContent( data );
\r
1172 // Compose the URL.
\r
1173 switch ( data.type || 'url' )
\r
1176 var protocol = ( data.url && data.url.protocol != undefined ) ? data.url.protocol : 'http://',
\r
1177 url = ( data.url && data.url.url ) || '';
\r
1178 attributes[ 'data-cke-saved-href' ] = ( url.indexOf( '/' ) === 0 ) ? url : protocol + url;
\r
1181 var name = ( data.anchor && data.anchor.name ),
\r
1182 id = ( data.anchor && data.anchor.id );
\r
1183 attributes[ 'data-cke-saved-href' ] = '#' + ( name || id || '' );
\r
1188 email = data.email,
\r
1189 address = email.address;
\r
1191 switch( emailProtection )
\r
1196 var subject = encodeURIComponent( email.subject || '' ),
\r
1197 body = encodeURIComponent( email.body || '' );
\r
1199 // Build the e-mail parameters first.
\r
1201 subject && argList.push( 'subject=' + subject );
\r
1202 body && argList.push( 'body=' + body );
\r
1203 argList = argList.length ? '?' + argList.join( '&' ) : '';
\r
1205 if ( emailProtection == 'encode' )
\r
1207 linkHref = [ 'javascript:void(location.href=\'mailto:\'+',
\r
1208 protectEmailAddressAsEncodedString( address ) ];
\r
1209 // parameters are optional.
\r
1210 argList && linkHref.push( '+\'', escapeSingleQuote( argList ), '\'' );
\r
1212 linkHref.push( ')' );
\r
1215 linkHref = [ 'mailto:', address, argList ];
\r
1221 // Separating name and domain.
\r
1222 var nameAndDomain = address.split( '@', 2 );
\r
1223 email.name = nameAndDomain[ 0 ];
\r
1224 email.domain = nameAndDomain[ 1 ];
\r
1226 linkHref = [ 'javascript:', protectEmailLinkAsFunction( email ) ];
\r
1230 attributes[ 'data-cke-saved-href' ] = linkHref.join( '' );
\r
1234 // Popups and target.
\r
1235 if ( data.target )
\r
1237 if ( data.target.type == 'popup' )
\r
1239 var onclickList = [ 'window.open(this.href, \'',
\r
1240 data.target.name || '', '\', \'' ];
\r
1241 var featureList = [ 'resizable', 'status', 'location', 'toolbar', 'menubar', 'fullscreen',
\r
1242 'scrollbars', 'dependent' ];
\r
1243 var featureLength = featureList.length;
\r
1244 var addFeature = function( featureName )
\r
1246 if ( data.target[ featureName ] )
\r
1247 featureList.push( featureName + '=' + data.target[ featureName ] );
\r
1250 for ( var i = 0 ; i < featureLength ; i++ )
\r
1251 featureList[i] = featureList[i] + ( data.target[ featureList[i] ] ? '=yes' : '=no' ) ;
\r
1252 addFeature( 'width' );
\r
1253 addFeature( 'left' );
\r
1254 addFeature( 'height' );
\r
1255 addFeature( 'top' );
\r
1257 onclickList.push( featureList.join( ',' ), '\'); return false;' );
\r
1258 attributes[ 'data-cke-pa-onclick' ] = onclickList.join( '' );
\r
1260 // Add the "target" attribute. (#5074)
\r
1261 removeAttributes.push( 'target' );
\r
1265 if ( data.target.type != 'notSet' && data.target.name )
\r
1266 attributes.target = data.target.name;
\r
1268 removeAttributes.push( 'target' );
\r
1270 removeAttributes.push( 'data-cke-pa-onclick', 'onclick' );
\r
1274 // Advanced attributes.
\r
1277 var advAttr = function( inputName, attrName )
\r
1279 var value = data.adv[ inputName ];
\r
1281 attributes[attrName] = value;
\r
1283 removeAttributes.push( attrName );
\r
1286 if ( this._.selectedElement )
\r
1287 advAttr( 'advId', 'id' );
\r
1288 advAttr( 'advLangDir', 'dir' );
\r
1289 advAttr( 'advAccessKey', 'accessKey' );
\r
1290 advAttr( 'advName', 'name' );
\r
1291 advAttr( 'advLangCode', 'lang' );
\r
1292 advAttr( 'advTabIndex', 'tabindex' );
\r
1293 advAttr( 'advTitle', 'title' );
\r
1294 advAttr( 'advContentType', 'type' );
\r
1295 advAttr( 'advCSSClasses', 'class' );
\r
1296 advAttr( 'advCharset', 'charset' );
\r
1297 advAttr( 'advStyles', 'style' );
\r
1300 if ( !this._.selectedElement )
\r
1302 // Create element if current selection is collapsed.
\r
1303 var selection = editor.getSelection(),
\r
1304 ranges = selection.getRanges( true );
\r
1305 if ( ranges.length == 1 && ranges[0].collapsed )
\r
1307 // Short mailto link text view (#5736).
\r
1308 var text = new CKEDITOR.dom.text( data.type == 'email' ?
\r
1309 data.email.address : attributes[ 'data-cke-saved-href' ], editor.document );
\r
1310 ranges[0].insertNode( text );
\r
1311 ranges[0].selectNodeContents( text );
\r
1312 selection.selectRanges( ranges );
\r
1316 var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
\r
1317 style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why.
\r
1318 style.apply( editor.document );
\r
1320 // Id. Apply only to the first link.
\r
1321 if ( data.adv && data.adv.advId )
\r
1323 var links = this.getParentEditor().document.$.getElementsByTagName( 'a' );
\r
1324 for ( i = 0 ; i < links.length ; i++ )
\r
1326 if ( links[i].href == attributes.href )
\r
1328 links[i].id = data.adv.advId;
\r
1336 // We're only editing an existing link, so just overwrite the attributes.
\r
1337 var element = this._.selectedElement,
\r
1338 href = element.data( 'cke-saved-href' ),
\r
1339 textView = element.getHtml();
\r
1341 // IE BUG: Setting the name attribute to an existing link doesn't work.
\r
1342 // Must re-create the link from weired syntax to workaround.
\r
1343 if ( CKEDITOR.env.ie && attributes.name != element.getAttribute( 'name' ) )
\r
1345 var newElement = new CKEDITOR.dom.element( '<a name="' + CKEDITOR.tools.htmlEncode( attributes.name ) + '">',
\r
1346 editor.document );
\r
1348 selection = editor.getSelection();
\r
1350 element.moveChildren( newElement );
\r
1351 element.copyAttributes( newElement, { name : 1 } );
\r
1352 newElement.replace( element );
\r
1353 element = newElement;
\r
1355 selection.selectElement( element );
\r
1358 element.setAttributes( attributes );
\r
1359 element.removeAttributes( removeAttributes );
\r
1360 // Update text view when user changes protocol (#4612).
\r
1361 if ( href == textView || data.type == 'email' && textView.indexOf( '@' ) != -1 )
\r
1363 // Short mailto link text view (#5736).
\r
1364 element.setHtml( data.type == 'email' ?
\r
1365 data.email.address : attributes[ 'data-cke-saved-href' ] );
\r
1367 // Make the element display as an anchor if a name has been set.
\r
1368 if ( element.getAttribute( 'name' ) )
\r
1369 element.addClass( 'cke_anchor' );
\r
1371 element.removeClass( 'cke_anchor' );
\r
1373 if ( this.fakeObj )
\r
1374 editor.createFakeElement( element, 'cke_anchor', 'anchor' ).replace( this.fakeObj );
\r
1376 delete this._.selectedElement;
\r
1379 onLoad : function()
\r
1381 if ( !editor.config.linkShowAdvancedTab )
\r
1382 this.hidePage( 'advanced' ); //Hide Advanded tab.
\r
1384 if ( !editor.config.linkShowTargetTab )
\r
1385 this.hidePage( 'target' ); //Hide Target tab.
\r
1388 // Inital focus on 'url' field if link is of type URL.
\r
1389 onFocus : function()
\r
1391 var linkType = this.getContentElement( 'info', 'linkType' ),
\r
1393 if ( linkType && linkType.getValue() == 'url' )
\r
1395 urlField = this.getContentElement( 'info', 'url' );
\r
1396 urlField.select();
\r
1403 * The e-mail address anti-spam protection option. The protection will be
\r
1404 * applied when creating or modifying e-mail links through the editor interface.<br>
\r
1405 * Two methods of protection can be choosed:
\r
1406 * <ol> <li>The e-mail parts (name, domain and any other query string) are
\r
1407 * assembled into a function call pattern. Such function must be
\r
1408 * provided by the developer in the pages that will use the contents.
\r
1409 * <li>Only the e-mail address is obfuscated into a special string that
\r
1410 * has no meaning for humans or spam bots, but which is properly
\r
1411 * rendered and accepted by the browser.</li></ol>
\r
1412 * Both approaches require JavaScript to be enabled.
\r
1413 * @name CKEDITOR.config.emailProtection
\r
1416 * @default '' (empty string = disabled)
\r
1418 * // href="mailto:tester@ckeditor.com?subject=subject&body=body"
\r
1419 * config.emailProtection = '';
\r
1421 * // 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
1422 * config.emailProtection = 'encode';
\r
1424 * // href="javascript:mt('tester','ckeditor.com','subject','body')"
\r
1425 * config.emailProtection = 'mt(NAME,DOMAIN,SUBJECT,BODY)';
\r