?? alai_tree.js
字號:
/*******************************************************************************
阿賴目錄樹控件程序 由賴國欣設計于2003年6月,保留所有權利!
*********************************************************************************/
function alai_imagelist()
{try{
var item=[]
count=0
this.path=""
this.type="gif"
this.err=""
iml=this
this.copywrite="Copywrite by Alai(賴國欣) (c)2003,All right reserved!"
this.add=function(src,key)
{
var img=new Image()
if(src==null || src=="")return
if(src.indexOf("/")==-1)src=iml.path+src
if(!(/\.gif$|\.jpg$|\.png$|\.bmp$/i).test(src))src+="."+iml.type
if(key==null || key=="")key=src.replace(/(.*\/){0,}([^\.]+).*/ig,"$2")
item[count]=img;img.index=count;item[key]=img;count++;
img.onerror=function()
{
alert("alai_imagelist cause run time error:\nImage file "+img.src+" not found!")
item[img.index]=null;item[key]=null;count--;
}
img.src=src
return img
}
this.item=item
this.count=function(){return count;}
}
catch(e){
iml.err="alai_imagelist cause run time error!\nError number:"+e.number+".\nError description:"+e.description;
iml.err+="\n -- \nYou can send the case and error description message to A@lai.com.cn for support.Please visit http://www.9499.net to get the last release!"
alert(iml.err);
return iml;
}
}
function alai_tree(imageList,indent,toObject,labelStyle)
{try{
if(!document.getElementById){throw new Error(999,"Your browser dosen't support Alai_tree(),IE5.0+ is recommended.");}
var count=0,depth=0,nodes=[],tree=this
this.copywrite="Copywrite by Alai(賴國欣) (c)2003,All right reserved!"
this.err=""
imageList=imageList==null?new alai_imagelist():imageList
var icons=imageList.item
this.imageList=imageList
if(icons["default"]!=null){if(icons["link"]==null)icons["link"]=icons["default"]}
var showExpand=icons["expand"]!=null && icons["collapse"]!=null
if(showExpand)
{ if(icons["expand_top"]==null)icons["expand_top"]=icons["expand"]
if(icons["expand_end"]==null)icons["expand_end"]=icons["expand"]
if(icons["collapse_top"]==null)icons["collapse_top"]=icons["collapse"]
if(icons["collapse_end"]==null)icons["collapse_end"]=icons["collapse"]
}
var showBranch=icons["leaf"]!=null && icons["twig"]!=null
var showLine=icons["line"]!=null && icons["blank"]!=null
var root={}
root.children=[]
root.expanded=true;
root.getTier=function(){return 0;}
var selectedNode=null,activeNode=null;
Array.prototype.remove=function(index){if(index<0 || index>=this.length)return;for(var i=index;i<this.length;i++)this[i]=this[i+1];this.length--;}
Array.prototype.indexOf=function(elm){for(var i=0;i<this.length;i++)if(elm==this[i])return i;return -1;}
var setExIcon=function(srcNode)
{ if(srcNode.hasChild && showExpand)
{ var sEx=srcNode.next==null?"_end":"";
if(srcNode==nodes[0])sEx="_top";
srcNode.exIcon.src=srcNode.expanded?icons["collapse"+sEx].src:icons["expand"+sEx].src;
srcNode.icon.style.marginLeft=0;
}
else
{ if(showBranch){srcNode.exIcon.src=srcNode.next==null?icons["twig"].src:icons["leaf"].src}
else if(showExpand){srcNode.icon.style.marginLeft=icons["expand"].width}
}
}
var setLine=function(srcNode,idx)
{ if(srcNode.hasChild){for(var i=0;i<srcNode.children.length;i++){srcNode.children[i].lineIcon[idx].src=icons["line"].src;setLine(srcNode.children[i],idx)}}
}
var doSelect=function(srcNode)
{ if(selectedNode!=null){selectedNode.label.style.background="";selectedNode.label.style.color="black";}
srcNode.label.style.background="highlight";srcNode.label.style.color="highlighttext";
selectedNode=srcNode
}
var doFocus=function(srcNode)
{ if(srcNode==selectedNode){srcNode.label.style.background="highlight";srcNode.label.style.color="highlighttext";}
activeNode=srcNode
}
var doBlur=function(srcNode)
{ if(srcNode==selectedNode){srcNode.label.style.background="buttonface";srcNode.label.style.color="windowtext";}
activeNode=null
}
var run=function(cmd,a0,a1,a2)
{
if(typeof(cmd)=="string")
{ try{return eval(cmd);}
catch(E){alert("run script string error:\n"+cmd);}
}
else if(typeof(cmd)=="function"){return cmd(a0,a1,a2);}
}
var doKeyDown=function(srcNode)
{ event.returnValue=false;
switch(event.keyCode)
{ case 38:
if(srcNode.prev==null){if(srcNode.parent!=root){srcNode.parent.focus();srcNode.parent.select();}}
else{var node=srcNode.prev;while(true){if(!node.hasChild || !node.expanded)break;node=node.last;} node.focus();node.select();}
break;
case 40:
if(srcNode.first!=null && srcNode.expanded){srcNode.first.focus();srcNode.first.select();}
else{var node=srcNode;while(true){if(node.next!=null || node.parent==root)break;node=node.parent}if(node.next!=null){node.next.focus();node.next.select();}}
break;
case 189: ;case 109: ;case 37: srcNode.expand(false);break;
case 107: ;case 187: ;case 39: srcNode.expand(true);break;
case 13: srcNode.click();break;
case 27: srcNode.blur();break;
}
}
var addNode=function(toNode,relation,text,key,ico,exeCategory,exeArg)
{
var node={}
var nbody=document.createElement("span")
var container=document.createElement("div")
container.insertAdjacentElement("afterBegin",nbody)
var tier
if(relation==null)relation="last"
if(toNode==root && (relation!="first" && relation!="last"))relation="last"
relation=relation.toLowerCase()
node.first=node.last=node.next=node.prev=null
switch(relation)
{ case "first":
tier=toNode.getTier()+1
if(toNode.hasChild){toNode.children[0].container.insertAdjacentElement("beforeBegin",container);}
else {toNode.container.insertAdjacentElement("beforeEnd",container)}
node.parent=toNode
toNode.children[toNode.children.length]=node
if(toNode.hasChild){node.next=toNode.first;toNode.first.prev=node;toNode.first=node;}
else{toNode.first=toNode.last=node;}
break;
case "next":
tier=toNode.getTier()
toNode.container.insertAdjacentElement("afterEnd",container)
node.parent=toNode.parent
toNode.parent.children[toNode.parent.children.length]=node
if(toNode.next==null)node.parent.last=node
node.next=toNode.next;node.prev=toNode;toNode.next=node;
break;
case "prev":
tier=toNode.getTier()
toNode.container.insertAdjacentElement("beforeBegin",container)
node.parent=toNode.parent
toNode.parent.children[toNode.parent.children.length]=node
if(toNode.prev==null)node.parent.first=node
node.prev=toNode.prev;node.next=toNode;toNode.prev=node
break;
default:
tier=toNode.getTier()+1
toNode.children[toNode.children.length]=node
var o=toNode==root?tree.body:toNode.container
o.insertAdjacentElement("beforeEnd",container)
node.parent=toNode
if(toNode.hasChild){node.prev=toNode.last;toNode.last.next=node;toNode.last=node;}
else{toNode.first=toNode.last=node;}
}
node.parent.hasChild=true
if(depth<tier)depth=tier;
var label=document.createElement("span")
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -