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
21 if ( value == 'popup' )
\r
23 popupFeatures.show();
\r
24 targetName.setLabel( editor.lang.link.targetPopupName );
\r
28 popupFeatures.hide();
\r
29 targetName.setLabel( editor.lang.link.targetFrameName );
\r
30 this.getDialog().setValueOf( 'target', 'linkTargetName', value.charAt( 0 ) == '_' ? value : '' );
\r
34 // Handles the event when the "Type" selection box is changed.
\r
35 var linkTypeChanged = function()
\r
37 var dialog = this.getDialog(),
\r
38 partIds = [ 'urlOptions', 'anchorOptions', 'emailOptions' ],
\r
39 typeValue = this.getValue(),
\r
40 uploadTab = dialog.definition.getContents( 'upload' ),
\r
41 uploadInitiallyHidden = uploadTab && uploadTab.hidden;
\r
43 if ( typeValue == 'url' )
\r
45 if ( editor.config.linkShowTargetTab )
\r
46 dialog.showPage( 'target' );
\r
47 if ( !uploadInitiallyHidden )
\r
48 dialog.showPage( 'upload' );
\r
52 dialog.hidePage( 'target' );
\r
53 if ( !uploadInitiallyHidden )
\r
54 dialog.hidePage( 'upload' );
\r
57 for ( var i = 0 ; i < partIds.length ; i++ )
\r
59 var element = dialog.getContentElement( 'info', partIds[i] );
\r
63 element = element.getElement().getParent().getParent();
\r
64 if ( partIds[i] == typeValue + 'Options' )
\r
71 // Loads the parameters in a selected link to the link dialog fields.
\r
72 var emailRegex = /^mailto:([^?]+)(?:\?(.+))?$/,
\r
73 emailSubjectRegex = /subject=([^;?:@&=$,\/]*)/,
\r
74 emailBodyRegex = /body=([^;?:@&=$,\/]*)/,
\r
75 anchorRegex = /^#(.*)$/,
\r
76 urlRegex = /^(?!javascript)((?:http|https|ftp|news):\/\/)?(.*)$/,
\r
77 selectableTargets = /^(_(?:self|top|parent|blank))$/,
\r
78 encodedEmailLinkRegex = /^javascript:void\(location\.href='mailto:'\+String\.fromCharCode\(([^)]+)\)(?:\+'(.*)')?\)$/,
\r
79 functionCallProtectedEmailLinkRegex = /^javascript:([^(]+)\(([^)]+)\)$/;
\r
82 /\s*window.open\(\s*this\.href\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*/;
\r
83 var popupFeaturesRegex = /(?:^|,)([^=]+)=(\d+|yes|no)/gi;
\r
85 var parseLink = function( editor, element )
\r
87 var href = element ? ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) : '',
\r
93 if ( ( anchorMatch = href.match( anchorRegex ) ) )
\r
95 retval.type = 'anchor';
\r
97 retval.anchor.name = retval.anchor.id = anchorMatch[1];
\r
99 // urlRegex matches empty strings, so need to check for href as well.
\r
100 else if ( href && ( urlMatch = href.match( urlRegex ) ) )
\r
102 retval.type = 'url';
\r
104 retval.url.protocol = urlMatch[1];
\r
105 retval.url.url = urlMatch[2];
\r
107 // Protected email link as encoded string.
\r
108 else if ( !emailProtection || emailProtection == 'encode' )
\r
110 if( emailProtection == 'encode' )
\r
112 href = href.replace( encodedEmailLinkRegex,
\r
113 function ( match, protectedAddress, rest )
\r
116 String.fromCharCode.apply( String, protectedAddress.split( ',' ) ) +
\r
117 ( rest && unescapeSingleQuote( rest ) );
\r
121 emailMatch = href.match( emailRegex );
\r
125 var subjectMatch = href.match( emailSubjectRegex ),
\r
126 bodyMatch = href.match( emailBodyRegex );
\r
128 retval.type = 'email';
\r
129 var email = ( retval.email = {} );
\r
130 email.address = emailMatch[ 1 ];
\r
131 subjectMatch && ( email.subject = decodeURIComponent( subjectMatch[ 1 ] ) );
\r
132 bodyMatch && ( email.body = decodeURIComponent( bodyMatch[ 1 ] ) );
\r
135 // Protected email link as function call.
\r
136 else if( emailProtection )
\r
138 href.replace( functionCallProtectedEmailLinkRegex, function( match, funcName, funcArgs )
\r
140 if( funcName == compiledProtectionFunction.name )
\r
142 retval.type = 'email';
\r
143 var email = retval.email = {};
\r
145 var paramRegex = /[^,\s]+/g,
\r
146 paramQuoteRegex = /(^')|('$)/g,
\r
147 paramsMatch = funcArgs.match( paramRegex ),
\r
148 paramsMatchLength = paramsMatch.length,
\r
152 for ( var i = 0; i < paramsMatchLength; i++ )
\r
154 paramVal = decodeURIComponent( unescapeSingleQuote( paramsMatch[ i ].replace( paramQuoteRegex, '' ) ) );
\r
155 paramName = compiledProtectionFunction.params[ i ].toLowerCase();
\r
156 email[ paramName ] = paramVal;
\r
158 email.address = [ email.name, email.domain ].join( '@' );
\r
163 retval.type = 'url';
\r
165 // Load target and popup settings.
\r
168 var target = element.getAttribute( 'target' );
\r
169 retval.target = {};
\r
172 // IE BUG: target attribute is an empty string instead of null in IE if it's not set.
\r
175 var onclick = element.getAttribute( '_cke_pa_onclick' ) || element.getAttribute( 'onclick' ),
\r
176 onclickMatch = onclick && onclick.match( popupRegex );
\r
177 if ( onclickMatch )
\r
179 retval.target.type = 'popup';
\r
180 retval.target.name = onclickMatch[1];
\r
183 while ( ( featureMatch = popupFeaturesRegex.exec( onclickMatch[2] ) ) )
\r
185 if ( featureMatch[2] == 'yes' || featureMatch[2] == '1' )
\r
186 retval.target[ featureMatch[1] ] = true;
\r
187 else if ( isFinite( featureMatch[2] ) )
\r
188 retval.target[ featureMatch[1] ] = featureMatch[2];
\r
194 var targetMatch = target.match( selectableTargets );
\r
196 retval.target.type = retval.target.name = target;
\r
199 retval.target.type = 'frame';
\r
200 retval.target.name = target;
\r
205 var advAttr = function( inputName, attrName )
\r
207 var value = element.getAttribute( attrName );
\r
208 if ( value !== null )
\r
209 retval.adv[ inputName ] = value || '';
\r
211 advAttr( 'advId', 'id' );
\r
212 advAttr( 'advLangDir', 'dir' );
\r
213 advAttr( 'advAccessKey', 'accessKey' );
\r
214 advAttr( 'advName', 'name' );
\r
215 advAttr( 'advLangCode', 'lang' );
\r
216 advAttr( 'advTabIndex', 'tabindex' );
\r
217 advAttr( 'advTitle', 'title' );
\r
218 advAttr( 'advContentType', 'type' );
\r
219 advAttr( 'advCSSClasses', 'class' );
\r
220 advAttr( 'advCharset', 'charset' );
\r
221 advAttr( 'advStyles', 'style' );
\r
224 // Find out whether we have any anchors in the editor.
\r
225 // Get all IMG elements in CK document.
\r
226 var elements = editor.document.getElementsByTag( 'img' ),
\r
227 realAnchors = new CKEDITOR.dom.nodeList( editor.document.$.anchors ),
\r
228 anchors = retval.anchors = [];
\r
230 for( var i = 0; i < elements.count() ; i++ )
\r
232 var item = elements.getItem( i );
\r
233 if ( item.getAttribute( '_cke_realelement' ) && item.getAttribute( '_cke_real_element_type' ) == 'anchor' )
\r
235 anchors.push( editor.restoreRealElement( item ) );
\r
239 for ( i = 0 ; i < realAnchors.count() ; i++ )
\r
240 anchors.push( realAnchors.getItem( i ) );
\r
242 for ( i = 0 ; i < anchors.length ; i++ )
\r
244 item = anchors[ i ];
\r
245 anchors[ i ] = { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) };
\r
248 // Record down the selected element in the dialog.
\r
249 this._.selectedElement = element;
\r
254 var setupParams = function( page, data )
\r
257 this.setValue( data[page][this.id] || '' );
\r
260 var setupPopupParams = function( data )
\r
262 return setupParams.call( this, 'target', data );
\r
265 var setupAdvParams = function( data )
\r
267 return setupParams.call( this, 'adv', data );
\r
270 var commitParams = function( page, data )
\r
275 data[page][this.id] = this.getValue() || '';
\r
278 var commitPopupParams = function( data )
\r
280 return commitParams.call( this, 'target', data );
\r
283 var commitAdvParams = function( data )
\r
285 return commitParams.call( this, 'adv', data );
\r
288 function unescapeSingleQuote( str )
\r
290 return str.replace( /\\'/g, '\'' );
\r
293 function escapeSingleQuote( str )
\r
295 return str.replace( /'/g, '\\$&' );
\r
298 var emailProtection = editor.config.emailProtection || '';
\r
300 // Compile the protection function pattern.
\r
301 if( emailProtection && emailProtection != 'encode' )
\r
303 var compiledProtectionFunction = {};
\r
305 emailProtection.replace( /^([^(]+)\(([^)]+)\)$/, function( match, funcName, params )
\r
307 compiledProtectionFunction.name = funcName;
\r
308 compiledProtectionFunction.params = [];
\r
309 params.replace( /[^,\s]+/g, function( param )
\r
311 compiledProtectionFunction.params.push( param );
\r
316 function protectEmailLinkAsFunction( email )
\r
319 name = compiledProtectionFunction.name,
\r
320 params = compiledProtectionFunction.params,
\r
324 retval = [ name, '(' ];
\r
325 for ( var i = 0; i < params.length; i++ )
\r
327 paramName = params[ i ].toLowerCase();
\r
328 paramValue = email[ paramName ];
\r
330 i > 0 && retval.push( ',' );
\r
333 escapeSingleQuote( encodeURIComponent( email[ paramName ] ) )
\r
337 retval.push( ')' );
\r
338 return retval.join( '' );
\r
341 function protectEmailAddressAsEncodedString( address )
\r
344 length = address.length,
\r
346 for ( var i = 0; i < length; i++ )
\r
348 charCode = address.charCodeAt( i );
\r
349 encodedChars.push( charCode );
\r
351 return 'String.fromCharCode(' + encodedChars.join( ',' ) + ')';
\r
355 title : editor.lang.link.title,
\r
361 label : editor.lang.link.info,
\r
362 title : editor.lang.link.info,
\r
368 label : editor.lang.link.type,
\r
372 [ editor.lang.common.url, 'url' ],
\r
373 [ editor.lang.link.toAnchor, 'anchor' ],
\r
374 [ editor.lang.link.toEmail, 'email' ]
\r
376 onChange : linkTypeChanged,
\r
377 setup : function( data )
\r
380 this.setValue( data.type );
\r
382 commit : function( data )
\r
384 data.type = this.getValue();
\r
394 widths : [ '25%', '75%' ],
\r
400 label : editor.lang.common.protocol,
\r
401 'default' : 'http://',
\r
402 style : 'width : 100%;',
\r
411 setup : function( data )
\r
414 this.setValue( data.url.protocol || '' );
\r
416 commit : function( data )
\r
421 data.url.protocol = this.getValue();
\r
427 label : editor.lang.common.url,
\r
428 onLoad : function ()
\r
430 this.allowOnChange = true;
\r
432 onKeyUp : function()
\r
434 this.allowOnChange = false;
\r
435 var protocolCmb = this.getDialog().getContentElement( 'info', 'protocol' ),
\r
436 url = this.getValue(),
\r
437 urlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/gi,
\r
438 urlOnChangeTestOther = /^((javascript:)|[#\/\.])/gi;
\r
440 var protocol = urlOnChangeProtocol.exec( url );
\r
443 this.setValue( url.substr( protocol[ 0 ].length ) );
\r
444 protocolCmb.setValue( protocol[ 0 ].toLowerCase() );
\r
446 else if ( urlOnChangeTestOther.test( url ) )
\r
447 protocolCmb.setValue( '' );
\r
449 this.allowOnChange = true;
\r
451 onChange : function()
\r
453 if ( this.allowOnChange ) // Dont't call on dialog load.
\r
456 validate : function()
\r
458 var dialog = this.getDialog();
\r
460 if ( dialog.getContentElement( 'info', 'linkType' ) &&
\r
461 dialog.getValueOf( 'info', 'linkType' ) != 'url' )
\r
464 if ( this.getDialog().fakeObj ) // Edit Anchor.
\r
467 var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noUrl );
\r
468 return func.apply( this );
\r
470 setup : function( data )
\r
472 this.allowOnChange = false;
\r
474 this.setValue( data.url.url );
\r
475 this.allowOnChange = true;
\r
477 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
478 if ( linkType && linkType.getValue() == 'url' )
\r
482 commit : function( data )
\r
487 data.url.url = this.getValue();
\r
488 this.allowOnChange = false;
\r
492 setup : function( data )
\r
494 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
495 this.getElement().show();
\r
502 filebrowser : 'info:url',
\r
503 label : editor.lang.common.browseServer
\r
509 id : 'anchorOptions',
\r
517 id : 'selectAnchorText',
\r
518 html : CKEDITOR.tools.htmlEncode( editor.lang.link.selectAnchor ),
\r
519 setup : function( data )
\r
521 if ( data.anchors.length > 0 )
\r
522 this.getElement().show();
\r
524 this.getElement().hide();
\r
530 style : 'text-align: center;',
\r
531 html : '<div>' + CKEDITOR.tools.htmlEncode( editor.lang.link.noAnchors ) + '</div>',
\r
532 setup : function( data )
\r
534 if ( data.anchors.length < 1 )
\r
535 this.getElement().show();
\r
537 this.getElement().hide();
\r
542 id : 'selectAnchor',
\r
549 label : editor.lang.link.anchorName,
\r
550 style : 'width: 100%;',
\r
555 setup : function( data )
\r
559 for ( var i = 0 ; i < data.anchors.length ; i++ )
\r
561 if ( data.anchors[i].name )
\r
562 this.add( data.anchors[i].name );
\r
566 this.setValue( data.anchor.name );
\r
568 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
569 if ( linkType && linkType.getValue() == 'email' )
\r
572 commit : function( data )
\r
574 if ( !data.anchor )
\r
577 data.anchor.name = this.getValue();
\r
584 label : editor.lang.link.anchorId,
\r
585 style : 'width: 100%;',
\r
590 setup : function( data )
\r
594 for ( var i = 0 ; i < data.anchors.length ; i++ )
\r
596 if ( data.anchors[i].id )
\r
597 this.add( data.anchors[i].id );
\r
601 this.setValue( data.anchor.id );
\r
603 commit : function( data )
\r
605 if ( !data.anchor )
\r
608 data.anchor.id = this.getValue();
\r
612 setup : function( data )
\r
614 if ( data.anchors.length > 0 )
\r
615 this.getElement().show();
\r
617 this.getElement().hide();
\r
621 setup : function( data )
\r
623 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
624 this.getElement().hide();
\r
629 id : 'emailOptions',
\r
635 id : 'emailAddress',
\r
636 label : editor.lang.link.emailAddress,
\r
637 validate : function()
\r
639 var dialog = this.getDialog();
\r
641 if ( !dialog.getContentElement( 'info', 'linkType' ) ||
\r
642 dialog.getValueOf( 'info', 'linkType' ) != 'email' )
\r
645 var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noEmail );
\r
646 return func.apply( this );
\r
648 setup : function( data )
\r
651 this.setValue( data.email.address );
\r
653 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
654 if ( linkType && linkType.getValue() == 'email' )
\r
657 commit : function( data )
\r
662 data.email.address = this.getValue();
\r
667 id : 'emailSubject',
\r
668 label : editor.lang.link.emailSubject,
\r
669 setup : function( data )
\r
672 this.setValue( data.email.subject );
\r
674 commit : function( data )
\r
679 data.email.subject = this.getValue();
\r
685 label : editor.lang.link.emailBody,
\r
688 setup : function( data )
\r
691 this.setValue( data.email.body );
\r
693 commit : function( data )
\r
698 data.email.body = this.getValue();
\r
702 setup : function( data )
\r
704 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
705 this.getElement().hide();
\r
712 label : editor.lang.link.target,
\r
713 title : editor.lang.link.target,
\r
718 widths : [ '50%', '50%' ],
\r
723 id : 'linkTargetType',
\r
724 label : editor.lang.link.target,
\r
725 'default' : 'notSet',
\r
726 style : 'width : 100%;',
\r
729 [ editor.lang.link.targetNotSet, 'notSet' ],
\r
730 [ editor.lang.link.targetFrame, 'frame' ],
\r
731 [ editor.lang.link.targetPopup, 'popup' ],
\r
732 [ editor.lang.link.targetNew, '_blank' ],
\r
733 [ editor.lang.link.targetTop, '_top' ],
\r
734 [ editor.lang.link.targetSelf, '_self' ],
\r
735 [ editor.lang.link.targetParent, '_parent' ]
\r
737 onChange : targetChanged,
\r
738 setup : function( data )
\r
741 this.setValue( data.target.type );
\r
743 commit : function( data )
\r
745 if ( !data.target )
\r
748 data.target.type = this.getValue();
\r
753 id : 'linkTargetName',
\r
754 label : editor.lang.link.targetFrameName,
\r
756 setup : function( data )
\r
759 this.setValue( data.target.name );
\r
761 commit : function( data )
\r
763 if ( !data.target )
\r
766 data.target.name = this.getValue();
\r
776 id : 'popupFeatures',
\r
781 html : CKEDITOR.tools.htmlEncode( editor.lang.link.popupFeatures )
\r
790 label : editor.lang.link.popupResizable,
\r
791 setup : setupPopupParams,
\r
792 commit : commitPopupParams
\r
797 label : editor.lang.link.popupStatusBar,
\r
798 setup : setupPopupParams,
\r
799 commit : commitPopupParams
\r
811 label : editor.lang.link.popupLocationBar,
\r
812 setup : setupPopupParams,
\r
813 commit : commitPopupParams
\r
819 label : editor.lang.link.popupToolbar,
\r
820 setup : setupPopupParams,
\r
821 commit : commitPopupParams
\r
833 label : editor.lang.link.popupMenuBar,
\r
834 setup : setupPopupParams,
\r
835 commit : commitPopupParams
\r
841 label : editor.lang.link.popupFullScreen,
\r
842 setup : setupPopupParams,
\r
843 commit : commitPopupParams
\r
855 label : editor.lang.link.popupScrollBars,
\r
856 setup : setupPopupParams,
\r
857 commit : commitPopupParams
\r
863 label : editor.lang.link.popupDependent,
\r
864 setup : setupPopupParams,
\r
865 commit : commitPopupParams
\r
876 widths : [ '30%', '70%' ],
\r
877 labelLayout : 'horizontal',
\r
878 label : editor.lang.link.popupWidth,
\r
880 setup : setupPopupParams,
\r
881 commit : commitPopupParams
\r
886 labelLayout : 'horizontal',
\r
887 widths : [ '55%', '45%' ],
\r
888 label : editor.lang.link.popupLeft,
\r
890 setup : setupPopupParams,
\r
891 commit : commitPopupParams
\r
902 labelLayout : 'horizontal',
\r
903 widths : [ '30%', '70%' ],
\r
904 label : editor.lang.link.popupHeight,
\r
906 setup : setupPopupParams,
\r
907 commit : commitPopupParams
\r
912 labelLayout : 'horizontal',
\r
913 label : editor.lang.link.popupTop,
\r
914 widths : [ '55%', '45%' ],
\r
916 setup : setupPopupParams,
\r
917 commit : commitPopupParams
\r
928 label : editor.lang.link.upload,
\r
929 title : editor.lang.link.upload,
\r
931 filebrowser : 'uploadButton',
\r
937 label : editor.lang.common.upload,
\r
938 style: 'height:40px',
\r
942 type : 'fileButton',
\r
943 id : 'uploadButton',
\r
944 label : editor.lang.common.uploadSubmit,
\r
945 filebrowser : 'info:url',
\r
946 'for' : [ 'upload', 'upload' ]
\r
952 label : editor.lang.link.advanced,
\r
953 title : editor.lang.link.advanced,
\r
963 widths : [ '45%', '35%', '20%' ],
\r
969 label : editor.lang.link.id,
\r
970 setup : setupAdvParams,
\r
971 commit : commitAdvParams
\r
976 label : editor.lang.link.langDir,
\r
978 style : 'width:110px',
\r
981 [ editor.lang.link.langDirNotSet, '' ],
\r
982 [ editor.lang.link.langDirLTR, 'ltr' ],
\r
983 [ editor.lang.link.langDirRTL, 'rtl' ]
\r
985 setup : setupAdvParams,
\r
986 commit : commitAdvParams
\r
990 id : 'advAccessKey',
\r
992 label : editor.lang.link.acccessKey,
\r
994 setup : setupAdvParams,
\r
995 commit : commitAdvParams
\r
1002 widths : [ '45%', '35%', '20%' ],
\r
1007 label : editor.lang.link.name,
\r
1009 setup : setupAdvParams,
\r
1010 commit : commitAdvParams
\r
1015 label : editor.lang.link.langCode,
\r
1016 id : 'advLangCode',
\r
1019 setup : setupAdvParams,
\r
1020 commit : commitAdvParams
\r
1025 label : editor.lang.link.tabIndex,
\r
1026 id : 'advTabIndex',
\r
1029 setup : setupAdvParams,
\r
1030 commit : commitAdvParams
\r
1044 widths : [ '45%', '55%' ],
\r
1049 label : editor.lang.link.advisoryTitle,
\r
1052 setup : setupAdvParams,
\r
1053 commit : commitAdvParams
\r
1058 label : editor.lang.link.advisoryContentType,
\r
1060 id : 'advContentType',
\r
1061 setup : setupAdvParams,
\r
1062 commit : commitAdvParams
\r
1069 widths : [ '45%', '55%' ],
\r
1074 label : editor.lang.link.cssClasses,
\r
1076 id : 'advCSSClasses',
\r
1077 setup : setupAdvParams,
\r
1078 commit : commitAdvParams
\r
1083 label : editor.lang.link.charset,
\r
1085 id : 'advCharset',
\r
1086 setup : setupAdvParams,
\r
1087 commit : commitAdvParams
\r
1098 label : editor.lang.link.styles,
\r
1101 setup : setupAdvParams,
\r
1102 commit : commitAdvParams
\r
1112 onShow : function()
\r
1114 this.fakeObj = false;
\r
1116 var editor = this.getParentEditor(),
\r
1117 selection = editor.getSelection(),
\r
1118 ranges = selection.getRanges(),
\r
1121 // Fill in all the relevant fields if there's already one link selected.
\r
1122 if ( ranges.length == 1 )
\r
1125 var rangeRoot = ranges[0].getCommonAncestor( true );
\r
1126 element = rangeRoot.getAscendant( 'a', true );
\r
1127 if ( element && element.getAttribute( 'href' ) )
\r
1129 selection.selectElement( element );
\r
1131 else if ( ( element = rangeRoot.getAscendant( 'img', true ) ) &&
\r
1132 element.getAttribute( '_cke_real_element_type' ) &&
\r
1133 element.getAttribute( '_cke_real_element_type' ) == 'anchor' )
\r
1135 this.fakeObj = element;
\r
1136 element = editor.restoreRealElement( this.fakeObj );
\r
1137 selection.selectElement( this.fakeObj );
\r
1143 this.setupContent( parseLink.apply( this, [ editor, element ] ) );
\r
1147 var attributes = { href : 'javascript:void(0)/*' + CKEDITOR.tools.getNextNumber() + '*/' },
\r
1148 removeAttributes = [],
\r
1149 data = { href : attributes.href },
\r
1151 editor = this.getParentEditor();
\r
1153 this.commitContent( data );
\r
1155 // Compose the URL.
\r
1156 switch ( data.type || 'url' )
\r
1159 var protocol = ( data.url && data.url.protocol != undefined ) ? data.url.protocol : 'http://',
\r
1160 url = ( data.url && data.url.url ) || '';
\r
1161 attributes._cke_saved_href = ( url.indexOf( '/' ) === 0 ) ? url : protocol + url;
\r
1164 var name = ( data.anchor && data.anchor.name ),
\r
1165 id = ( data.anchor && data.anchor.id );
\r
1166 attributes._cke_saved_href = '#' + ( name || id || '' );
\r
1171 email = data.email,
\r
1172 address = email.address;
\r
1174 switch( emailProtection )
\r
1179 var subject = encodeURIComponent( email.subject || '' ),
\r
1180 body = encodeURIComponent( email.body || '' );
\r
1182 // Build the e-mail parameters first.
\r
1184 subject && argList.push( 'subject=' + subject );
\r
1185 body && argList.push( 'body=' + body );
\r
1186 argList = argList.length ? '?' + argList.join( '&' ) : '';
\r
1188 if ( emailProtection == 'encode' )
\r
1190 linkHref = [ 'javascript:void(location.href=\'mailto:\'+',
\r
1191 protectEmailAddressAsEncodedString( address ) ];
\r
1192 // parameters are optional.
\r
1193 argList && linkHref.push( '+\'', escapeSingleQuote( argList ), '\'' );
\r
1195 linkHref.push( ')' );
\r
1198 linkHref = [ 'mailto:', address, argList ];
\r
1204 // Separating name and domain.
\r
1205 var nameAndDomain = address.split( '@', 2 );
\r
1206 email.name = nameAndDomain[ 0 ];
\r
1207 email.domain = nameAndDomain[ 1 ];
\r
1209 linkHref = [ 'javascript:', protectEmailLinkAsFunction( email ) ];
\r
1213 attributes._cke_saved_href = linkHref.join( '' );
\r
1217 // Popups and target.
\r
1218 if ( data.target )
\r
1220 if ( data.target.type == 'popup' )
\r
1222 var onclickList = [ 'window.open(this.href, \'',
\r
1223 data.target.name || '', '\', \'' ];
\r
1224 var featureList = [ 'resizable', 'status', 'location', 'toolbar', 'menubar', 'fullscreen',
\r
1225 'scrollbars', 'dependent' ];
\r
1226 var featureLength = featureList.length;
\r
1227 var addFeature = function( featureName )
\r
1229 if ( data.target[ featureName ] )
\r
1230 featureList.push( featureName + '=' + data.target[ featureName ] );
\r
1233 for ( var i = 0 ; i < featureLength ; i++ )
\r
1234 featureList[i] = featureList[i] + ( data.target[ featureList[i] ] ? '=yes' : '=no' ) ;
\r
1235 addFeature( 'width' );
\r
1236 addFeature( 'left' );
\r
1237 addFeature( 'height' );
\r
1238 addFeature( 'top' );
\r
1240 onclickList.push( featureList.join( ',' ), '\'); return false;' );
\r
1241 attributes[ '_cke_pa_onclick' ] = onclickList.join( '' );
\r
1245 if ( data.target.type != 'notSet' && data.target.name )
\r
1246 attributes.target = data.target.name;
\r
1248 removeAttributes.push( 'target' );
\r
1250 removeAttributes.push( '_cke_pa_onclick', 'onclick' );
\r
1254 // Advanced attributes.
\r
1257 var advAttr = function( inputName, attrName )
\r
1259 var value = data.adv[ inputName ];
\r
1261 attributes[attrName] = value;
\r
1263 removeAttributes.push( attrName );
\r
1266 if ( this._.selectedElement )
\r
1267 advAttr( 'advId', 'id' );
\r
1268 advAttr( 'advLangDir', 'dir' );
\r
1269 advAttr( 'advAccessKey', 'accessKey' );
\r
1270 advAttr( 'advName', 'name' );
\r
1271 advAttr( 'advLangCode', 'lang' );
\r
1272 advAttr( 'advTabIndex', 'tabindex' );
\r
1273 advAttr( 'advTitle', 'title' );
\r
1274 advAttr( 'advContentType', 'type' );
\r
1275 advAttr( 'advCSSClasses', 'class' );
\r
1276 advAttr( 'advCharset', 'charset' );
\r
1277 advAttr( 'advStyles', 'style' );
\r
1280 if ( !this._.selectedElement )
\r
1282 // Create element if current selection is collapsed.
\r
1283 var selection = editor.getSelection(),
\r
1284 ranges = selection.getRanges();
\r
1285 if ( ranges.length == 1 && ranges[0].collapsed )
\r
1287 var text = new CKEDITOR.dom.text( attributes._cke_saved_href, editor.document );
\r
1288 ranges[0].insertNode( text );
\r
1289 ranges[0].selectNodeContents( text );
\r
1290 selection.selectRanges( ranges );
\r
1294 var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
\r
1295 style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why.
\r
1296 style.apply( editor.document );
\r
1298 // Id. Apply only to the first link.
\r
1299 if ( data.adv && data.adv.advId )
\r
1301 var links = this.getParentEditor().document.$.getElementsByTagName( 'a' );
\r
1302 for ( i = 0 ; i < links.length ; i++ )
\r
1304 if ( links[i].href == attributes.href )
\r
1306 links[i].id = data.adv.advId;
\r
1314 // We're only editing an existing link, so just overwrite the attributes.
\r
1315 var element = this._.selectedElement;
\r
1317 // IE BUG: Setting the name attribute to an existing link doesn't work.
\r
1318 // Must re-create the link from weired syntax to workaround.
\r
1319 if ( CKEDITOR.env.ie && attributes.name != element.getAttribute( 'name' ) )
\r
1321 var newElement = new CKEDITOR.dom.element( '<a name="' + CKEDITOR.tools.htmlEncode( attributes.name ) + '">',
\r
1322 editor.document );
\r
1324 selection = editor.getSelection();
\r
1326 element.moveChildren( newElement );
\r
1327 element.copyAttributes( newElement, { name : 1 } );
\r
1328 newElement.replace( element );
\r
1329 element = newElement;
\r
1331 selection.selectElement( element );
\r
1334 element.setAttributes( attributes );
\r
1335 element.removeAttributes( removeAttributes );
\r
1337 // Make the element display as an anchor if a name has been set.
\r
1338 if ( element.getAttribute( 'name' ) )
\r
1339 element.addClass( 'cke_anchor' );
\r
1341 element.removeClass( 'cke_anchor' );
\r
1343 if ( this.fakeObj )
\r
1344 editor.createFakeElement( element, 'cke_anchor', 'anchor' ).replace( this.fakeObj );
\r
1346 delete this._.selectedElement;
\r
1349 onLoad : function()
\r
1351 if ( !editor.config.linkShowAdvancedTab )
\r
1352 this.hidePage( 'advanced' ); //Hide Advanded tab.
\r
1354 if ( !editor.config.linkShowTargetTab )
\r
1355 this.hidePage( 'target' ); //Hide Target tab.
\r
1362 * The e-mail address anti-spam protection option.
\r
1363 * @name CKEDITOR.config.emailProtection
\r
1365 * Two forms of protection could be choosed from :
\r
1366 * 1. The whole address parts ( name, domain with any other query string ) are assembled into a
\r
1367 * function call pattern which invoke you own provided function, with the specified arguments.
\r
1368 * 2. Only the e-mail address is obfuscated into unicode code point sequences, replacement are
\r
1369 * done by a String.fromCharCode() call.
\r
1370 * Note: Both approaches require JavaScript to be enabled.
\r
1373 * config.emailProtection = '';
\r
1374 * // href="mailto:tester@ckeditor.com?subject=subject&body=body"
\r
1375 * config.emailProtection = 'encode';
\r
1376 * // 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
1377 * config.emailProtection = 'mt(NAME,DOMAIN,SUBJECT,BODY)';
\r
1378 * // href="javascript:mt('tester','ckeditor.com','subject','body')"
\r