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
247 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
367 title : editor.lang.link.title,
\r
373 label : editor.lang.link.info,
\r
374 title : editor.lang.link.info,
\r
380 label : editor.lang.link.type,
\r
384 [ editor.lang.link.toUrl, 'url' ],
\r
385 [ editor.lang.link.toAnchor, 'anchor' ],
\r
386 [ editor.lang.link.toEmail, 'email' ]
\r
388 onChange : linkTypeChanged,
\r
389 setup : function( data )
\r
392 this.setValue( data.type );
\r
394 commit : function( data )
\r
396 data.type = this.getValue();
\r
406 widths : [ '25%', '75%' ],
\r
412 label : editor.lang.common.protocol,
\r
413 'default' : 'http://',
\r
416 // Force 'ltr' for protocol names in BIDI. (#5433)
\r
417 [ 'http://\u200E', 'http://' ],
\r
418 [ 'https://\u200E', 'https://' ],
\r
419 [ 'ftp://\u200E', 'ftp://' ],
\r
420 [ 'news://\u200E', 'news://' ],
\r
421 [ editor.lang.link.other , '' ]
\r
423 setup : function( data )
\r
426 this.setValue( data.url.protocol || '' );
\r
428 commit : function( data )
\r
433 data.url.protocol = this.getValue();
\r
439 label : editor.lang.common.url,
\r
441 onLoad : function ()
\r
443 this.allowOnChange = true;
\r
445 onKeyUp : function()
\r
447 this.allowOnChange = false;
\r
448 var protocolCmb = this.getDialog().getContentElement( 'info', 'protocol' ),
\r
449 url = this.getValue(),
\r
450 urlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/gi,
\r
451 urlOnChangeTestOther = /^((javascript:)|[#\/\.\?])/gi;
\r
453 var protocol = urlOnChangeProtocol.exec( url );
\r
456 this.setValue( url.substr( protocol[ 0 ].length ) );
\r
457 protocolCmb.setValue( protocol[ 0 ].toLowerCase() );
\r
459 else if ( urlOnChangeTestOther.test( url ) )
\r
460 protocolCmb.setValue( '' );
\r
462 this.allowOnChange = true;
\r
464 onChange : function()
\r
466 if ( this.allowOnChange ) // Dont't call on dialog load.
\r
469 validate : function()
\r
471 var dialog = this.getDialog();
\r
473 if ( dialog.getContentElement( 'info', 'linkType' ) &&
\r
474 dialog.getValueOf( 'info', 'linkType' ) != 'url' )
\r
477 if ( this.getDialog().fakeObj ) // Edit Anchor.
\r
480 var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noUrl );
\r
481 return func.apply( this );
\r
483 setup : function( data )
\r
485 this.allowOnChange = false;
\r
487 this.setValue( data.url.url );
\r
488 this.allowOnChange = true;
\r
491 commit : function( data )
\r
493 // IE will not trigger the onChange event if the mouse has been used
\r
494 // to carry all the operations #4724
\r
500 data.url.url = this.getValue();
\r
501 this.allowOnChange = false;
\r
505 setup : function( data )
\r
507 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
508 this.getElement().show();
\r
515 filebrowser : 'info:url',
\r
516 label : editor.lang.common.browseServer
\r
522 id : 'anchorOptions',
\r
530 id : 'selectAnchorText',
\r
531 label : editor.lang.link.selectAnchor,
\r
532 setup : function( data )
\r
534 if ( data.anchors.length > 0 )
\r
535 this.getElement().show();
\r
537 this.getElement().hide();
\r
543 id : 'selectAnchor',
\r
550 label : editor.lang.link.anchorName,
\r
551 style : 'width: 100%;',
\r
556 setup : function( data )
\r
560 for ( var i = 0 ; i < data.anchors.length ; i++ )
\r
562 if ( data.anchors[i].name )
\r
563 this.add( data.anchors[i].name );
\r
567 this.setValue( data.anchor.name );
\r
569 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
570 if ( linkType && linkType.getValue() == 'email' )
\r
573 commit : function( data )
\r
575 if ( !data.anchor )
\r
578 data.anchor.name = this.getValue();
\r
585 label : editor.lang.link.anchorId,
\r
586 style : 'width: 100%;',
\r
591 setup : function( data )
\r
595 for ( var i = 0 ; i < data.anchors.length ; i++ )
\r
597 if ( data.anchors[i].id )
\r
598 this.add( data.anchors[i].id );
\r
602 this.setValue( data.anchor.id );
\r
604 commit : function( data )
\r
606 if ( !data.anchor )
\r
609 data.anchor.id = this.getValue();
\r
613 setup : function( data )
\r
615 if ( data.anchors.length > 0 )
\r
616 this.getElement().show();
\r
618 this.getElement().hide();
\r
626 style : 'text-align: center;',
\r
627 html : '<div role="label" tabIndex="-1">' + CKEDITOR.tools.htmlEncode( editor.lang.link.noAnchors ) + '</div>',
\r
628 // Focus the first element defined in above html.
\r
630 setup : function( data )
\r
632 if ( data.anchors.length < 1 )
\r
633 this.getElement().show();
\r
635 this.getElement().hide();
\r
639 setup : function( data )
\r
641 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
642 this.getElement().hide();
\r
647 id : 'emailOptions',
\r
653 id : 'emailAddress',
\r
654 label : editor.lang.link.emailAddress,
\r
656 validate : function()
\r
658 var dialog = this.getDialog();
\r
660 if ( !dialog.getContentElement( 'info', 'linkType' ) ||
\r
661 dialog.getValueOf( 'info', 'linkType' ) != 'email' )
\r
664 var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noEmail );
\r
665 return func.apply( this );
\r
667 setup : function( data )
\r
670 this.setValue( data.email.address );
\r
672 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
673 if ( linkType && linkType.getValue() == 'email' )
\r
676 commit : function( data )
\r
681 data.email.address = this.getValue();
\r
686 id : 'emailSubject',
\r
687 label : editor.lang.link.emailSubject,
\r
688 setup : function( data )
\r
691 this.setValue( data.email.subject );
\r
693 commit : function( data )
\r
698 data.email.subject = this.getValue();
\r
704 label : editor.lang.link.emailBody,
\r
707 setup : function( data )
\r
710 this.setValue( data.email.body );
\r
712 commit : function( data )
\r
717 data.email.body = this.getValue();
\r
721 setup : function( data )
\r
723 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
724 this.getElement().hide();
\r
731 label : editor.lang.link.target,
\r
732 title : editor.lang.link.target,
\r
737 widths : [ '50%', '50%' ],
\r
742 id : 'linkTargetType',
\r
743 label : editor.lang.common.target,
\r
744 'default' : 'notSet',
\r
745 style : 'width : 100%;',
\r
748 [ editor.lang.common.notSet, 'notSet' ],
\r
749 [ editor.lang.link.targetFrame, 'frame' ],
\r
750 [ editor.lang.link.targetPopup, 'popup' ],
\r
751 [ editor.lang.common.targetNew, '_blank' ],
\r
752 [ editor.lang.common.targetTop, '_top' ],
\r
753 [ editor.lang.common.targetSelf, '_self' ],
\r
754 [ editor.lang.common.targetParent, '_parent' ]
\r
756 onChange : targetChanged,
\r
757 setup : function( data )
\r
760 this.setValue( data.target.type );
\r
762 commit : function( data )
\r
764 if ( !data.target )
\r
767 data.target.type = this.getValue();
\r
772 id : 'linkTargetName',
\r
773 label : editor.lang.link.targetFrameName,
\r
775 setup : function( data )
\r
778 this.setValue( data.target.name );
\r
780 commit : function( data )
\r
782 if ( !data.target )
\r
785 data.target.name = this.getValue().replace(/\W/gi, '');
\r
795 id : 'popupFeatures',
\r
800 label : editor.lang.link.popupFeatures,
\r
810 label : editor.lang.link.popupResizable,
\r
811 setup : setupPopupParams,
\r
812 commit : commitPopupParams
\r
817 label : editor.lang.link.popupStatusBar,
\r
818 setup : setupPopupParams,
\r
819 commit : commitPopupParams
\r
831 label : editor.lang.link.popupLocationBar,
\r
832 setup : setupPopupParams,
\r
833 commit : commitPopupParams
\r
839 label : editor.lang.link.popupToolbar,
\r
840 setup : setupPopupParams,
\r
841 commit : commitPopupParams
\r
853 label : editor.lang.link.popupMenuBar,
\r
854 setup : setupPopupParams,
\r
855 commit : commitPopupParams
\r
861 label : editor.lang.link.popupFullScreen,
\r
862 setup : setupPopupParams,
\r
863 commit : commitPopupParams
\r
875 label : editor.lang.link.popupScrollBars,
\r
876 setup : setupPopupParams,
\r
877 commit : commitPopupParams
\r
883 label : editor.lang.link.popupDependent,
\r
884 setup : setupPopupParams,
\r
885 commit : commitPopupParams
\r
896 widths : [ '30%', '70%' ],
\r
897 labelLayout : 'horizontal',
\r
898 label : editor.lang.link.popupWidth,
\r
900 setup : setupPopupParams,
\r
901 commit : commitPopupParams
\r
906 labelLayout : 'horizontal',
\r
907 widths : [ '55%', '45%' ],
\r
908 label : editor.lang.link.popupLeft,
\r
910 setup : setupPopupParams,
\r
911 commit : commitPopupParams
\r
922 labelLayout : 'horizontal',
\r
923 widths : [ '30%', '70%' ],
\r
924 label : editor.lang.link.popupHeight,
\r
926 setup : setupPopupParams,
\r
927 commit : commitPopupParams
\r
932 labelLayout : 'horizontal',
\r
933 label : editor.lang.link.popupTop,
\r
934 widths : [ '55%', '45%' ],
\r
936 setup : setupPopupParams,
\r
937 commit : commitPopupParams
\r
950 label : editor.lang.link.upload,
\r
951 title : editor.lang.link.upload,
\r
953 filebrowser : 'uploadButton',
\r
959 label : editor.lang.common.upload,
\r
960 style: 'height:40px',
\r
964 type : 'fileButton',
\r
965 id : 'uploadButton',
\r
966 label : editor.lang.common.uploadSubmit,
\r
967 filebrowser : 'info:url',
\r
968 'for' : [ 'upload', 'upload' ]
\r
974 label : editor.lang.link.advanced,
\r
975 title : editor.lang.link.advanced,
\r
985 widths : [ '45%', '35%', '20%' ],
\r
991 label : editor.lang.link.id,
\r
992 setup : setupAdvParams,
\r
993 commit : commitAdvParams
\r
998 label : editor.lang.link.langDir,
\r
1000 style : 'width:110px',
\r
1003 [ editor.lang.common.notSet, '' ],
\r
1004 [ editor.lang.link.langDirLTR, 'ltr' ],
\r
1005 [ editor.lang.link.langDirRTL, 'rtl' ]
\r
1007 setup : setupAdvParams,
\r
1008 commit : commitAdvParams
\r
1012 id : 'advAccessKey',
\r
1014 label : editor.lang.link.acccessKey,
\r
1016 setup : setupAdvParams,
\r
1017 commit : commitAdvParams
\r
1024 widths : [ '45%', '35%', '20%' ],
\r
1029 label : editor.lang.link.name,
\r
1031 setup : setupAdvParams,
\r
1032 commit : commitAdvParams
\r
1037 label : editor.lang.link.langCode,
\r
1038 id : 'advLangCode',
\r
1041 setup : setupAdvParams,
\r
1042 commit : commitAdvParams
\r
1047 label : editor.lang.link.tabIndex,
\r
1048 id : 'advTabIndex',
\r
1051 setup : setupAdvParams,
\r
1052 commit : commitAdvParams
\r
1066 widths : [ '45%', '55%' ],
\r
1071 label : editor.lang.link.advisoryTitle,
\r
1074 setup : setupAdvParams,
\r
1075 commit : commitAdvParams
\r
1080 label : editor.lang.link.advisoryContentType,
\r
1082 id : 'advContentType',
\r
1083 setup : setupAdvParams,
\r
1084 commit : commitAdvParams
\r
1091 widths : [ '45%', '55%' ],
\r
1096 label : editor.lang.link.cssClasses,
\r
1098 id : 'advCSSClasses',
\r
1099 setup : setupAdvParams,
\r
1100 commit : commitAdvParams
\r
1105 label : editor.lang.link.charset,
\r
1107 id : 'advCharset',
\r
1108 setup : setupAdvParams,
\r
1109 commit : commitAdvParams
\r
1120 label : editor.lang.link.styles,
\r
1123 setup : setupAdvParams,
\r
1124 commit : commitAdvParams
\r
1134 onShow : function()
\r
1136 this.fakeObj = false;
\r
1138 var editor = this.getParentEditor(),
\r
1139 selection = editor.getSelection(),
\r
1142 // Fill in all the relevant fields if there's already one link selected.
\r
1143 if ( ( element = plugin.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) )
\r
1144 selection.selectElement( element );
\r
1145 else if ( ( element = selection.getSelectedElement() ) && element.is( 'img' )
\r
1146 && element.getAttribute( '_cke_real_element_type' )
\r
1147 && element.getAttribute( '_cke_real_element_type' ) == 'anchor' )
\r
1149 this.fakeObj = element;
\r
1150 element = editor.restoreRealElement( this.fakeObj );
\r
1151 selection.selectElement( this.fakeObj );
\r
1156 this.setupContent( parseLink.apply( this, [ editor, element ] ) );
\r
1160 var attributes = { href : 'javascript:void(0)/*' + CKEDITOR.tools.getNextNumber() + '*/' },
\r
1161 removeAttributes = [],
\r
1162 data = { href : attributes.href },
\r
1164 editor = this.getParentEditor();
\r
1166 this.commitContent( data );
\r
1168 // Compose the URL.
\r
1169 switch ( data.type || 'url' )
\r
1172 var protocol = ( data.url && data.url.protocol != undefined ) ? data.url.protocol : 'http://',
\r
1173 url = ( data.url && data.url.url ) || '';
\r
1174 attributes._cke_saved_href = ( url.indexOf( '/' ) === 0 ) ? url : protocol + url;
\r
1177 var name = ( data.anchor && data.anchor.name ),
\r
1178 id = ( data.anchor && data.anchor.id );
\r
1179 attributes._cke_saved_href = '#' + ( name || id || '' );
\r
1184 email = data.email,
\r
1185 address = email.address;
\r
1187 switch( emailProtection )
\r
1192 var subject = encodeURIComponent( email.subject || '' ),
\r
1193 body = encodeURIComponent( email.body || '' );
\r
1195 // Build the e-mail parameters first.
\r
1197 subject && argList.push( 'subject=' + subject );
\r
1198 body && argList.push( 'body=' + body );
\r
1199 argList = argList.length ? '?' + argList.join( '&' ) : '';
\r
1201 if ( emailProtection == 'encode' )
\r
1203 linkHref = [ 'javascript:void(location.href=\'mailto:\'+',
\r
1204 protectEmailAddressAsEncodedString( address ) ];
\r
1205 // parameters are optional.
\r
1206 argList && linkHref.push( '+\'', escapeSingleQuote( argList ), '\'' );
\r
1208 linkHref.push( ')' );
\r
1211 linkHref = [ 'mailto:', address, argList ];
\r
1217 // Separating name and domain.
\r
1218 var nameAndDomain = address.split( '@', 2 );
\r
1219 email.name = nameAndDomain[ 0 ];
\r
1220 email.domain = nameAndDomain[ 1 ];
\r
1222 linkHref = [ 'javascript:', protectEmailLinkAsFunction( email ) ];
\r
1226 attributes._cke_saved_href = linkHref.join( '' );
\r
1230 // Popups and target.
\r
1231 if ( data.target )
\r
1233 if ( data.target.type == 'popup' )
\r
1235 var onclickList = [ 'window.open(this.href, \'',
\r
1236 data.target.name || '', '\', \'' ];
\r
1237 var featureList = [ 'resizable', 'status', 'location', 'toolbar', 'menubar', 'fullscreen',
\r
1238 'scrollbars', 'dependent' ];
\r
1239 var featureLength = featureList.length;
\r
1240 var addFeature = function( featureName )
\r
1242 if ( data.target[ featureName ] )
\r
1243 featureList.push( featureName + '=' + data.target[ featureName ] );
\r
1246 for ( var i = 0 ; i < featureLength ; i++ )
\r
1247 featureList[i] = featureList[i] + ( data.target[ featureList[i] ] ? '=yes' : '=no' ) ;
\r
1248 addFeature( 'width' );
\r
1249 addFeature( 'left' );
\r
1250 addFeature( 'height' );
\r
1251 addFeature( 'top' );
\r
1253 onclickList.push( featureList.join( ',' ), '\'); return false;' );
\r
1254 attributes[ '_cke_pa_onclick' ] = onclickList.join( '' );
\r
1258 if ( data.target.type != 'notSet' && data.target.name )
\r
1259 attributes.target = data.target.name;
\r
1261 removeAttributes.push( 'target' );
\r
1263 removeAttributes.push( '_cke_pa_onclick', 'onclick' );
\r
1267 // Advanced attributes.
\r
1270 var advAttr = function( inputName, attrName )
\r
1272 var value = data.adv[ inputName ];
\r
1274 attributes[attrName] = value;
\r
1276 removeAttributes.push( attrName );
\r
1279 if ( this._.selectedElement )
\r
1280 advAttr( 'advId', 'id' );
\r
1281 advAttr( 'advLangDir', 'dir' );
\r
1282 advAttr( 'advAccessKey', 'accessKey' );
\r
1283 advAttr( 'advName', 'name' );
\r
1284 advAttr( 'advLangCode', 'lang' );
\r
1285 advAttr( 'advTabIndex', 'tabindex' );
\r
1286 advAttr( 'advTitle', 'title' );
\r
1287 advAttr( 'advContentType', 'type' );
\r
1288 advAttr( 'advCSSClasses', 'class' );
\r
1289 advAttr( 'advCharset', 'charset' );
\r
1290 advAttr( 'advStyles', 'style' );
\r
1293 if ( !this._.selectedElement )
\r
1295 // Create element if current selection is collapsed.
\r
1296 var selection = editor.getSelection(),
\r
1297 ranges = selection.getRanges();
\r
1298 if ( ranges.length == 1 && ranges[0].collapsed )
\r
1300 var text = new CKEDITOR.dom.text( attributes._cke_saved_href, editor.document );
\r
1301 ranges[0].insertNode( text );
\r
1302 ranges[0].selectNodeContents( text );
\r
1303 selection.selectRanges( ranges );
\r
1307 var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
\r
1308 style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why.
\r
1309 style.apply( editor.document );
\r
1311 // Id. Apply only to the first link.
\r
1312 if ( data.adv && data.adv.advId )
\r
1314 var links = this.getParentEditor().document.$.getElementsByTagName( 'a' );
\r
1315 for ( i = 0 ; i < links.length ; i++ )
\r
1317 if ( links[i].href == attributes.href )
\r
1319 links[i].id = data.adv.advId;
\r
1327 // We're only editing an existing link, so just overwrite the attributes.
\r
1328 var element = this._.selectedElement,
\r
1329 href = element.getAttribute( '_cke_saved_href' ),
\r
1330 textView = element.getHtml();
\r
1332 // IE BUG: Setting the name attribute to an existing link doesn't work.
\r
1333 // Must re-create the link from weired syntax to workaround.
\r
1334 if ( CKEDITOR.env.ie && attributes.name != element.getAttribute( 'name' ) )
\r
1336 var newElement = new CKEDITOR.dom.element( '<a name="' + CKEDITOR.tools.htmlEncode( attributes.name ) + '">',
\r
1337 editor.document );
\r
1339 selection = editor.getSelection();
\r
1341 element.moveChildren( newElement );
\r
1342 element.copyAttributes( newElement, { name : 1 } );
\r
1343 newElement.replace( element );
\r
1344 element = newElement;
\r
1346 selection.selectElement( element );
\r
1349 element.setAttributes( attributes );
\r
1350 element.removeAttributes( removeAttributes );
\r
1351 // Update text view when user changes protocol #4612.
\r
1352 if (href == textView)
\r
1353 element.setHtml( attributes._cke_saved_href );
\r
1354 // Make the element display as an anchor if a name has been set.
\r
1355 if ( element.getAttribute( 'name' ) )
\r
1356 element.addClass( 'cke_anchor' );
\r
1358 element.removeClass( 'cke_anchor' );
\r
1360 if ( this.fakeObj )
\r
1361 editor.createFakeElement( element, 'cke_anchor', 'anchor' ).replace( this.fakeObj );
\r
1363 delete this._.selectedElement;
\r
1366 onLoad : function()
\r
1368 if ( !editor.config.linkShowAdvancedTab )
\r
1369 this.hidePage( 'advanced' ); //Hide Advanded tab.
\r
1371 if ( !editor.config.linkShowTargetTab )
\r
1372 this.hidePage( 'target' ); //Hide Target tab.
\r
1375 // Inital focus on 'url' field if link is of type URL.
\r
1376 onFocus : function()
\r
1378 var linkType = this.getContentElement( 'info', 'linkType' ),
\r
1380 if ( linkType && linkType.getValue( ) == 'url' )
\r
1382 urlField = this.getContentElement( 'info', 'url' );
\r
1383 urlField.select();
\r
1390 * The e-mail address anti-spam protection option. The protection will be
\r
1391 * applied when creating or modifying e-mail links through the editor interface.<br>
\r
1392 * Two methods of protection can be choosed:
\r
1393 * <ol> <li>The e-mail parts (name, domain and any other query string) are
\r
1394 * assembled into a function call pattern. Such function must be
\r
1395 * provided by the developer in the pages that will use the contents.
\r
1396 * <li>Only the e-mail address is obfuscated into a special string that
\r
1397 * has no meaning for humans or spam bots, but which is properly
\r
1398 * rendered and accepted by the browser.</li></ol>
\r
1399 * Both approaches require JavaScript to be enabled.
\r
1400 * @name CKEDITOR.config.emailProtection
\r
1403 * @default '' (empty string = disabled)
\r
1405 * // href="mailto:tester@ckeditor.com?subject=subject&body=body"
\r
1406 * config.emailProtection = '';
\r
1408 * // 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
1409 * config.emailProtection = 'encode';
\r
1411 * // href="javascript:mt('tester','ckeditor.com','subject','body')"
\r
1412 * config.emailProtection = 'mt(NAME,DOMAIN,SUBJECT,BODY)';
\r