X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=plugins%2Flink%2Fdialogs%2Flink.js;h=355d7c845b098b382f758b13487efdf94c015fe2;hb=f0610347140239143439a511ee2bd48cb784f470;hp=4e1138f6f2dc8a5c1d886d5125de2e5d5aec26b0;hpb=941b0a9ba4e673e292510d80a5a86806994b8ea6;p=ckeditor.git diff --git a/plugins/link/dialogs/link.js b/plugins/link/dialogs/link.js index 4e1138f..355d7c8 100644 --- a/plugins/link/dialogs/link.js +++ b/plugins/link/dialogs/link.js @@ -1,11 +1,12 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ -CKEDITOR.dialog.add('link',function(a){var b=function(){var A=this.getDialog(),B=A.getContentElement('target','popupFeatures'),C=A.getContentElement('target','linkTargetName'),D=this.getValue();if(!B||!C)return;B=B.getElement();if(D=='popup'){B.show();C.setLabel(a.lang.link.targetPopupName);}else{B.hide();C.setLabel(a.lang.link.targetFrameName);this.getDialog().setValueOf('target','linkTargetName',D.charAt(0)=='_'?D:'');}},c=function(){var A=this.getDialog(),B=['urlOptions','anchorOptions','emailOptions'],C=this.getValue(),D=A.definition.getContents('upload'),E=D&&D.hidden;if(C=='url'){if(a.config.linkShowTargetTab)A.showPage('target');if(!E)A.showPage('upload');}else{A.hidePage('target');if(!E)A.hidePage('upload');}for(var F=0;F0&&B.push(',');B.push("'",F?v(encodeURIComponent(A[E])):'',"'");}B.push(')');return B.join('');};function z(A){var B,C=A.length,D=[];for(var E=0;E','']],setup:function(A){if(A.url)this.setValue(A.url.protocol||''); -},commit:function(A){if(!A.url)A.url={};A.url.protocol=this.getValue();}},{type:'text',id:'url',label:a.lang.common.url,onLoad:function(){this.allowOnChange=true;},onKeyUp:function(){var F=this;F.allowOnChange=false;var A=F.getDialog().getContentElement('info','protocol'),B=F.getValue(),C=/^(http|https|ftp|news):\/\/(?=.)/gi,D=/^((javascript:)|[#\/\.])/gi,E=C.exec(B);if(E){F.setValue(B.substr(E[0].length));A.setValue(E[0].toLowerCase());}else if(D.test(B))A.setValue('');F.allowOnChange=true;},onChange:function(){if(this.allowOnChange)this.onKeyUp();},validate:function(){var A=this.getDialog();if(A.getContentElement('info','linkType')&&A.getValueOf('info','linkType')!='url')return true;if(this.getDialog().fakeObj)return true;var B=CKEDITOR.dialog.validate.notEmpty(a.lang.link.noUrl);return B.apply(this);},setup:function(A){var C=this;C.allowOnChange=false;if(A.url)C.setValue(A.url.url);C.allowOnChange=true;var B=C.getDialog().getContentElement('info','linkType');if(B&&B.getValue()=='url')C.select();},commit:function(A){if(!A.url)A.url={};A.url.url=this.getValue();this.allowOnChange=false;}}],setup:function(A){if(!this.getDialog().getContentElement('info','linkType'))this.getElement().show();}},{type:'button',id:'browse',hidden:'true',filebrowser:'info:url',label:a.lang.common.browseServer}]},{type:'vbox',id:'anchorOptions',width:260,align:'center',padding:0,children:[{type:'html',id:'selectAnchorText',html:CKEDITOR.tools.htmlEncode(a.lang.link.selectAnchor),setup:function(A){if(A.anchors.length>0)this.getElement().show();else this.getElement().hide();}},{type:'html',id:'noAnchors',style:'text-align: center;',html:'
'+CKEDITOR.tools.htmlEncode(a.lang.link.noAnchors)+'
',setup:function(A){if(A.anchors.length<1)this.getElement().show();else this.getElement().hide();}},{type:'hbox',id:'selectAnchor',children:[{type:'select',id:'anchorName','default':'',label:a.lang.link.anchorName,style:'width: 100%;',items:[['']],setup:function(A){var D=this;D.clear();D.add('');for(var B=0;B0)this.getElement().show();else this.getElement().hide();}}],setup:function(A){if(!this.getDialog().getContentElement('info','linkType'))this.getElement().hide();}},{type:'vbox',id:'emailOptions',padding:1,children:[{type:'text',id:'emailAddress',label:a.lang.link.emailAddress,validate:function(){var A=this.getDialog();if(!A.getContentElement('info','linkType')||A.getValueOf('info','linkType')!='email')return true;var B=CKEDITOR.dialog.validate.notEmpty(a.lang.link.noEmail);return B.apply(this);},setup:function(A){if(A.email)this.setValue(A.email.address);var B=this.getDialog().getContentElement('info','linkType');if(B&&B.getValue()=='email')this.select();},commit:function(A){if(!A.email)A.email={};A.email.address=this.getValue();}},{type:'text',id:'emailSubject',label:a.lang.link.emailSubject,setup:function(A){if(A.email)this.setValue(A.email.subject);},commit:function(A){if(!A.email)A.email={};A.email.subject=this.getValue();}},{type:'textarea',id:'emailBody',label:a.lang.link.emailBody,rows:3,'default':'',setup:function(A){if(A.email)this.setValue(A.email.body);},commit:function(A){if(!A.email)A.email={};A.email.body=this.getValue();}}],setup:function(A){if(!this.getDialog().getContentElement('info','linkType'))this.getElement().hide();}}]},{id:'target',label:a.lang.link.target,title:a.lang.link.target,elements:[{type:'hbox',widths:['50%','50%'],children:[{type:'select',id:'linkTargetType',label:a.lang.link.target,'default':'notSet',style:'width : 100%;',items:[[a.lang.link.targetNotSet,'notSet'],[a.lang.link.targetFrame,'frame'],[a.lang.link.targetPopup,'popup'],[a.lang.link.targetNew,'_blank'],[a.lang.link.targetTop,'_top'],[a.lang.link.targetSelf,'_self'],[a.lang.link.targetParent,'_parent']],onChange:b,setup:function(A){if(A.target)this.setValue(A.target.type);},commit:function(A){if(!A.target)A.target={};A.target.type=this.getValue();}},{type:'text',id:'linkTargetName',label:a.lang.link.targetFrameName,'default':'',setup:function(A){if(A.target)this.setValue(A.target.name);},commit:function(A){if(!A.target)A.target={};A.target.name=this.getValue();}}]},{type:'vbox',width:260,align:'center',padding:2,id:'popupFeatures',children:[{type:'html',html:CKEDITOR.tools.htmlEncode(a.lang.link.popupFeatures)},{type:'hbox',children:[{type:'checkbox',id:'resizable',label:a.lang.link.popupResizable,setup:p,commit:s},{type:'checkbox',id:'status',label:a.lang.link.popupStatusBar,setup:p,commit:s}]},{type:'hbox',children:[{type:'checkbox',id:'location',label:a.lang.link.popupLocationBar,setup:p,commit:s},{type:'checkbox',id:'toolbar',label:a.lang.link.popupToolbar,setup:p,commit:s}]},{type:'hbox',children:[{type:'checkbox',id:'menubar',label:a.lang.link.popupMenuBar,setup:p,commit:s},{type:'checkbox',id:'fullscreen',label:a.lang.link.popupFullScreen,setup:p,commit:s}]},{type:'hbox',children:[{type:'checkbox',id:'scrollbars',label:a.lang.link.popupScrollBars,setup:p,commit:s},{type:'checkbox',id:'dependent',label:a.lang.link.popupDependent,setup:p,commit:s}]},{type:'hbox',children:[{type:'text',widths:['30%','70%'],labelLayout:'horizontal',label:a.lang.link.popupWidth,id:'width',setup:p,commit:s},{type:'text',labelLayout:'horizontal',widths:['55%','45%'],label:a.lang.link.popupLeft,id:'left',setup:p,commit:s}]},{type:'hbox',children:[{type:'text',labelLayout:'horizontal',widths:['30%','70%'],label:a.lang.link.popupHeight,id:'height',setup:p,commit:s},{type:'text',labelLayout:'horizontal',label:a.lang.link.popupTop,widths:['55%','45%'],id:'top',setup:p,commit:s}]}]}]},{id:'upload',label:a.lang.link.upload,title:a.lang.link.upload,hidden:true,filebrowser:'uploadButton',elements:[{type:'file',id:'upload',label:a.lang.common.upload,style:'height:40px',size:29},{type:'fileButton',id:'uploadButton',label:a.lang.common.uploadSubmit,filebrowser:'info:url','for':['upload','upload']}]},{id:'advanced',label:a.lang.link.advanced,title:a.lang.link.advanced,elements:[{type:'vbox',padding:1,children:[{type:'hbox',widths:['45%','35%','20%'],children:[{type:'text',id:'advId',label:a.lang.link.id,setup:q,commit:t},{type:'select',id:'advLangDir',label:a.lang.link.langDir,'default':'',style:'width:110px',items:[[a.lang.link.langDirNotSet,''],[a.lang.link.langDirLTR,'ltr'],[a.lang.link.langDirRTL,'rtl']],setup:q,commit:t},{type:'text',id:'advAccessKey',width:'80px',label:a.lang.link.acccessKey,maxLength:1,setup:q,commit:t}]},{type:'hbox',widths:['45%','35%','20%'],children:[{type:'text',label:a.lang.link.name,id:'advName',setup:q,commit:t},{type:'text',label:a.lang.link.langCode,id:'advLangCode',width:'110px','default':'',setup:q,commit:t},{type:'text',label:a.lang.link.tabIndex,id:'advTabIndex',width:'80px',maxLength:5,setup:q,commit:t}]}]},{type:'vbox',padding:1,children:[{type:'hbox',widths:['45%','55%'],children:[{type:'text',label:a.lang.link.advisoryTitle,'default':'',id:'advTitle',setup:q,commit:t},{type:'text',label:a.lang.link.advisoryContentType,'default':'',id:'advContentType',setup:q,commit:t}]},{type:'hbox',widths:['45%','55%'],children:[{type:'text',label:a.lang.link.cssClasses,'default':'',id:'advCSSClasses',setup:q,commit:t},{type:'text',label:a.lang.link.charset,'default':'',id:'advCharset',setup:q,commit:t}]},{type:'hbox',children:[{type:'text',label:a.lang.link.styles,'default':'',id:'advStyles',setup:q,commit:t}]}]}]}],onShow:function(){var G=this; -G.fakeObj=false;var A=G.getParentEditor(),B=A.getSelection(),C=B.getRanges(),D=null,E=G;if(C.length==1){var F=C[0].getCommonAncestor(true);D=F.getAscendant('a',true);if(D&&D.getAttribute('href'))B.selectElement(D);else if((D=F.getAscendant('img',true))&&D.getAttribute('_cke_real_element_type')&&D.getAttribute('_cke_real_element_type')=='anchor'){G.fakeObj=D;D=A.restoreRealElement(G.fakeObj);B.selectElement(G.fakeObj);}else D=null;}G.setupContent(n.apply(G,[A,D]));},onOk:function(){var A={href:'javascript:void(0)/*'+CKEDITOR.tools.getNextNumber()+'*/'},B=[],C={href:A.href},D=this,E=this.getParentEditor();this.commitContent(C);switch(C.type||'url'){case 'url':var F=C.url&&C.url.protocol!=undefined?C.url.protocol:'http://',G=C.url&&C.url.url||'';A._cke_saved_href=G.indexOf('/')===0?G:F+G;break;case 'anchor':var H=C.anchor&&C.anchor.name,I=C.anchor&&C.anchor.id;A._cke_saved_href='#'+(H||I||'');break;case 'email':var J,K=C.email,L=K.address;switch(w){case '':case 'encode':var M=encodeURIComponent(K.subject||''),N=encodeURIComponent(K.body||''),O=[];M&&O.push('subject='+M);N&&O.push('body='+N);O=O.length?'?'+O.join('&'):'';if(w=='encode'){J=["javascript:void(location.href='mailto:'+",z(L)];O&&J.push("+'",v(O),"'");J.push(')');}else J=['mailto:',L,O];break;default:var P=L.split('@',2);K.name=P[0];K.domain=P[1];J=['javascript:',y(K)];}A._cke_saved_href=J.join('');break;}if(C.target)if(C.target.type=='popup'){var Q=["window.open(this.href, '",C.target.name||'',"', '"],R=['resizable','status','location','toolbar','menubar','fullscreen','scrollbars','dependent'],S=R.length,T=function(ad){if(C.target[ad])R.push(ad+'='+C.target[ad]);};for(var U=0;U',E.document);W=E.getSelection();ab.moveChildren(ac);ab.copyAttributes(ac,{name:1});ac.replace(ab);ab=ac;W.selectElement(ab);}ab.setAttributes(A);ab.removeAttributes(B);if(ab.getAttribute('name'))ab.addClass('cke_anchor');else ab.removeClass('cke_anchor');if(this.fakeObj)E.createFakeElement(ab,'cke_anchor','anchor').replace(this.fakeObj);delete this._.selectedElement;}},onLoad:function(){if(!a.config.linkShowAdvancedTab)this.hidePage('advanced');if(!a.config.linkShowTargetTab)this.hidePage('target');}};}); +CKEDITOR.dialog.add('link',function(a){var b=CKEDITOR.plugins.link,c=function(){var F=this.getDialog(),G=F.getContentElement('target','popupFeatures'),H=F.getContentElement('target','linkTargetName'),I=this.getValue();if(!G||!H)return;G=G.getElement();G.hide();H.setValue('');switch(I){case 'frame':H.setLabel(a.lang.link.targetFrameName);H.getElement().show();break;case 'popup':G.show();H.setLabel(a.lang.link.targetPopupName);H.getElement().show();break;default:H.setValue(I);H.getElement().hide();break;}},d=function(){var F=this.getDialog(),G=['urlOptions','anchorOptions','emailOptions'],H=this.getValue(),I=F.definition.getContents('upload'),J=I&&I.hidden;if(H=='url'){if(a.config.linkShowTargetTab)F.showPage('target');if(!J)F.showPage('upload');}else{F.hidePage('target');if(!J)F.hidePage('upload');}for(var K=0;K0&&G.push(',');G.push("'",K?x(encodeURIComponent(F[J])):'',"'");}G.push(')');return G.join('');};function B(F){var G,H=F.length,I=[];for(var J=0;J0)this.getElement().show();else this.getElement().hide();},children:[{type:'hbox',id:'selectAnchor',children:[{type:'select',id:'anchorName','default':'',label:E.anchorName,style:'width: 100%;',items:[['']],setup:function(F){var I=this;I.clear();I.add('');for(var G=0;G0)this.getElement().show();else this.getElement().hide();}}]},{type:'html',id:'noAnchors',style:'text-align: center;',html:'
'+CKEDITOR.tools.htmlEncode(E.noAnchors)+'
',focus:true,setup:function(F){if(F.anchors.length<1)this.getElement().show();else this.getElement().hide();}}],setup:function(F){if(!this.getDialog().getContentElement('info','linkType'))this.getElement().hide();}},{type:'vbox',id:'emailOptions',padding:1,children:[{type:'text',id:'emailAddress',label:E.emailAddress,required:true,validate:function(){var F=this.getDialog();if(!F.getContentElement('info','linkType')||F.getValueOf('info','linkType')!='email')return true;var G=CKEDITOR.dialog.validate.notEmpty(E.noEmail);return G.apply(this);},setup:function(F){if(F.email)this.setValue(F.email.address);var G=this.getDialog().getContentElement('info','linkType');if(G&&G.getValue()=='email')this.select();},commit:function(F){if(!F.email)F.email={};F.email.address=this.getValue();}},{type:'text',id:'emailSubject',label:E.emailSubject,setup:function(F){if(F.email)this.setValue(F.email.subject);},commit:function(F){if(!F.email)F.email={};F.email.subject=this.getValue();}},{type:'textarea',id:'emailBody',label:E.emailBody,rows:3,'default':'',setup:function(F){if(F.email)this.setValue(F.email.body);},commit:function(F){if(!F.email)F.email={};F.email.body=this.getValue();}}],setup:function(F){if(!this.getDialog().getContentElement('info','linkType'))this.getElement().hide();}}]},{id:'target',label:E.target,title:E.target,elements:[{type:'hbox',widths:['50%','50%'],children:[{type:'select',id:'linkTargetType',label:D.target,'default':'notSet',style:'width : 100%;',items:[[D.notSet,'notSet'],[E.targetFrame,'frame'],[E.targetPopup,'popup'],[D.targetNew,'_blank'],[D.targetTop,'_top'],[D.targetSelf,'_self'],[D.targetParent,'_parent']],onChange:c,setup:function(F){if(F.target)this.setValue(F.target.type||'notSet');c.call(this);},commit:function(F){if(!F.target)F.target={}; +F.target.type=this.getValue();}},{type:'text',id:'linkTargetName',label:E.targetFrameName,'default':'',setup:function(F){if(F.target)this.setValue(F.target.name);},commit:function(F){if(!F.target)F.target={};F.target.name=this.getValue().replace(/\W/gi,'');}}]},{type:'vbox',width:'100%',align:'center',padding:2,id:'popupFeatures',children:[{type:'fieldset',label:E.popupFeatures,children:[{type:'hbox',children:[{type:'checkbox',id:'resizable',label:E.popupResizable,setup:r,commit:u},{type:'checkbox',id:'status',label:E.popupStatusBar,setup:r,commit:u}]},{type:'hbox',children:[{type:'checkbox',id:'location',label:E.popupLocationBar,setup:r,commit:u},{type:'checkbox',id:'toolbar',label:E.popupToolbar,setup:r,commit:u}]},{type:'hbox',children:[{type:'checkbox',id:'menubar',label:E.popupMenuBar,setup:r,commit:u},{type:'checkbox',id:'fullscreen',label:E.popupFullScreen,setup:r,commit:u}]},{type:'hbox',children:[{type:'checkbox',id:'scrollbars',label:E.popupScrollBars,setup:r,commit:u},{type:'checkbox',id:'dependent',label:E.popupDependent,setup:r,commit:u}]},{type:'hbox',children:[{type:'text',widths:['50%','50%'],labelLayout:'horizontal',label:D.width,id:'width',setup:r,commit:u},{type:'text',labelLayout:'horizontal',widths:['50%','50%'],label:E.popupLeft,id:'left',setup:r,commit:u}]},{type:'hbox',children:[{type:'text',labelLayout:'horizontal',widths:['50%','50%'],label:D.height,id:'height',setup:r,commit:u},{type:'text',labelLayout:'horizontal',label:E.popupTop,widths:['50%','50%'],id:'top',setup:r,commit:u}]}]}]}]},{id:'upload',label:E.upload,title:E.upload,hidden:true,filebrowser:'uploadButton',elements:[{type:'file',id:'upload',label:D.upload,style:'height:40px',size:29},{type:'fileButton',id:'uploadButton',label:D.uploadSubmit,filebrowser:'info:url','for':['upload','upload']}]},{id:'advanced',label:E.advanced,title:E.advanced,elements:[{type:'vbox',padding:1,children:[{type:'hbox',widths:['45%','35%','20%'],children:[{type:'text',id:'advId',label:E.id,setup:s,commit:v},{type:'select',id:'advLangDir',label:E.langDir,'default':'',style:'width:110px',items:[[D.notSet,''],[E.langDirLTR,'ltr'],[E.langDirRTL,'rtl']],setup:s,commit:v},{type:'text',id:'advAccessKey',width:'80px',label:E.acccessKey,maxLength:1,setup:s,commit:v}]},{type:'hbox',widths:['45%','35%','20%'],children:[{type:'text',label:E.name,id:'advName',setup:s,commit:v},{type:'text',label:E.langCode,id:'advLangCode',width:'110px','default':'',setup:s,commit:v},{type:'text',label:E.tabIndex,id:'advTabIndex',width:'80px',maxLength:5,setup:s,commit:v}]}]},{type:'vbox',padding:1,children:[{type:'hbox',widths:['45%','55%'],children:[{type:'text',label:E.advisoryTitle,'default':'',id:'advTitle',setup:s,commit:v},{type:'text',label:E.advisoryContentType,'default':'',id:'advContentType',setup:s,commit:v}]},{type:'hbox',widths:['45%','55%'],children:[{type:'text',label:E.cssClasses,'default':'',id:'advCSSClasses',setup:s,commit:v},{type:'text',label:E.charset,'default':'',id:'advCharset',setup:s,commit:v}]},{type:'hbox',widths:['45%','55%'],children:[{type:'text',label:E.rel,'default':'',id:'advRel',setup:s,commit:v},{type:'text',label:E.styles,'default':'',id:'advStyles',setup:s,commit:v}]}]}]}],onShow:function(){var F=this.getParentEditor(),G=F.getSelection(),H=null; +if((H=b.getSelectedLink(F))&&H.hasAttribute('href'))G.selectElement(H);else H=null;this.setupContent(p.apply(this,[F,H]));},onOk:function(){var F={},G=[],H={},I=this,J=this.getParentEditor();this.commitContent(H);switch(H.type||'url'){case 'url':var K=H.url&&H.url.protocol!=undefined?H.url.protocol:'http://',L=H.url&&CKEDITOR.tools.trim(H.url.url)||'';F['data-cke-saved-href']=L.indexOf('/')===0?L:K+L;break;case 'anchor':var M=H.anchor&&H.anchor.name,N=H.anchor&&H.anchor.id;F['data-cke-saved-href']='#'+(M||N||'');break;case 'email':var O,P=H.email,Q=P.address;switch(y){case '':case 'encode':var R=encodeURIComponent(P.subject||''),S=encodeURIComponent(P.body||''),T=[];R&&T.push('subject='+R);S&&T.push('body='+S);T=T.length?'?'+T.join('&'):'';if(y=='encode'){O=["javascript:void(location.href='mailto:'+",B(Q)];T&&O.push("+'",x(T),"'");O.push(')');}else O=['mailto:',Q,T];break;default:var U=Q.split('@',2);P.name=U[0];P.domain=U[1];O=['javascript:',A(P)];}F['data-cke-saved-href']=O.join('');break;}if(H.target)if(H.target.type=='popup'){var V=["window.open(this.href, '",H.target.name||'',"', '"],W=['resizable','status','location','toolbar','menubar','fullscreen','scrollbars','dependent'],X=W.length,Y=function(ai){if(H.target[ai])W.push(ai+'='+H.target[ai]);};for(var Z=0;Z