Index: openacs-4/packages/acs-templating/www/resources/xinha-nightly/modules/CreateLink/pluginMethods.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/www/resources/xinha-nightly/modules/CreateLink/pluginMethods.js,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-templating/www/resources/xinha-nightly/modules/CreateLink/pluginMethods.js 27 Mar 2009 08:20:43 -0000 1.2 +++ openacs-4/packages/acs-templating/www/resources/xinha-nightly/modules/CreateLink/pluginMethods.js 23 May 2010 11:58:33 -0000 1.3 @@ -1,3 +1,165 @@ -/* This compressed file is part of Xinha. For uncompressed sources, forum, and bug reports, go to xinha.org */ -/* This file is part of version 0.96beta2 released Fri, 20 Mar 2009 11:01:14 +0100 */ -CreateLink.prototype.show=function(c){if(!this.dialog){this.prepareDialog()}var d=this.editor;this.a=c;if(!c&&this.editor.selectionEmpty(this.editor.getSelection())){alert(this._lc("You need to select some text before creating a link"));return false}var b={f_href:"",f_title:"",f_target:"",f_other_target:""};if(c&&c.tagName.toLowerCase()=="a"){b.f_href=this.editor.fixRelativeLinks(c.getAttribute("href"));b.f_title=c.title;if(c.target){if(!/_self|_top_|_blank/.test(c.target)){b.f_target="_other";b.f_other_target=c.target}else{b.f_target=c.target;b.f_other_target=""}}}this.dialog.show(b)};CreateLink.prototype.apply=function(){var m=this.dialog.hide();var l=this.a;var h=this.editor;var k={href:"",target:"",title:""};if(m.f_href){k.href=m.f_href;k.title=m.f_title;if(m.f_target.value){if(m.f_target.value=="other"){k.target=m.f_other_target}else{k.target=m.f_target.value}}}if(m.f_target.value){if(m.f_target.value!="_other"){k.target=m.f_target.value}else{k.target=m.f_other_target}}if(l&&l.tagName.toLowerCase()=="a"){if(!k.href){if(confirm(this._lc("Are you sure you wish to remove this link?"))){var c=l.parentNode;while(l.hasChildNodes()){c.insertBefore(l.removeChild(l.childNodes[0]),l)}c.removeChild(l);h.updateToolbar();return}}else{for(var f in k){l.setAttribute(f,k[f])}if(Xinha.is_ie){if(/mailto:([^?<>]*)(\?[^<]*)?$/i.test(l.innerHTML)){l.innerHTML=RegExp.$1}}}}else{if(!k.href){return true}var g=Xinha.uniq("http://www.example.com/Link");h._doc.execCommand("createlink",false,g);var b=h._doc.getElementsByTagName("a");for(var f=0;f]*)(\?[^<]*)?$/i.test(a.innerHTML)) + { + a.innerHTML = RegExp.$1; + } + } + } + } + else + { + if(!atr.href) return true; + + // Insert a link, we let the browser do this, we figure it knows best + var tmp = Xinha.uniq('http://www.example.com/Link'); + editor._doc.execCommand('createlink', false, tmp); + + // Fix them up + var anchors = editor._doc.getElementsByTagName('a'); + for(var i = 0; i < anchors.length; i++) + { + var anchor = anchors[i]; + if(anchor.href == tmp) + { + // Found one. + if (!a) a = anchor; + for(var j in atr) + { + anchor.setAttribute(j, atr[j]); + } + } + } + } + editor.selectNodeContents(a); + editor.updateToolbar(); +}; +CreateLink.prototype._getSelectedAnchor = function() +{ + var sel = this.editor.getSelection(); + var rng = this.editor.createRange(sel); + var a = this.editor.activeElement(sel); + if(a != null && a.tagName.toLowerCase() == 'a') + { + return a; + } + else + { + a = this.editor._getFirstAncestor(sel, 'a'); + if(a != null) + { + return a; + } + } + return null; +}; \ No newline at end of file