仿照eXcell_link 实现多个超级链接
/*
muti links
多个超级链接
@author
[email protected]
@date 2009-01-19
The corresponding cell value in XML should be a "^" delimited list of following values:
1st - Link Text (or "img:image_src")
2nd - URL (optional)
3rd - target (optional, default is _blank)
Samples:
<cell>Stephen King</cell>
<cell>Stephen King^http://www.stephenking.com/</cell>
<cell>Stephen King^http://www.stephenking.com/^_self</cell>
<cell>text1,text2^http://news.sina.com.cn^ ^aaaa^http://news.21cn.com^</cell>
<cell>text1,text2^http://news.sina.com.cn^_self^aaaa^http://news.21cn.com^_blank</cell>
*/
function eXcell_link2(cell){
this.cell = cell;
this.myValue = "";
this.grid = this.cell.parentNode.grid;
this.edit = function(){}
this.getValue = function(){
if(this.cell.firstChild.getAttribute){
if(this.myValue!=""){
return this.myValue;
}
return this.cell.firstChild.innerHTML+"^"+this.cell.firstChild.getAttribute("href")
}
else
return "";
}
this.setValue = function(val){
var flag = true;
var valsAr = val.split("^");
this.myValue = "";
//alert('----valsAr.length===' +valsAr.length);
if(valsAr.length==1){
valsAr[1] = "";
}
else{
if(valsAr.length>1){
if(valsAr.length<4){
valsAr[1] = "href='"+valsAr[1]+"'";
}
if(valsAr.length==3)
valsAr[1]+= " target='"+valsAr[2]+"'";
else if(valsAr.length<3){
valsAr[1]+= " target='_blank'";
}
else if(valsAr.length>3){
this.myValue= val;
var i= valsAr.length % 3;
if(i>0){
i=1;
}
//alert('>3----valsAr.length====' +valsAr.length);
var j= (valsAr.length - valsAr.length % 3 )/3 + i;
var div = "";
var myTarget ="";
var k0,k1,k2;
for(var k=1;k<= j;k++){
k0 = (k-1)*3;
k1 = (k-1)*3+1;
k2 = (k-1)*3+2;
//alert('valsAr[k2]='+valsAr[k2])
if(!valsAr[k2]){
valsAr[k2] ="'_blank'";
}
else{
//alert('valsAr[k2]='+valsAr[k2]+"--xxx==" +valsAr[k2].length);
valsAr[k2] = valsAr[k2].replace(/(^\s*)/g, "");
// alert('valsAr[k2]='+valsAr[k2]+"--xxx==" +valsAr[k2].length);
if(valsAr[k2]==null || valsAr[k2]=='' ||valsAr[k2]==' ' ||valsAr[k2].length<1){
valsAr[k2] ='_blank';
}
valsAr[k2] ="'" +valsAr[k2] + "'";
}
if(k>1){
div = div + " "
}
div = div + "<a href='" + valsAr[k1] + "' " ;
div = div + " target=" + valsAr[k2 ] + ">" + valsAr[k0] + " </a>"
}
this.setCValue(div,valsAr);
//alert('content=' + div);
flag = false;
// this.cell.innerHTML = '<div>' + div +'</div>';
}
}
}
if(flag){
this.setCValue("<a "+valsAr[1]+" onclick='(isIE()?event:arguments[0]).cancelBubble = true;'>"+valsAr[0]+"</a>",valsAr);
}
}
}
eXcell_link2.prototype = new eXcell;
eXcell_link2.prototype.getTitle=function(){
return this.cell.firstChild.getAttribute("href");
}