2 Copyright (c) 2003-2009, 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 uploadInitiallyHidden = dialog.definition.getContents( 'upload' ).hidden;
\r
42 if ( typeValue == 'url' )
\r
44 if ( editor.config.linkShowTargetTab )
\r
45 dialog.showPage( 'target' );
\r
46 if ( !uploadInitiallyHidden )
\r
47 dialog.showPage( 'upload' );
\r
51 dialog.hidePage( 'target' );
\r
52 if ( !uploadInitiallyHidden )
\r
53 dialog.hidePage( 'upload' );
\r
56 for ( var i = 0 ; i < partIds.length ; i++ )
\r
58 var element = dialog.getContentElement( 'info', partIds[i] );
\r
62 element = element.getElement().getParent().getParent();
\r
63 if ( partIds[i] == typeValue + 'Options' )
\r
70 // Loads the parameters in a selected link to the link dialog fields.
\r
71 var emailRegex = /^mailto:([^?]+)(?:\?(.+))?$/,
\r
72 emailSubjectRegex = /subject=([^;?:@&=$,\/]*)/,
\r
73 emailBodyRegex = /body=([^;?:@&=$,\/]*)/,
\r
74 anchorRegex = /^#(.*)$/,
\r
75 urlRegex = /^((?:http|https|ftp|news):\/\/)?(.*)$/,
\r
76 selectableTargets = /^(_(?:self|top|parent|blank))$/;
\r
79 /\s*window.open\(\s*this\.href\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*/;
\r
80 var popupFeaturesRegex = /(?:^|,)([^=]+)=(\d+|yes|no)/gi;
\r
82 var parseLink = function( editor, element )
\r
84 var href = element ? ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) : '',
\r
92 emailMatch = href.match( emailRegex );
\r
93 anchorMatch = href.match( anchorRegex );
\r
94 urlMatch = href.match( urlRegex );
\r
97 // Load the link type and URL.
\r
100 var subjectMatch = href.match( emailSubjectRegex ),
\r
101 bodyMatch = href.match( emailBodyRegex );
\r
102 retval.type = 'email';
\r
104 retval.email.address = emailMatch[1];
\r
105 subjectMatch && ( retval.email.subject = decodeURIComponent( subjectMatch[1] ) );
\r
106 bodyMatch && ( retval.email.body = decodeURIComponent( bodyMatch[1] ) );
\r
108 else if ( anchorMatch )
\r
110 retval.type = 'anchor';
\r
111 retval.anchor = {};
\r
112 retval.anchor.name = retval.anchor.id = anchorMatch[1];
\r
114 else if ( href && urlMatch ) // urlRegex matches empty strings, so need to check for href as well.
\r
116 retval.type = 'url';
\r
118 retval.url.protocol = urlMatch[1];
\r
119 retval.url.url = urlMatch[2];
\r
122 retval.type = 'url';
\r
124 // Load target and popup settings.
\r
127 var target = element.getAttribute( 'target' );
\r
128 retval.target = {};
\r
131 // IE BUG: target attribute is an empty string instead of null in IE if it's not set.
\r
134 var onclick = element.getAttribute( '_cke_pa_onclick' ) || element.getAttribute( 'onclick' ),
\r
135 onclickMatch = onclick && onclick.match( popupRegex );
\r
136 if ( onclickMatch )
\r
138 retval.target.type = 'popup';
\r
139 retval.target.name = onclickMatch[1];
\r
142 while ( ( featureMatch = popupFeaturesRegex.exec( onclickMatch[2] ) ) )
\r
144 if ( featureMatch[2] == 'yes' || featureMatch[2] == '1' )
\r
145 retval.target[ featureMatch[1] ] = true;
\r
146 else if ( isFinite( featureMatch[2] ) )
\r
147 retval.target[ featureMatch[1] ] = featureMatch[2];
\r
153 var targetMatch = target.match( selectableTargets );
\r
155 retval.target.type = retval.target.name = target;
\r
158 retval.target.type = 'frame';
\r
159 retval.target.name = target;
\r
164 var advAttr = function( inputName, attrName )
\r
166 var value = element.getAttribute( attrName );
\r
167 if ( value !== null )
\r
168 retval.adv[ inputName ] = value || '';
\r
170 advAttr( 'advId', 'id' );
\r
171 advAttr( 'advLangDir', 'dir' );
\r
172 advAttr( 'advAccessKey', 'accessKey' );
\r
173 advAttr( 'advName', 'name' );
\r
174 advAttr( 'advLangCode', 'lang' );
\r
175 advAttr( 'advTabIndex', 'tabindex' );
\r
176 advAttr( 'advTitle', 'title' );
\r
177 advAttr( 'advContentType', 'type' );
\r
178 advAttr( 'advCSSClasses', 'class' );
\r
179 advAttr( 'advCharset', 'charset' );
\r
180 advAttr( 'advStyles', 'style' );
\r
183 // Find out whether we have any anchors in the editor.
\r
184 // Get all IMG elements in CK document.
\r
185 var elements = editor.document.getElementsByTag( 'img' ),
\r
186 realAnchors = new CKEDITOR.dom.nodeList( editor.document.$.anchors ),
\r
187 anchors = retval.anchors = [];
\r
189 for( var i = 0; i < elements.count() ; i++ )
\r
191 var item = elements.getItem( i );
\r
192 if ( item.getAttribute( '_cke_realelement' ) && item.getAttribute( '_cke_real_element_type' ) == 'anchor' )
\r
194 anchors.push( editor.restoreRealElement( item ) );
\r
198 for ( i = 0 ; i < realAnchors.count() ; i++ )
\r
199 anchors.push( realAnchors.getItem( i ) );
\r
201 for ( i = 0 ; i < anchors.length ; i++ )
\r
203 item = anchors[ i ];
\r
204 anchors[ i ] = { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) };
\r
207 // Record down the selected element in the dialog.
\r
208 this._.selectedElement = element;
\r
213 var setupParams = function( page, data )
\r
216 this.setValue( data[page][this.id] || '' );
\r
219 var setupPopupParams = function( data )
\r
221 return setupParams.call( this, 'target', data );
\r
224 var setupAdvParams = function( data )
\r
226 return setupParams.call( this, 'adv', data );
\r
229 var commitParams = function( page, data )
\r
234 data[page][this.id] = this.getValue() || '';
\r
237 var commitPopupParams = function( data )
\r
239 return commitParams.call( this, 'target', data );
\r
242 var commitAdvParams = function( data )
\r
244 return commitParams.call( this, 'adv', data );
\r
248 title : editor.lang.link.title,
\r
254 label : editor.lang.link.info,
\r
255 title : editor.lang.link.info,
\r
261 label : editor.lang.link.type,
\r
265 [ editor.lang.common.url, 'url' ],
\r
266 [ editor.lang.link.toAnchor, 'anchor' ],
\r
267 [ editor.lang.link.toEmail, 'email' ]
\r
269 onChange : linkTypeChanged,
\r
270 setup : function( data )
\r
273 this.setValue( data.type );
\r
275 commit : function( data )
\r
277 data.type = this.getValue();
\r
287 widths : [ '25%', '75%' ],
\r
293 label : editor.lang.common.protocol,
\r
294 'default' : 'http://',
\r
295 style : 'width : 100%;',
\r
304 setup : function( data )
\r
307 this.setValue( data.url.protocol );
\r
309 commit : function( data )
\r
314 data.url.protocol = this.getValue();
\r
320 label : editor.lang.common.url,
\r
321 onLoad : function ()
\r
323 this.allowOnChange = true;
\r
325 onKeyUp : function()
\r
327 this.allowOnChange = false;
\r
328 var protocolCmb = this.getDialog().getContentElement( 'info', 'protocol' ),
\r
329 url = this.getValue(),
\r
330 urlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/gi,
\r
331 urlOnChangeTestOther = /^((javascript:)|[#\/\.])/gi;
\r
333 var protocol = urlOnChangeProtocol.exec( url );
\r
336 this.setValue( url.substr( protocol[ 0 ].length ) );
\r
337 protocolCmb.setValue( protocol[ 0 ].toLowerCase() );
\r
339 else if ( urlOnChangeTestOther.test( url ) )
\r
340 protocolCmb.setValue( '' );
\r
342 this.allowOnChange = true;
\r
344 onChange : function()
\r
346 if ( this.allowOnChange ) // Dont't call on dialog load.
\r
349 validate : function()
\r
351 var dialog = this.getDialog();
\r
353 if ( dialog.getContentElement( 'info', 'linkType' ) &&
\r
354 dialog.getValueOf( 'info', 'linkType' ) != 'url' )
\r
357 if ( this.getDialog().fakeObj ) // Edit Anchor.
\r
360 var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noUrl );
\r
361 return func.apply( this );
\r
363 setup : function( data )
\r
365 this.allowOnChange = false;
\r
367 this.setValue( data.url.url );
\r
368 this.allowOnChange = true;
\r
370 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
371 if ( linkType && linkType.getValue() == 'url' )
\r
375 commit : function( data )
\r
380 data.url.url = this.getValue();
\r
381 this.allowOnChange = false;
\r
385 setup : function( data )
\r
387 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
388 this.getElement().show();
\r
395 filebrowser : 'info:url',
\r
396 label : editor.lang.common.browseServer
\r
402 id : 'anchorOptions',
\r
410 id : 'selectAnchorText',
\r
411 html : CKEDITOR.tools.htmlEncode( editor.lang.link.selectAnchor ),
\r
412 setup : function( data )
\r
414 if ( data.anchors.length > 0 )
\r
415 this.getElement().show();
\r
417 this.getElement().hide();
\r
423 style : 'text-align: center;',
\r
424 html : '<div>' + CKEDITOR.tools.htmlEncode( editor.lang.link.noAnchors ) + '</div>',
\r
425 setup : function( data )
\r
427 if ( data.anchors.length < 1 )
\r
428 this.getElement().show();
\r
430 this.getElement().hide();
\r
435 id : 'selectAnchor',
\r
442 label : editor.lang.link.anchorName,
\r
443 style : 'width: 100%;',
\r
448 setup : function( data )
\r
452 for ( var i = 0 ; i < data.anchors.length ; i++ )
\r
454 if ( data.anchors[i].name )
\r
455 this.add( data.anchors[i].name );
\r
459 this.setValue( data.anchor.name );
\r
461 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
462 if ( linkType && linkType.getValue() == 'email' )
\r
465 commit : function( data )
\r
467 if ( !data.anchor )
\r
470 data.anchor.name = this.getValue();
\r
477 label : editor.lang.link.anchorId,
\r
478 style : 'width: 100%;',
\r
483 setup : function( data )
\r
487 for ( var i = 0 ; i < data.anchors.length ; i++ )
\r
489 if ( data.anchors[i].id )
\r
490 this.add( data.anchors[i].id );
\r
494 this.setValue( data.anchor.id );
\r
496 commit : function( data )
\r
498 if ( !data.anchor )
\r
501 data.anchor.id = this.getValue();
\r
505 setup : function( data )
\r
507 if ( data.anchors.length > 0 )
\r
508 this.getElement().show();
\r
510 this.getElement().hide();
\r
514 setup : function( data )
\r
516 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
517 this.getElement().hide();
\r
522 id : 'emailOptions',
\r
528 id : 'emailAddress',
\r
529 label : editor.lang.link.emailAddress,
\r
530 validate : function()
\r
532 var dialog = this.getDialog();
\r
534 if ( !dialog.getContentElement( 'info', 'linkType' ) ||
\r
535 dialog.getValueOf( 'info', 'linkType' ) != 'email' )
\r
538 var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noEmail );
\r
539 return func.apply( this );
\r
541 setup : function( data )
\r
544 this.setValue( data.email.address );
\r
546 var linkType = this.getDialog().getContentElement( 'info', 'linkType' );
\r
547 if ( linkType && linkType.getValue() == 'email' )
\r
550 commit : function( data )
\r
555 data.email.address = this.getValue();
\r
560 id : 'emailSubject',
\r
561 label : editor.lang.link.emailSubject,
\r
562 setup : function( data )
\r
565 this.setValue( data.email.subject );
\r
567 commit : function( data )
\r
572 data.email.subject = this.getValue();
\r
578 label : editor.lang.link.emailBody,
\r
581 setup : function( data )
\r
584 this.setValue( data.email.body );
\r
586 commit : function( data )
\r
591 data.email.body = this.getValue();
\r
595 setup : function( data )
\r
597 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
\r
598 this.getElement().hide();
\r
605 label : editor.lang.link.target,
\r
606 title : editor.lang.link.target,
\r
611 widths : [ '50%', '50%' ],
\r
616 id : 'linkTargetType',
\r
617 label : editor.lang.link.target,
\r
618 'default' : 'notSet',
\r
619 style : 'width : 100%;',
\r
622 [ editor.lang.link.targetNotSet, 'notSet' ],
\r
623 [ editor.lang.link.targetFrame, 'frame' ],
\r
624 [ editor.lang.link.targetPopup, 'popup' ],
\r
625 [ editor.lang.link.targetNew, '_blank' ],
\r
626 [ editor.lang.link.targetTop, '_top' ],
\r
627 [ editor.lang.link.targetSelf, '_self' ],
\r
628 [ editor.lang.link.targetParent, '_parent' ]
\r
630 onChange : targetChanged,
\r
631 setup : function( data )
\r
634 this.setValue( data.target.type );
\r
636 commit : function( data )
\r
638 if ( !data.target )
\r
641 data.target.type = this.getValue();
\r
646 id : 'linkTargetName',
\r
647 label : editor.lang.link.targetFrameName,
\r
649 setup : function( data )
\r
652 this.setValue( data.target.name );
\r
654 commit : function( data )
\r
656 if ( !data.target )
\r
659 data.target.name = this.getValue();
\r
669 id : 'popupFeatures',
\r
674 html : CKEDITOR.tools.htmlEncode( editor.lang.link.popupFeatures )
\r
683 label : editor.lang.link.popupResizable,
\r
684 setup : setupPopupParams,
\r
685 commit : commitPopupParams
\r
690 label : editor.lang.link.popupStatusBar,
\r
691 setup : setupPopupParams,
\r
692 commit : commitPopupParams
\r
704 label : editor.lang.link.popupLocationBar,
\r
705 setup : setupPopupParams,
\r
706 commit : commitPopupParams
\r
712 label : editor.lang.link.popupToolbar,
\r
713 setup : setupPopupParams,
\r
714 commit : commitPopupParams
\r
726 label : editor.lang.link.popupMenuBar,
\r
727 setup : setupPopupParams,
\r
728 commit : commitPopupParams
\r
734 label : editor.lang.link.popupFullScreen,
\r
735 setup : setupPopupParams,
\r
736 commit : commitPopupParams
\r
748 label : editor.lang.link.popupScrollBars,
\r
749 setup : setupPopupParams,
\r
750 commit : commitPopupParams
\r
756 label : editor.lang.link.popupDependent,
\r
757 setup : setupPopupParams,
\r
758 commit : commitPopupParams
\r
769 widths : [ '30%', '70%' ],
\r
770 labelLayout : 'horizontal',
\r
771 label : editor.lang.link.popupWidth,
\r
773 setup : setupPopupParams,
\r
774 commit : commitPopupParams
\r
779 labelLayout : 'horizontal',
\r
780 widths : [ '55%', '45%' ],
\r
781 label : editor.lang.link.popupLeft,
\r
783 setup : setupPopupParams,
\r
784 commit : commitPopupParams
\r
795 labelLayout : 'horizontal',
\r
796 widths : [ '30%', '70%' ],
\r
797 label : editor.lang.link.popupHeight,
\r
799 setup : setupPopupParams,
\r
800 commit : commitPopupParams
\r
805 labelLayout : 'horizontal',
\r
806 label : editor.lang.link.popupTop,
\r
807 widths : [ '55%', '45%' ],
\r
809 setup : setupPopupParams,
\r
810 commit : commitPopupParams
\r
821 label : editor.lang.link.upload,
\r
822 title : editor.lang.link.upload,
\r
824 filebrowser : 'uploadButton',
\r
830 label : editor.lang.common.upload,
\r
831 style: 'height:40px',
\r
835 type : 'fileButton',
\r
836 id : 'uploadButton',
\r
837 label : editor.lang.common.uploadSubmit,
\r
838 filebrowser : 'info:url',
\r
839 'for' : [ 'upload', 'upload' ]
\r
845 label : editor.lang.link.advanced,
\r
846 title : editor.lang.link.advanced,
\r
856 widths : [ '45%', '35%', '20%' ],
\r
862 label : editor.lang.link.id,
\r
863 setup : setupAdvParams,
\r
864 commit : commitAdvParams
\r
869 label : editor.lang.link.langDir,
\r
871 style : 'width:110px',
\r
874 [ editor.lang.link.langDirNotSet, '' ],
\r
875 [ editor.lang.link.langDirLTR, 'ltr' ],
\r
876 [ editor.lang.link.langDirRTL, 'rtl' ]
\r
878 setup : setupAdvParams,
\r
879 commit : commitAdvParams
\r
883 id : 'advAccessKey',
\r
885 label : editor.lang.link.acccessKey,
\r
887 setup : setupAdvParams,
\r
888 commit : commitAdvParams
\r
895 widths : [ '45%', '35%', '20%' ],
\r
900 label : editor.lang.link.name,
\r
902 setup : setupAdvParams,
\r
903 commit : commitAdvParams
\r
908 label : editor.lang.link.langCode,
\r
909 id : 'advLangCode',
\r
912 setup : setupAdvParams,
\r
913 commit : commitAdvParams
\r
918 label : editor.lang.link.tabIndex,
\r
919 id : 'advTabIndex',
\r
922 setup : setupAdvParams,
\r
923 commit : commitAdvParams
\r
937 widths : [ '45%', '55%' ],
\r
942 label : editor.lang.link.advisoryTitle,
\r
945 setup : setupAdvParams,
\r
946 commit : commitAdvParams
\r
951 label : editor.lang.link.advisoryContentType,
\r
953 id : 'advContentType',
\r
954 setup : setupAdvParams,
\r
955 commit : commitAdvParams
\r
962 widths : [ '45%', '55%' ],
\r
967 label : editor.lang.link.cssClasses,
\r
969 id : 'advCSSClasses',
\r
970 setup : setupAdvParams,
\r
971 commit : commitAdvParams
\r
976 label : editor.lang.link.charset,
\r
979 setup : setupAdvParams,
\r
980 commit : commitAdvParams
\r
991 label : editor.lang.link.styles,
\r
994 setup : setupAdvParams,
\r
995 commit : commitAdvParams
\r
1005 onShow : function()
\r
1007 this.fakeObj = false;
\r
1009 var editor = this.getParentEditor(),
\r
1010 selection = editor.getSelection(),
\r
1011 ranges = selection.getRanges(),
\r
1014 // Fill in all the relevant fields if there's already one link selected.
\r
1015 if ( ranges.length == 1 )
\r
1018 var rangeRoot = ranges[0].getCommonAncestor( true );
\r
1019 element = rangeRoot.getAscendant( 'a', true );
\r
1020 if ( element && element.getAttribute( 'href' ) )
\r
1022 selection.selectElement( element );
\r
1024 else if ( ( element = rangeRoot.getAscendant( 'img', true ) ) &&
\r
1025 element.getAttribute( '_cke_real_element_type' ) &&
\r
1026 element.getAttribute( '_cke_real_element_type' ) == 'anchor' )
\r
1028 this.fakeObj = element;
\r
1029 element = editor.restoreRealElement( this.fakeObj );
\r
1030 selection.selectElement( this.fakeObj );
\r
1036 this.setupContent( parseLink.apply( this, [ editor, element ] ) );
\r
1040 var attributes = { href : 'javascript:void(0)/*' + CKEDITOR.tools.getNextNumber() + '*/' },
\r
1041 removeAttributes = [],
\r
1042 data = { href : attributes.href },
\r
1043 me = this, editor = this.getParentEditor();
\r
1045 this.commitContent( data );
\r
1047 // Compose the URL.
\r
1048 switch ( data.type || 'url' )
\r
1051 var protocol = ( data.url && data.url.protocol != undefined ) ? data.url.protocol : 'http://',
\r
1052 url = ( data.url && data.url.url ) || '';
\r
1053 attributes._cke_saved_href = ( url.indexOf( '/' ) === 0 ) ? url : protocol + url;
\r
1056 var name = ( data.anchor && data.anchor.name ),
\r
1057 id = ( data.anchor && data.anchor.id );
\r
1058 attributes._cke_saved_href = '#' + ( name || id || '' );
\r
1061 var address = ( data.email && data.email.address ),
\r
1062 subject = ( data.email && encodeURIComponent( data.email.subject || '' ) ),
\r
1063 body = ( data.email && encodeURIComponent( data.email.body || '' ) ),
\r
1064 linkList = [ 'mailto:', address ];
\r
1065 if ( subject || body )
\r
1068 linkList.push( '?' );
\r
1069 subject && argList.push( 'subject=' + subject );
\r
1070 body && argList.push( 'body=' + body );
\r
1071 linkList.push( argList.join( '&' ) );
\r
1073 attributes._cke_saved_href = linkList.join( '' );
\r
1078 // Popups and target.
\r
1079 if ( data.target )
\r
1081 if ( data.target.type == 'popup' )
\r
1083 var onclickList = [ 'window.open(this.href, \'',
\r
1084 data.target.name || '', '\', \'' ];
\r
1085 var featureList = [ 'resizable', 'status', 'location', 'toolbar', 'menubar', 'fullscreen',
\r
1086 'scrollbars', 'dependent' ];
\r
1087 var featureLength = featureList.length;
\r
1088 var addFeature = function( featureName )
\r
1090 if ( data.target[ featureName ] )
\r
1091 featureList.push( featureName + '=' + data.target[ featureName ] );
\r
1094 for ( var i = 0 ; i < featureLength ; i++ )
\r
1095 featureList[i] = featureList[i] + ( data.target[ featureList[i] ] ? '=yes' : '=no' ) ;
\r
1096 addFeature( 'width' );
\r
1097 addFeature( 'left' );
\r
1098 addFeature( 'height' );
\r
1099 addFeature( 'top' );
\r
1101 onclickList.push( featureList.join( ',' ), '\'); return false;' );
\r
1102 attributes[ CKEDITOR.env.ie || CKEDITOR.env.webkit ? '_cke_pa_onclick' : 'onclick' ] = onclickList.join( '' );
\r
1106 if ( data.target.type != 'notSet' && data.target.name )
\r
1107 attributes.target = data.target.name;
\r
1108 removeAttributes.push( '_cke_pa_onclick', 'onclick' );
\r
1112 // Advanced attributes.
\r
1115 var advAttr = function( inputName, attrName )
\r
1117 var value = data.adv[ inputName ];
\r
1119 attributes[attrName] = value;
\r
1121 removeAttributes.push( attrName );
\r
1124 if ( this._.selectedElement )
\r
1125 advAttr( 'advId', 'id' );
\r
1126 advAttr( 'advLangDir', 'dir' );
\r
1127 advAttr( 'advAccessKey', 'accessKey' );
\r
1128 advAttr( 'advName', 'name' );
\r
1129 advAttr( 'advLangCode', 'lang' );
\r
1130 advAttr( 'advTabIndex', 'tabindex' );
\r
1131 advAttr( 'advTitle', 'title' );
\r
1132 advAttr( 'advContentType', 'type' );
\r
1133 advAttr( 'advCSSClasses', 'class' );
\r
1134 advAttr( 'advCharset', 'charset' );
\r
1135 advAttr( 'advStyles', 'style' );
\r
1138 if ( !this._.selectedElement )
\r
1140 // Create element if current selection is collapsed.
\r
1141 var selection = editor.getSelection(),
\r
1142 ranges = selection.getRanges();
\r
1143 if ( ranges.length == 1 && ranges[0].collapsed )
\r
1145 var text = new CKEDITOR.dom.text( attributes._cke_saved_href, editor.document );
\r
1146 ranges[0].insertNode( text );
\r
1147 ranges[0].selectNodeContents( text );
\r
1148 selection.selectRanges( ranges );
\r
1152 var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
\r
1153 style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why.
\r
1154 style.apply( editor.document );
\r
1156 // Id. Apply only to the first link.
\r
1157 if ( data.adv && data.adv.advId )
\r
1159 var links = this.getParentEditor().document.$.getElementsByTagName( 'a' );
\r
1160 for ( i = 0 ; i < links.length ; i++ )
\r
1162 if ( links[i].href == attributes.href )
\r
1164 links[i].id = data.adv.advId;
\r
1172 // We're only editing an existing link, so just overwrite the attributes.
\r
1173 var element = this._.selectedElement;
\r
1175 // IE BUG: Setting the name attribute to an existing link doesn't work.
\r
1176 // Must re-create the link from weired syntax to workaround.
\r
1177 if ( CKEDITOR.env.ie && attributes.name != element.getAttribute( 'name' ) )
\r
1179 var newElement = new CKEDITOR.dom.element( '<a name="' + CKEDITOR.tools.htmlEncode( attributes.name ) + '">',
\r
1180 editor.document );
\r
1182 selection = editor.getSelection();
\r
1184 element.moveChildren( newElement );
\r
1185 element.copyAttributes( newElement, { name : 1 } );
\r
1186 newElement.replace( element );
\r
1187 element = newElement;
\r
1189 selection.selectElement( element );
\r
1192 element.setAttributes( attributes );
\r
1193 element.removeAttributes( removeAttributes );
\r
1195 // Make the element display as an anchor if a name has been set.
\r
1196 if ( element.getAttribute( 'name' ) )
\r
1197 element.addClass( 'cke_anchor' );
\r
1199 element.removeClass( 'cke_anchor' );
\r
1201 if ( this.fakeObj )
\r
1202 editor.createFakeElement( element, 'cke_anchor', 'anchor' ).replace( this.fakeObj );
\r
1204 delete this._.selectedElement;
\r
1207 onLoad : function()
\r
1209 if ( !editor.config.linkShowAdvancedTab )
\r
1210 this.hidePage( 'advanced' ); //Hide Advanded tab.
\r
1212 if ( !editor.config.linkShowTargetTab )
\r
1213 this.hidePage( 'target' ); //Hide Target tab.
\r