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.link.toUrl, '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
440 onLoad : function ()
\r
442 this.allowOnChange = true;
\r
444 onKeyUp : function()
\r
446 this.allowOnChange = false;
\r
447 var protocolCmb = this.getDialog().getContentElement( 'info', 'protocol' ),
\r
448 url = this.getValue(),
\r
449 urlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/gi,
\r
450 urlOnChangeTestOther = /^((javascript:)|[#\/\.])/gi;
\r
452 var protocol = urlOnChangeProtocol.exec( url );
\r
455 this.setValue( url.substr( protocol[ 0 ].length ) );
\r
456 protocolCmb.setValue( protocol[ 0 ].toLowerCase() );
\r
458 else if ( urlOnChangeTestOther.test( url ) )
\r
459 protocolCmb.setValue( '' );
\r
461 this.allowOnChange = true;
\r
463 onChange : function()
\r
465 if ( this.allowOnChange ) // Dont't call on dialog load.
\r
468 validate : function()
\r
470 var dialog = this.getDialog();
\r
472 if ( dialog.getContentElement( 'info', 'linkType' ) &&
\r
473 dialog.getValueOf( 'info', 'linkType' ) != 'url' )
\r
476 if ( this.getDialog().fakeObj ) // Edit Anchor.
\r
479 var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noUrl );
\r
480 return func.apply( this );
\r
482 setup : function( data )
\r
484 this.allowOnChange = false;
\r
486 this.setValue( data.url.url );
\r
487 this.allowOnChange = true;
\r
490 commit : function( data )
\r
492 // IE will not trigger the onChange event if the mouse has been used
\r
493 // to carry all the operations #4724
\r
499 data.url.url = this.getValue();
\r
500 this.allowOnChange = false;
\r
504 setup : function( data )
\r
506 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
507 this.getElement().show();
\r
514 filebrowser : 'info:url',
\r
515 label : editor.lang.common.browseServer
\r
521 id : 'anchorOptions',
\r
529 id : 'selectAnchorText',
\r
530 label : editor.lang.link.selectAnchor,
\r
531 setup : function( data )
\r
533 if ( data.anchors.length > 0 )
\r
534 this.getElement().show();
\r
536 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
625 style : 'text-align: center;',
\r
626 html : '<div role="label" tabIndex="-1">' + CKEDITOR.tools.htmlEncode( editor.lang.link.noAnchors ) + '</div>',
\r
627 // Focus the first element defined in above html.
\r
629 setup : function( data )
\r
631 if ( data.anchors.length < 1 )
\r
632 this.getElement().show();
\r
634 this.getElement().hide();
\r
638 setup : function( data )
\r
640 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
641 this.getElement().hide();
\r
646 id : 'emailOptions',
\r
652 id : 'emailAddress',
\r
653 label : editor.lang.link.emailAddress,
\r
655 validate : function()
\r
657 var dialog = this.getDialog();
\r
659 if ( !dialog.getContentElement( 'info', 'linkType' ) ||
\r
660 dialog.getValueOf( 'info', 'linkType' ) != 'email' )
\r
663 var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noEmail );
\r
664 return func.apply( this );
\r
666 setup : function( data )
\r
669 this.setValue( data.email.address );
\r
671 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
672 if ( linkType && linkType.getValue() == 'email' )
\r
675 commit : function( data )
\r
680 data.email.address = this.getValue();
\r
685 id : 'emailSubject',
\r
686 label : editor.lang.link.emailSubject,
\r
687 setup : function( data )
\r
690 this.setValue( data.email.subject );
\r
692 commit : function( data )
\r
697 data.email.subject = this.getValue();
\r
703 label : editor.lang.link.emailBody,
\r
706 setup : function( data )
\r
709 this.setValue( data.email.body );
\r
711 commit : function( data )
\r
716 data.email.body = this.getValue();
\r
720 setup : function( data )
\r
722 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
723 this.getElement().hide();
\r
730 label : editor.lang.link.target,
\r
731 title : editor.lang.link.target,
\r
736 widths : [ '50%', '50%' ],
\r
741 id : 'linkTargetType',
\r
742 label : editor.lang.common.target,
\r
743 'default' : 'notSet',
\r
744 style : 'width : 100%;',
\r
747 [ editor.lang.common.notSet, 'notSet' ],
\r
748 [ editor.lang.link.targetFrame, 'frame' ],
\r
749 [ editor.lang.link.targetPopup, 'popup' ],
\r
750 [ editor.lang.common.targetNew, '_blank' ],
\r
751 [ editor.lang.common.targetTop, '_top' ],
\r
752 [ editor.lang.common.targetSelf, '_self' ],
\r
753 [ editor.lang.common.targetParent, '_parent' ]
\r
755 onChange : targetChanged,
\r
756 setup : function( data )
\r
759 this.setValue( data.target.type );
\r
761 commit : function( data )
\r
763 if ( !data.target )
\r
766 data.target.type = this.getValue();
\r
771 id : 'linkTargetName',
\r
772 label : editor.lang.link.targetFrameName,
\r
774 setup : function( data )
\r
777 this.setValue( data.target.name );
\r
779 commit : function( data )
\r
781 if ( !data.target )
\r
784 data.target.name = this.getValue();
\r
794 id : 'popupFeatures',
\r
799 label : editor.lang.link.popupFeatures,
\r
809 label : editor.lang.link.popupResizable,
\r
810 setup : setupPopupParams,
\r
811 commit : commitPopupParams
\r
816 label : editor.lang.link.popupStatusBar,
\r
817 setup : setupPopupParams,
\r
818 commit : commitPopupParams
\r
830 label : editor.lang.link.popupLocationBar,
\r
831 setup : setupPopupParams,
\r
832 commit : commitPopupParams
\r
838 label : editor.lang.link.popupToolbar,
\r
839 setup : setupPopupParams,
\r
840 commit : commitPopupParams
\r
852 label : editor.lang.link.popupMenuBar,
\r
853 setup : setupPopupParams,
\r
854 commit : commitPopupParams
\r
860 label : editor.lang.link.popupFullScreen,
\r
861 setup : setupPopupParams,
\r
862 commit : commitPopupParams
\r
874 label : editor.lang.link.popupScrollBars,
\r
875 setup : setupPopupParams,
\r
876 commit : commitPopupParams
\r
882 label : editor.lang.link.popupDependent,
\r
883 setup : setupPopupParams,
\r
884 commit : commitPopupParams
\r
895 widths : [ '30%', '70%' ],
\r
896 labelLayout : 'horizontal',
\r
897 label : editor.lang.link.popupWidth,
\r
899 setup : setupPopupParams,
\r
900 commit : commitPopupParams
\r
905 labelLayout : 'horizontal',
\r
906 widths : [ '55%', '45%' ],
\r
907 label : editor.lang.link.popupLeft,
\r
909 setup : setupPopupParams,
\r
910 commit : commitPopupParams
\r
921 labelLayout : 'horizontal',
\r
922 widths : [ '30%', '70%' ],
\r
923 label : editor.lang.link.popupHeight,
\r
925 setup : setupPopupParams,
\r
926 commit : commitPopupParams
\r
931 labelLayout : 'horizontal',
\r
932 label : editor.lang.link.popupTop,
\r
933 widths : [ '55%', '45%' ],
\r
935 setup : setupPopupParams,
\r
936 commit : commitPopupParams
\r
949 label : editor.lang.link.upload,
\r
950 title : editor.lang.link.upload,
\r
952 filebrowser : 'uploadButton',
\r
958 label : editor.lang.common.upload,
\r
959 style: 'height:40px',
\r
963 type : 'fileButton',
\r
964 id : 'uploadButton',
\r
965 label : editor.lang.common.uploadSubmit,
\r
966 filebrowser : 'info:url',
\r
967 'for' : [ 'upload', 'upload' ]
\r
973 label : editor.lang.link.advanced,
\r
974 title : editor.lang.link.advanced,
\r
984 widths : [ '45%', '35%', '20%' ],
\r
990 label : editor.lang.link.id,
\r
991 setup : setupAdvParams,
\r
992 commit : commitAdvParams
\r
997 label : editor.lang.link.langDir,
\r
999 style : 'width:110px',
\r
1002 [ editor.lang.common.notSet, '' ],
\r
1003 [ editor.lang.link.langDirLTR, 'ltr' ],
\r
1004 [ editor.lang.link.langDirRTL, 'rtl' ]
\r
1006 setup : setupAdvParams,
\r
1007 commit : commitAdvParams
\r
1011 id : 'advAccessKey',
\r
1013 label : editor.lang.link.acccessKey,
\r
1015 setup : setupAdvParams,
\r
1016 commit : commitAdvParams
\r
1023 widths : [ '45%', '35%', '20%' ],
\r
1028 label : editor.lang.link.name,
\r
1030 setup : setupAdvParams,
\r
1031 commit : commitAdvParams
\r
1036 label : editor.lang.link.langCode,
\r
1037 id : 'advLangCode',
\r
1040 setup : setupAdvParams,
\r
1041 commit : commitAdvParams
\r
1046 label : editor.lang.link.tabIndex,
\r
1047 id : 'advTabIndex',
\r
1050 setup : setupAdvParams,
\r
1051 commit : commitAdvParams
\r
1065 widths : [ '45%', '55%' ],
\r
1070 label : editor.lang.link.advisoryTitle,
\r
1073 setup : setupAdvParams,
\r
1074 commit : commitAdvParams
\r
1079 label : editor.lang.link.advisoryContentType,
\r
1081 id : 'advContentType',
\r
1082 setup : setupAdvParams,
\r
1083 commit : commitAdvParams
\r
1090 widths : [ '45%', '55%' ],
\r
1095 label : editor.lang.link.cssClasses,
\r
1097 id : 'advCSSClasses',
\r
1098 setup : setupAdvParams,
\r
1099 commit : commitAdvParams
\r
1104 label : editor.lang.link.charset,
\r
1106 id : 'advCharset',
\r
1107 setup : setupAdvParams,
\r
1108 commit : commitAdvParams
\r
1119 label : editor.lang.link.styles,
\r
1122 setup : setupAdvParams,
\r
1123 commit : commitAdvParams
\r
1133 onShow : function()
\r
1135 this.fakeObj = false;
\r
1137 var editor = this.getParentEditor(),
\r
1138 selection = editor.getSelection(),
\r
1139 ranges = selection.getRanges(),
\r
1142 // Fill in all the relevant fields if there's already one link selected.
\r
1143 if ( ranges.length == 1 )
\r
1146 var rangeRoot = ranges[0].getCommonAncestor( true );
\r
1147 element = rangeRoot.getAscendant( 'a', true );
\r
1148 if ( element && element.getAttribute( 'href' ) )
\r
1150 selection.selectElement( element );
\r
1152 else if ( ( element = rangeRoot.getAscendant( 'img', true ) ) &&
\r
1153 element.getAttribute( '_cke_real_element_type' ) &&
\r
1154 element.getAttribute( '_cke_real_element_type' ) == 'anchor' )
\r
1156 this.fakeObj = element;
\r
1157 element = editor.restoreRealElement( this.fakeObj );
\r
1158 selection.selectElement( this.fakeObj );
\r
1164 this.setupContent( parseLink.apply( this, [ editor, element ] ) );
\r
1168 var attributes = { href : 'javascript:void(0)/*' + CKEDITOR.tools.getNextNumber() + '*/' },
\r
1169 removeAttributes = [],
\r
1170 data = { href : attributes.href },
\r
1172 editor = this.getParentEditor();
\r
1174 this.commitContent( data );
\r
1176 // Compose the URL.
\r
1177 switch ( data.type || 'url' )
\r
1180 var protocol = ( data.url && data.url.protocol != undefined ) ? data.url.protocol : 'http://',
\r
1181 url = ( data.url && data.url.url ) || '';
\r
1182 attributes._cke_saved_href = ( url.indexOf( '/' ) === 0 ) ? url : protocol + url;
\r
1185 var name = ( data.anchor && data.anchor.name ),
\r
1186 id = ( data.anchor && data.anchor.id );
\r
1187 attributes._cke_saved_href = '#' + ( name || id || '' );
\r
1192 email = data.email,
\r
1193 address = email.address;
\r
1195 switch( emailProtection )
\r
1200 var subject = encodeURIComponent( email.subject || '' ),
\r
1201 body = encodeURIComponent( email.body || '' );
\r
1203 // Build the e-mail parameters first.
\r
1205 subject && argList.push( 'subject=' + subject );
\r
1206 body && argList.push( 'body=' + body );
\r
1207 argList = argList.length ? '?' + argList.join( '&' ) : '';
\r
1209 if ( emailProtection == 'encode' )
\r
1211 linkHref = [ 'javascript:void(location.href=\'mailto:\'+',
\r
1212 protectEmailAddressAsEncodedString( address ) ];
\r
1213 // parameters are optional.
\r
1214 argList && linkHref.push( '+\'', escapeSingleQuote( argList ), '\'' );
\r
1216 linkHref.push( ')' );
\r
1219 linkHref = [ 'mailto:', address, argList ];
\r
1225 // Separating name and domain.
\r
1226 var nameAndDomain = address.split( '@', 2 );
\r
1227 email.name = nameAndDomain[ 0 ];
\r
1228 email.domain = nameAndDomain[ 1 ];
\r
1230 linkHref = [ 'javascript:', protectEmailLinkAsFunction( email ) ];
\r
1234 attributes._cke_saved_href = linkHref.join( '' );
\r
1238 // Popups and target.
\r
1239 if ( data.target )
\r
1241 if ( data.target.type == 'popup' )
\r
1243 var onclickList = [ 'window.open(this.href, \'',
\r
1244 data.target.name || '', '\', \'' ];
\r
1245 var featureList = [ 'resizable', 'status', 'location', 'toolbar', 'menubar', 'fullscreen',
\r
1246 'scrollbars', 'dependent' ];
\r
1247 var featureLength = featureList.length;
\r
1248 var addFeature = function( featureName )
\r
1250 if ( data.target[ featureName ] )
\r
1251 featureList.push( featureName + '=' + data.target[ featureName ] );
\r
1254 for ( var i = 0 ; i < featureLength ; i++ )
\r
1255 featureList[i] = featureList[i] + ( data.target[ featureList[i] ] ? '=yes' : '=no' ) ;
\r
1256 addFeature( 'width' );
\r
1257 addFeature( 'left' );
\r
1258 addFeature( 'height' );
\r
1259 addFeature( 'top' );
\r
1261 onclickList.push( featureList.join( ',' ), '\'); return false;' );
\r
1262 attributes[ '_cke_pa_onclick' ] = onclickList.join( '' );
\r
1266 if ( data.target.type != 'notSet' && data.target.name )
\r
1267 attributes.target = data.target.name;
\r
1269 removeAttributes.push( 'target' );
\r
1271 removeAttributes.push( '_cke_pa_onclick', 'onclick' );
\r
1275 // Advanced attributes.
\r
1278 var advAttr = function( inputName, attrName )
\r
1280 var value = data.adv[ inputName ];
\r
1282 attributes[attrName] = value;
\r
1284 removeAttributes.push( attrName );
\r
1287 if ( this._.selectedElement )
\r
1288 advAttr( 'advId', 'id' );
\r
1289 advAttr( 'advLangDir', 'dir' );
\r
1290 advAttr( 'advAccessKey', 'accessKey' );
\r
1291 advAttr( 'advName', 'name' );
\r
1292 advAttr( 'advLangCode', 'lang' );
\r
1293 advAttr( 'advTabIndex', 'tabindex' );
\r
1294 advAttr( 'advTitle', 'title' );
\r
1295 advAttr( 'advContentType', 'type' );
\r
1296 advAttr( 'advCSSClasses', 'class' );
\r
1297 advAttr( 'advCharset', 'charset' );
\r
1298 advAttr( 'advStyles', 'style' );
\r
1301 if ( !this._.selectedElement )
\r
1303 // Create element if current selection is collapsed.
\r
1304 var selection = editor.getSelection(),
\r
1305 ranges = selection.getRanges();
\r
1306 if ( ranges.length == 1 && ranges[0].collapsed )
\r
1308 var text = new CKEDITOR.dom.text( attributes._cke_saved_href, editor.document );
\r
1309 ranges[0].insertNode( text );
\r
1310 ranges[0].selectNodeContents( text );
\r
1311 selection.selectRanges( ranges );
\r
1315 var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
\r
1316 style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why.
\r
1317 style.apply( editor.document );
\r
1319 // Id. Apply only to the first link.
\r
1320 if ( data.adv && data.adv.advId )
\r
1322 var links = this.getParentEditor().document.$.getElementsByTagName( 'a' );
\r
1323 for ( i = 0 ; i < links.length ; i++ )
\r
1325 if ( links[i].href == attributes.href )
\r
1327 links[i].id = data.adv.advId;
\r
1335 // We're only editing an existing link, so just overwrite the attributes.
\r
1336 var element = this._.selectedElement,
\r
1337 href = element.getAttribute( '_cke_saved_href' ),
\r
1338 textView = element.getHtml();
\r
1340 // IE BUG: Setting the name attribute to an existing link doesn't work.
\r
1341 // Must re-create the link from weired syntax to workaround.
\r
1342 if ( CKEDITOR.env.ie && attributes.name != element.getAttribute( 'name' ) )
\r
1344 var newElement = new CKEDITOR.dom.element( '<a name="' + CKEDITOR.tools.htmlEncode( attributes.name ) + '">',
\r
1345 editor.document );
\r
1347 selection = editor.getSelection();
\r
1349 element.moveChildren( newElement );
\r
1350 element.copyAttributes( newElement, { name : 1 } );
\r
1351 newElement.replace( element );
\r
1352 element = newElement;
\r
1354 selection.selectElement( element );
\r
1357 element.setAttributes( attributes );
\r
1358 element.removeAttributes( removeAttributes );
\r
1359 // Update text view when user changes protocol #4612.
\r
1360 if (href == textView)
\r
1361 element.setHtml( attributes._cke_saved_href );
\r
1362 // Make the element display as an anchor if a name has been set.
\r
1363 if ( element.getAttribute( 'name' ) )
\r
1364 element.addClass( 'cke_anchor' );
\r
1366 element.removeClass( 'cke_anchor' );
\r
1368 if ( this.fakeObj )
\r
1369 editor.createFakeElement( element, 'cke_anchor', 'anchor' ).replace( this.fakeObj );
\r
1371 delete this._.selectedElement;
\r
1374 onLoad : function()
\r
1376 if ( !editor.config.linkShowAdvancedTab )
\r
1377 this.hidePage( 'advanced' ); //Hide Advanded tab.
\r
1379 if ( !editor.config.linkShowTargetTab )
\r
1380 this.hidePage( 'target' ); //Hide Target tab.
\r
1383 // Inital focus on 'url' field if link is of type URL.
\r
1384 onFocus : function()
\r
1386 var linkType = this.getContentElement( 'info', 'linkType' ),
\r
1388 if ( linkType && linkType.getValue( ) == 'url' )
\r
1390 urlField = this.getContentElement( 'info', 'url' );
\r
1391 urlField.select();
\r
1398 * The e-mail address anti-spam protection option. The protection will be
\r
1399 * applied when creating or modifying e-mail links through the editor interface.<br>
\r
1400 * Two methods of protection can be choosed:
\r
1401 * <ol> <li>The e-mail parts (name, domain and any other query string) are
\r
1402 * assembled into a function call pattern. Such function must be
\r
1403 * provided by the developer in the pages that will use the contents.
\r
1404 * <li>Only the e-mail address is obfuscated into a special string that
\r
1405 * has no meaning for humans or spam bots, but which is properly
\r
1406 * rendered and accepted by the browser.</li></ol>
\r
1407 * Both approaches require JavaScript to be enabled.
\r
1408 * @name CKEDITOR.config.emailProtection
\r
1411 * @default '' (empty string = disabled)
\r
1413 * // href="mailto:tester@ckeditor.com?subject=subject&body=body"
\r
1414 * config.emailProtection = '';
\r
1416 * // 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
1417 * config.emailProtection = 'encode';
\r
1419 * // href="javascript:mt('tester','ckeditor.com','subject','body')"
\r
1420 * config.emailProtection = 'mt(NAME,DOMAIN,SUBJECT,BODY)';
\r