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 // Handles the event when the "Target" selection box is changed.
\r
9 var targetChanged = function()
\r
11 var dialog = this.getDialog(),
\r
12 popupFeatures = dialog.getContentElement( 'target', 'popupFeatures' ),
\r
13 targetName = dialog.getContentElement( 'target', 'linkTargetName' ),
\r
14 value = this.getValue();
\r
16 if ( !popupFeatures || !targetName )
\r
19 popupFeatures = popupFeatures.getElement();
\r
20 popupFeatures.hide();
\r
21 targetName.setValue( '' );
\r
26 targetName.setLabel( editor.lang.link.targetFrameName );
\r
27 targetName.getElement().show();
\r
30 popupFeatures.show();
\r
31 targetName.setLabel( editor.lang.link.targetPopupName );
\r
32 targetName.getElement().show();
\r
35 targetName.setValue( value );
\r
36 targetName.getElement().hide();
\r
42 // Handles the event when the "Type" selection box is changed.
\r
43 var linkTypeChanged = function()
\r
45 var dialog = this.getDialog(),
\r
46 partIds = [ 'urlOptions', 'anchorOptions', 'emailOptions' ],
\r
47 typeValue = this.getValue(),
\r
48 uploadTab = dialog.definition.getContents( 'upload' ),
\r
49 uploadInitiallyHidden = uploadTab && uploadTab.hidden;
\r
51 if ( typeValue == 'url' )
\r
53 if ( editor.config.linkShowTargetTab )
\r
54 dialog.showPage( 'target' );
\r
55 if ( !uploadInitiallyHidden )
\r
56 dialog.showPage( 'upload' );
\r
60 dialog.hidePage( 'target' );
\r
61 if ( !uploadInitiallyHidden )
\r
62 dialog.hidePage( 'upload' );
\r
65 for ( var i = 0 ; i < partIds.length ; i++ )
\r
67 var element = dialog.getContentElement( 'info', partIds[i] );
\r
71 element = element.getElement().getParent().getParent();
\r
72 if ( partIds[i] == typeValue + 'Options' )
\r
79 // Loads the parameters in a selected link to the link dialog fields.
\r
80 var javascriptProtocolRegex = /^javascript:/,
\r
81 emailRegex = /^mailto:([^?]+)(?:\?(.+))?$/,
\r
82 emailSubjectRegex = /subject=([^;?:@&=$,\/]*)/,
\r
83 emailBodyRegex = /body=([^;?:@&=$,\/]*)/,
\r
84 anchorRegex = /^#(.*)$/,
\r
85 urlRegex = /^((?:http|https|ftp|news):\/\/)?(.*)$/,
\r
86 selectableTargets = /^(_(?:self|top|parent|blank))$/,
\r
87 encodedEmailLinkRegex = /^javascript:void\(location\.href='mailto:'\+String\.fromCharCode\(([^)]+)\)(?:\+'(.*)')?\)$/,
\r
88 functionCallProtectedEmailLinkRegex = /^javascript:([^(]+)\(([^)]+)\)$/;
\r
91 /\s*window.open\(\s*this\.href\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*/;
\r
92 var popupFeaturesRegex = /(?:^|,)([^=]+)=(\d+|yes|no)/gi;
\r
94 var parseLink = function( editor, element )
\r
96 var href = element ? ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) : '',
\r
103 if ( ( javascriptMatch = href.match( javascriptProtocolRegex ) ) )
\r
105 if ( emailProtection == 'encode' )
\r
107 href = href.replace( encodedEmailLinkRegex,
\r
108 function ( match, protectedAddress, rest )
\r
111 String.fromCharCode.apply( String, protectedAddress.split( ',' ) ) +
\r
112 ( rest && unescapeSingleQuote( rest ) );
\r
115 // Protected email link as function call.
\r
116 else if ( emailProtection )
\r
118 href.replace( functionCallProtectedEmailLinkRegex, function( match, funcName, funcArgs )
\r
120 if ( funcName == compiledProtectionFunction.name )
\r
122 retval.type = 'email';
\r
123 var email = retval.email = {};
\r
125 var paramRegex = /[^,\s]+/g,
\r
126 paramQuoteRegex = /(^')|('$)/g,
\r
127 paramsMatch = funcArgs.match( paramRegex ),
\r
128 paramsMatchLength = paramsMatch.length,
\r
132 for ( var i = 0; i < paramsMatchLength; i++ )
\r
134 paramVal = decodeURIComponent( unescapeSingleQuote( paramsMatch[ i ].replace( paramQuoteRegex, '' ) ) );
\r
135 paramName = compiledProtectionFunction.params[ i ].toLowerCase();
\r
136 email[ paramName ] = paramVal;
\r
138 email.address = [ email.name, email.domain ].join( '@' );
\r
144 if ( !retval.type )
\r
146 if ( ( anchorMatch = href.match( anchorRegex ) ) )
\r
148 retval.type = 'anchor';
\r
149 retval.anchor = {};
\r
150 retval.anchor.name = retval.anchor.id = anchorMatch[1];
\r
152 // Protected email link as encoded string.
\r
153 else if ( ( emailMatch = href.match( emailRegex ) ) )
\r
155 var subjectMatch = href.match( emailSubjectRegex ),
\r
156 bodyMatch = href.match( emailBodyRegex );
\r
158 retval.type = 'email';
\r
159 var email = ( retval.email = {} );
\r
160 email.address = emailMatch[ 1 ];
\r
161 subjectMatch && ( email.subject = decodeURIComponent( subjectMatch[ 1 ] ) );
\r
162 bodyMatch && ( email.body = decodeURIComponent( bodyMatch[ 1 ] ) );
\r
164 // urlRegex matches empty strings, so need to check for href as well.
\r
165 else if ( href && ( urlMatch = href.match( urlRegex ) ) )
\r
167 retval.type = 'url';
\r
169 retval.url.protocol = urlMatch[1];
\r
170 retval.url.url = urlMatch[2];
\r
173 retval.type = 'url';
\r
176 // Load target and popup settings.
\r
179 var target = element.getAttribute( 'target' );
\r
180 retval.target = {};
\r
183 // IE BUG: target attribute is an empty string instead of null in IE if it's not set.
\r
186 var onclick = element.getAttribute( '_cke_pa_onclick' ) || element.getAttribute( 'onclick' ),
\r
187 onclickMatch = onclick && onclick.match( popupRegex );
\r
188 if ( onclickMatch )
\r
190 retval.target.type = 'popup';
\r
191 retval.target.name = onclickMatch[1];
\r
194 while ( ( featureMatch = popupFeaturesRegex.exec( onclickMatch[2] ) ) )
\r
196 if ( featureMatch[2] == 'yes' || featureMatch[2] == '1' )
\r
197 retval.target[ featureMatch[1] ] = true;
\r
198 else if ( isFinite( featureMatch[2] ) )
\r
199 retval.target[ featureMatch[1] ] = featureMatch[2];
\r
205 var targetMatch = target.match( selectableTargets );
\r
207 retval.target.type = retval.target.name = target;
\r
210 retval.target.type = 'frame';
\r
211 retval.target.name = target;
\r
216 var advAttr = function( inputName, attrName )
\r
218 var value = element.getAttribute( attrName );
\r
219 if ( value !== null )
\r
220 retval.adv[ inputName ] = value || '';
\r
222 advAttr( 'advId', 'id' );
\r
223 advAttr( 'advLangDir', 'dir' );
\r
224 advAttr( 'advAccessKey', 'accessKey' );
\r
225 advAttr( 'advName', 'name' );
\r
226 advAttr( 'advLangCode', 'lang' );
\r
227 advAttr( 'advTabIndex', 'tabindex' );
\r
228 advAttr( 'advTitle', 'title' );
\r
229 advAttr( 'advContentType', 'type' );
\r
230 advAttr( 'advCSSClasses', 'class' );
\r
231 advAttr( 'advCharset', 'charset' );
\r
232 advAttr( 'advStyles', 'style' );
\r
235 // Find out whether we have any anchors in the editor.
\r
236 // Get all IMG elements in CK document.
\r
237 var elements = editor.document.getElementsByTag( 'img' ),
\r
238 realAnchors = new CKEDITOR.dom.nodeList( editor.document.$.anchors ),
\r
239 anchors = retval.anchors = [];
\r
241 for ( var i = 0; i < elements.count() ; i++ )
\r
243 var item = elements.getItem( i );
\r
244 if ( item.getAttribute( '_cke_realelement' ) && item.getAttribute( '_cke_real_element_type' ) == 'anchor' )
\r
246 anchors.push( editor.restoreRealElement( item ) );
\r
250 for ( i = 0 ; i < realAnchors.count() ; i++ )
\r
251 anchors.push( realAnchors.getItem( i ) );
\r
253 for ( i = 0 ; i < anchors.length ; i++ )
\r
255 item = anchors[ i ];
\r
256 anchors[ i ] = { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) };
\r
259 // Record down the selected element in the dialog.
\r
260 this._.selectedElement = element;
\r
265 var setupParams = function( page, data )
\r
268 this.setValue( data[page][this.id] || '' );
\r
271 var setupPopupParams = function( data )
\r
273 return setupParams.call( this, 'target', data );
\r
276 var setupAdvParams = function( data )
\r
278 return setupParams.call( this, 'adv', data );
\r
281 var commitParams = function( page, data )
\r
286 data[page][this.id] = this.getValue() || '';
\r
289 var commitPopupParams = function( data )
\r
291 return commitParams.call( this, 'target', data );
\r
294 var commitAdvParams = function( data )
\r
296 return commitParams.call( this, 'adv', data );
\r
299 function unescapeSingleQuote( str )
\r
301 return str.replace( /\\'/g, '\'' );
\r
304 function escapeSingleQuote( str )
\r
306 return str.replace( /'/g, '\\$&' );
\r
309 var emailProtection = editor.config.emailProtection || '';
\r
311 // Compile the protection function pattern.
\r
312 if ( emailProtection && emailProtection != 'encode' )
\r
314 var compiledProtectionFunction = {};
\r
316 emailProtection.replace( /^([^(]+)\(([^)]+)\)$/, function( match, funcName, params )
\r
318 compiledProtectionFunction.name = funcName;
\r
319 compiledProtectionFunction.params = [];
\r
320 params.replace( /[^,\s]+/g, function( param )
\r
322 compiledProtectionFunction.params.push( param );
\r
327 function protectEmailLinkAsFunction( email )
\r
330 name = compiledProtectionFunction.name,
\r
331 params = compiledProtectionFunction.params,
\r
335 retval = [ name, '(' ];
\r
336 for ( var i = 0; i < params.length; i++ )
\r
338 paramName = params[ i ].toLowerCase();
\r
339 paramValue = email[ paramName ];
\r
341 i > 0 && retval.push( ',' );
\r
344 escapeSingleQuote( encodeURIComponent( email[ paramName ] ) )
\r
348 retval.push( ')' );
\r
349 return retval.join( '' );
\r
352 function protectEmailAddressAsEncodedString( address )
\r
355 length = address.length,
\r
357 for ( var i = 0; i < length; i++ )
\r
359 charCode = address.charCodeAt( i );
\r
360 encodedChars.push( charCode );
\r
362 return 'String.fromCharCode(' + encodedChars.join( ',' ) + ')';
\r
366 title : editor.lang.link.title,
\r
372 label : editor.lang.link.info,
\r
373 title : editor.lang.link.info,
\r
379 label : editor.lang.link.type,
\r
383 [ editor.lang.common.url, 'url' ],
\r
384 [ editor.lang.link.toAnchor, 'anchor' ],
\r
385 [ editor.lang.link.toEmail, 'email' ]
\r
387 onChange : linkTypeChanged,
\r
388 setup : function( data )
\r
391 this.setValue( data.type );
\r
393 commit : function( data )
\r
395 data.type = this.getValue();
\r
405 widths : [ '25%', '75%' ],
\r
411 label : editor.lang.common.protocol,
\r
412 'default' : 'http://',
\r
413 style : 'width : 100%;',
\r
422 setup : function( data )
\r
425 this.setValue( data.url.protocol || '' );
\r
427 commit : function( data )
\r
432 data.url.protocol = this.getValue();
\r
438 label : editor.lang.common.url,
\r
439 onLoad : function ()
\r
441 this.allowOnChange = true;
\r
443 onKeyUp : function()
\r
445 this.allowOnChange = false;
\r
446 var protocolCmb = this.getDialog().getContentElement( 'info', 'protocol' ),
\r
447 url = this.getValue(),
\r
448 urlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/gi,
\r
449 urlOnChangeTestOther = /^((javascript:)|[#\/\.])/gi;
\r
451 var protocol = urlOnChangeProtocol.exec( url );
\r
454 this.setValue( url.substr( protocol[ 0 ].length ) );
\r
455 protocolCmb.setValue( protocol[ 0 ].toLowerCase() );
\r
457 else if ( urlOnChangeTestOther.test( url ) )
\r
458 protocolCmb.setValue( '' );
\r
460 this.allowOnChange = true;
\r
462 onChange : function()
\r
464 if ( this.allowOnChange ) // Dont't call on dialog load.
\r
467 validate : function()
\r
469 var dialog = this.getDialog();
\r
471 if ( dialog.getContentElement( 'info', 'linkType' ) &&
\r
472 dialog.getValueOf( 'info', 'linkType' ) != 'url' )
\r
475 if ( this.getDialog().fakeObj ) // Edit Anchor.
\r
478 var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noUrl );
\r
479 return func.apply( this );
\r
481 setup : function( data )
\r
483 this.allowOnChange = false;
\r
485 this.setValue( data.url.url );
\r
486 this.allowOnChange = true;
\r
488 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
489 if ( linkType && linkType.getValue() == 'url' )
\r
493 commit : function( data )
\r
495 // IE will not trigger the onChange event if the mouse has been used
\r
496 // to carry all the operations #4724
\r
502 data.url.url = this.getValue();
\r
503 this.allowOnChange = false;
\r
507 setup : function( data )
\r
509 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
510 this.getElement().show();
\r
517 filebrowser : 'info:url',
\r
518 label : editor.lang.common.browseServer
\r
524 id : 'anchorOptions',
\r
532 id : 'selectAnchorText',
\r
533 html : CKEDITOR.tools.htmlEncode( editor.lang.link.selectAnchor ),
\r
534 setup : function( data )
\r
536 if ( data.anchors.length > 0 )
\r
537 this.getElement().show();
\r
539 this.getElement().hide();
\r
545 style : 'text-align: center;',
\r
546 html : '<div>' + CKEDITOR.tools.htmlEncode( editor.lang.link.noAnchors ) + '</div>',
\r
547 setup : function( data )
\r
549 if ( data.anchors.length < 1 )
\r
550 this.getElement().show();
\r
552 this.getElement().hide();
\r
557 id : 'selectAnchor',
\r
564 label : editor.lang.link.anchorName,
\r
565 style : 'width: 100%;',
\r
570 setup : function( data )
\r
574 for ( var i = 0 ; i < data.anchors.length ; i++ )
\r
576 if ( data.anchors[i].name )
\r
577 this.add( data.anchors[i].name );
\r
581 this.setValue( data.anchor.name );
\r
583 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
584 if ( linkType && linkType.getValue() == 'email' )
\r
587 commit : function( data )
\r
589 if ( !data.anchor )
\r
592 data.anchor.name = this.getValue();
\r
599 label : editor.lang.link.anchorId,
\r
600 style : 'width: 100%;',
\r
605 setup : function( data )
\r
609 for ( var i = 0 ; i < data.anchors.length ; i++ )
\r
611 if ( data.anchors[i].id )
\r
612 this.add( data.anchors[i].id );
\r
616 this.setValue( data.anchor.id );
\r
618 commit : function( data )
\r
620 if ( !data.anchor )
\r
623 data.anchor.id = this.getValue();
\r
627 setup : function( data )
\r
629 if ( data.anchors.length > 0 )
\r
630 this.getElement().show();
\r
632 this.getElement().hide();
\r
636 setup : function( data )
\r
638 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
639 this.getElement().hide();
\r
644 id : 'emailOptions',
\r
650 id : 'emailAddress',
\r
651 label : editor.lang.link.emailAddress,
\r
652 validate : function()
\r
654 var dialog = this.getDialog();
\r
656 if ( !dialog.getContentElement( 'info', 'linkType' ) ||
\r
657 dialog.getValueOf( 'info', 'linkType' ) != 'email' )
\r
660 var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noEmail );
\r
661 return func.apply( this );
\r
663 setup : function( data )
\r
666 this.setValue( data.email.address );
\r
668 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
669 if ( linkType && linkType.getValue() == 'email' )
\r
672 commit : function( data )
\r
677 data.email.address = this.getValue();
\r
682 id : 'emailSubject',
\r
683 label : editor.lang.link.emailSubject,
\r
684 setup : function( data )
\r
687 this.setValue( data.email.subject );
\r
689 commit : function( data )
\r
694 data.email.subject = this.getValue();
\r
700 label : editor.lang.link.emailBody,
\r
703 setup : function( data )
\r
706 this.setValue( data.email.body );
\r
708 commit : function( data )
\r
713 data.email.body = this.getValue();
\r
717 setup : function( data )
\r
719 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
720 this.getElement().hide();
\r
727 label : editor.lang.link.target,
\r
728 title : editor.lang.link.target,
\r
733 widths : [ '50%', '50%' ],
\r
738 id : 'linkTargetType',
\r
739 label : editor.lang.link.target,
\r
740 'default' : 'notSet',
\r
741 style : 'width : 100%;',
\r
744 [ editor.lang.link.targetNotSet, 'notSet' ],
\r
745 [ editor.lang.link.targetFrame, 'frame' ],
\r
746 [ editor.lang.link.targetPopup, 'popup' ],
\r
747 [ editor.lang.link.targetNew, '_blank' ],
\r
748 [ editor.lang.link.targetTop, '_top' ],
\r
749 [ editor.lang.link.targetSelf, '_self' ],
\r
750 [ editor.lang.link.targetParent, '_parent' ]
\r
752 onChange : targetChanged,
\r
753 setup : function( data )
\r
756 this.setValue( data.target.type );
\r
758 commit : function( data )
\r
760 if ( !data.target )
\r
763 data.target.type = this.getValue();
\r
768 id : 'linkTargetName',
\r
769 label : editor.lang.link.targetFrameName,
\r
771 setup : function( data )
\r
774 this.setValue( data.target.name );
\r
776 commit : function( data )
\r
778 if ( !data.target )
\r
781 data.target.name = this.getValue();
\r
791 id : 'popupFeatures',
\r
796 html : CKEDITOR.tools.htmlEncode( editor.lang.link.popupFeatures )
\r
805 label : editor.lang.link.popupResizable,
\r
806 setup : setupPopupParams,
\r
807 commit : commitPopupParams
\r
812 label : editor.lang.link.popupStatusBar,
\r
813 setup : setupPopupParams,
\r
814 commit : commitPopupParams
\r
826 label : editor.lang.link.popupLocationBar,
\r
827 setup : setupPopupParams,
\r
828 commit : commitPopupParams
\r
834 label : editor.lang.link.popupToolbar,
\r
835 setup : setupPopupParams,
\r
836 commit : commitPopupParams
\r
848 label : editor.lang.link.popupMenuBar,
\r
849 setup : setupPopupParams,
\r
850 commit : commitPopupParams
\r
856 label : editor.lang.link.popupFullScreen,
\r
857 setup : setupPopupParams,
\r
858 commit : commitPopupParams
\r
870 label : editor.lang.link.popupScrollBars,
\r
871 setup : setupPopupParams,
\r
872 commit : commitPopupParams
\r
878 label : editor.lang.link.popupDependent,
\r
879 setup : setupPopupParams,
\r
880 commit : commitPopupParams
\r
891 widths : [ '30%', '70%' ],
\r
892 labelLayout : 'horizontal',
\r
893 label : editor.lang.link.popupWidth,
\r
895 setup : setupPopupParams,
\r
896 commit : commitPopupParams
\r
901 labelLayout : 'horizontal',
\r
902 widths : [ '55%', '45%' ],
\r
903 label : editor.lang.link.popupLeft,
\r
905 setup : setupPopupParams,
\r
906 commit : commitPopupParams
\r
917 labelLayout : 'horizontal',
\r
918 widths : [ '30%', '70%' ],
\r
919 label : editor.lang.link.popupHeight,
\r
921 setup : setupPopupParams,
\r
922 commit : commitPopupParams
\r
927 labelLayout : 'horizontal',
\r
928 label : editor.lang.link.popupTop,
\r
929 widths : [ '55%', '45%' ],
\r
931 setup : setupPopupParams,
\r
932 commit : commitPopupParams
\r
943 label : editor.lang.link.upload,
\r
944 title : editor.lang.link.upload,
\r
946 filebrowser : 'uploadButton',
\r
952 label : editor.lang.common.upload,
\r
953 style: 'height:40px',
\r
957 type : 'fileButton',
\r
958 id : 'uploadButton',
\r
959 label : editor.lang.common.uploadSubmit,
\r
960 filebrowser : 'info:url',
\r
961 'for' : [ 'upload', 'upload' ]
\r
967 label : editor.lang.link.advanced,
\r
968 title : editor.lang.link.advanced,
\r
978 widths : [ '45%', '35%', '20%' ],
\r
984 label : editor.lang.link.id,
\r
985 setup : setupAdvParams,
\r
986 commit : commitAdvParams
\r
991 label : editor.lang.link.langDir,
\r
993 style : 'width:110px',
\r
996 [ editor.lang.link.langDirNotSet, '' ],
\r
997 [ editor.lang.link.langDirLTR, 'ltr' ],
\r
998 [ editor.lang.link.langDirRTL, 'rtl' ]
\r
1000 setup : setupAdvParams,
\r
1001 commit : commitAdvParams
\r
1005 id : 'advAccessKey',
\r
1007 label : editor.lang.link.acccessKey,
\r
1009 setup : setupAdvParams,
\r
1010 commit : commitAdvParams
\r
1017 widths : [ '45%', '35%', '20%' ],
\r
1022 label : editor.lang.link.name,
\r
1024 setup : setupAdvParams,
\r
1025 commit : commitAdvParams
\r
1030 label : editor.lang.link.langCode,
\r
1031 id : 'advLangCode',
\r
1034 setup : setupAdvParams,
\r
1035 commit : commitAdvParams
\r
1040 label : editor.lang.link.tabIndex,
\r
1041 id : 'advTabIndex',
\r
1044 setup : setupAdvParams,
\r
1045 commit : commitAdvParams
\r
1059 widths : [ '45%', '55%' ],
\r
1064 label : editor.lang.link.advisoryTitle,
\r
1067 setup : setupAdvParams,
\r
1068 commit : commitAdvParams
\r
1073 label : editor.lang.link.advisoryContentType,
\r
1075 id : 'advContentType',
\r
1076 setup : setupAdvParams,
\r
1077 commit : commitAdvParams
\r
1084 widths : [ '45%', '55%' ],
\r
1089 label : editor.lang.link.cssClasses,
\r
1091 id : 'advCSSClasses',
\r
1092 setup : setupAdvParams,
\r
1093 commit : commitAdvParams
\r
1098 label : editor.lang.link.charset,
\r
1100 id : 'advCharset',
\r
1101 setup : setupAdvParams,
\r
1102 commit : commitAdvParams
\r
1113 label : editor.lang.link.styles,
\r
1116 setup : setupAdvParams,
\r
1117 commit : commitAdvParams
\r
1127 onShow : function()
\r
1129 this.fakeObj = false;
\r
1131 var editor = this.getParentEditor(),
\r
1132 selection = editor.getSelection(),
\r
1133 ranges = selection.getRanges(),
\r
1136 // Fill in all the relevant fields if there's already one link selected.
\r
1137 if ( ranges.length == 1 )
\r
1140 var rangeRoot = ranges[0].getCommonAncestor( true );
\r
1141 element = rangeRoot.getAscendant( 'a', true );
\r
1142 if ( element && element.getAttribute( 'href' ) )
\r
1144 selection.selectElement( element );
\r
1146 else if ( ( element = rangeRoot.getAscendant( 'img', true ) ) &&
\r
1147 element.getAttribute( '_cke_real_element_type' ) &&
\r
1148 element.getAttribute( '_cke_real_element_type' ) == 'anchor' )
\r
1150 this.fakeObj = element;
\r
1151 element = editor.restoreRealElement( this.fakeObj );
\r
1152 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
1260 if ( data.target.type != 'notSet' && data.target.name )
\r
1261 attributes.target = data.target.name;
\r
1263 removeAttributes.push( 'target' );
\r
1265 removeAttributes.push( '_cke_pa_onclick', 'onclick' );
\r
1269 // Advanced attributes.
\r
1272 var advAttr = function( inputName, attrName )
\r
1274 var value = data.adv[ inputName ];
\r
1276 attributes[attrName] = value;
\r
1278 removeAttributes.push( attrName );
\r
1281 if ( this._.selectedElement )
\r
1282 advAttr( 'advId', 'id' );
\r
1283 advAttr( 'advLangDir', 'dir' );
\r
1284 advAttr( 'advAccessKey', 'accessKey' );
\r
1285 advAttr( 'advName', 'name' );
\r
1286 advAttr( 'advLangCode', 'lang' );
\r
1287 advAttr( 'advTabIndex', 'tabindex' );
\r
1288 advAttr( 'advTitle', 'title' );
\r
1289 advAttr( 'advContentType', 'type' );
\r
1290 advAttr( 'advCSSClasses', 'class' );
\r
1291 advAttr( 'advCharset', 'charset' );
\r
1292 advAttr( 'advStyles', 'style' );
\r
1295 if ( !this._.selectedElement )
\r
1297 // Create element if current selection is collapsed.
\r
1298 var selection = editor.getSelection(),
\r
1299 ranges = selection.getRanges();
\r
1300 if ( ranges.length == 1 && ranges[0].collapsed )
\r
1302 var text = new CKEDITOR.dom.text( attributes._cke_saved_href, editor.document );
\r
1303 ranges[0].insertNode( text );
\r
1304 ranges[0].selectNodeContents( text );
\r
1305 selection.selectRanges( ranges );
\r
1309 var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
\r
1310 style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why.
\r
1311 style.apply( editor.document );
\r
1313 // Id. Apply only to the first link.
\r
1314 if ( data.adv && data.adv.advId )
\r
1316 var links = this.getParentEditor().document.$.getElementsByTagName( 'a' );
\r
1317 for ( i = 0 ; i < links.length ; i++ )
\r
1319 if ( links[i].href == attributes.href )
\r
1321 links[i].id = data.adv.advId;
\r
1329 // We're only editing an existing link, so just overwrite the attributes.
\r
1330 var element = this._.selectedElement,
\r
1331 href = element.getAttribute( '_cke_saved_href' ),
\r
1332 textView = element.getHtml();
\r
1334 // IE BUG: Setting the name attribute to an existing link doesn't work.
\r
1335 // Must re-create the link from weired syntax to workaround.
\r
1336 if ( CKEDITOR.env.ie && attributes.name != element.getAttribute( 'name' ) )
\r
1338 var newElement = new CKEDITOR.dom.element( '<a name="' + CKEDITOR.tools.htmlEncode( attributes.name ) + '">',
\r
1339 editor.document );
\r
1341 selection = editor.getSelection();
\r
1343 element.moveChildren( newElement );
\r
1344 element.copyAttributes( newElement, { name : 1 } );
\r
1345 newElement.replace( element );
\r
1346 element = newElement;
\r
1348 selection.selectElement( element );
\r
1351 element.setAttributes( attributes );
\r
1352 element.removeAttributes( removeAttributes );
\r
1353 // Update text view when user changes protocol #4612.
\r
1354 if (href == textView)
\r
1355 element.setHtml( attributes._cke_saved_href );
\r
1356 // Make the element display as an anchor if a name has been set.
\r
1357 if ( element.getAttribute( 'name' ) )
\r
1358 element.addClass( 'cke_anchor' );
\r
1360 element.removeClass( 'cke_anchor' );
\r
1362 if ( this.fakeObj )
\r
1363 editor.createFakeElement( element, 'cke_anchor', 'anchor' ).replace( this.fakeObj );
\r
1365 delete this._.selectedElement;
\r
1368 onLoad : function()
\r
1370 if ( !editor.config.linkShowAdvancedTab )
\r
1371 this.hidePage( 'advanced' ); //Hide Advanded tab.
\r
1373 if ( !editor.config.linkShowTargetTab )
\r
1374 this.hidePage( 'target' ); //Hide Target tab.
\r
1381 * The e-mail address anti-spam protection option. The protection will be
\r
1382 * applied when creating or modifying e-mail links through the editor interface.<br>
\r
1383 * Two methods of protection can be choosed:
\r
1384 * <ol> <li>The e-mail parts (name, domain and any other query string) are
\r
1385 * assembled into a function call pattern. Such function must be
\r
1386 * provided by the developer in the pages that will use the contents.
\r
1387 * <li>Only the e-mail address is obfuscated into a special string that
\r
1388 * has no meaning for humans or spam bots, but which is properly
\r
1389 * rendered and accepted by the browser.</li></ol>
\r
1390 * Both approaches require JavaScript to be enabled.
\r
1391 * @name CKEDITOR.config.emailProtection
\r
1394 * @default '' (empty string = disabled)
\r
1396 * // href="mailto:tester@ckeditor.com?subject=subject&body=body"
\r
1397 * config.emailProtection = '';
\r
1399 * // 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
1400 * config.emailProtection = 'encode';
\r
1402 * // href="javascript:mt('tester','ckeditor.com','subject','body')"
\r
1403 * config.emailProtection = 'mt(NAME,DOMAIN,SUBJECT,BODY)';
\r