📄 tree_maker.js
字号:
this.getType=function getType(){
return this.action.type;
}
this.getLink=function getLink(){
return this.action.link;
}
this.getTarget=function getTarget(){
return this.action.target;
}
this.getScript=function getScript(){
return this.action.script;
}
//------------
this.getTreeView=function getTreeView(){
return Tree_treeView_array[this.action.treeViewIndex];
}
//---------
this.delChild=function delChild(index)
{
if(index>this.childCount-1 || index<0)
return;
var len=this.childCount-1;
var tree=this.getTreeView();
if(tree.isReady())//refresh
{
var div=document.getElementById("Tree_expand_"+ this.child[index].id).parentNode;
div.parentNode.removeChild(div);
if(this.childCount==1&&this.parent)
{
this.childCount--;
var img = this.getImage();
if(img) img.src=Tree_imgSrc(this);
this.childCount++;
}
if(index==this.childCount-1 &&index>0){
this.childCount--;
var node=this.child[index-1];
var line=document.getElementsByName("Tree_td_line_"+ node.id);
for(var i=line.length-1;i>=0;i--)
line[i].innerHTML="<IMG style='width:19px;height:20px;visibility:hidden'>";
line=document.getElementById("Tree_line_"+node.id);
if(line) line.src=Tree_GetLineImg(node);
this.childCount++;
}
if(this.childCount==1){
this.childCount--;
var line=document.getElementById("Tree_line_"+ this.id);
if(line) line.src=Tree_GetLineImg(this);
document.getElementById("Tree_expand_"+this.id).style.display="none";
this.childCount++;
}
}
if(this.child[index].contain(tree.selectID))//select node will be deleted
tree.selectID=null;
Tree_node_array[this.child[index].id]=null;
while(index<=len-1)//move element
{
this.child[index+1].index=index;
this.child[index]=this.child[index+1];
index++;
}
this.child.length=(--this.childCount);
}
//--------------
this.getHtml=function getHtml()
{
var html="";
if(this.parent)
{
var tree=this.getTreeView();
html+="<DIV>";
html+=Tree_table(this);
html+="<DIV id=Tree_expand_"+ this.id+
" STYLE='{display:"+(this.expanded?"block;":"none;")+"}'>";
}
if(this.childCount>0) {//folder
for(var i=0;i<=this.childCount-1;i++)
{
html+=this.child[i].getHtml();
}
}
if(this.parent)html+="</DIV></DIV>";
return html;
}
//----------
this.setText=function setText(text){
var td=document.getElementById("Tree_td_"+this.id);
if(td)
td.innerHTML=this.text=text;
}
//---
this.expand=function expand(toExpand){
this.getTreeView().expand(this.id,toExpand);
}
//--
this.click=function click() {
this.getTreeView().click(this.id);
}
//--
this.select=function select(flag) {
this.getTreeView().select(this.id,flag);
}
}
//--------------------
function Tree_on_action(action)//fire when click node
{
if(action.type==Tree_LINK)//link
{
var target = action.target;
if(target=="")//default target
{
target = Tree_treeView_array[action.treeViewIndex].target;
}
if( target=="_self"||target=="_top"||target=="_parent"||target=="_blank")
window.open(action.link,target);
else
{
var command = target +".location = action.link";
if(action.link!="") try{eval(command);}catch(e){alert("脚本运行错误\r\n\r\n"+e.description);}
}
}
else if(action.type==Tree_SCRIPT)//run script
{
try{eval(action.script);}catch(e){alert("脚本运行错误\r\n\r\n"+e.description);}
}
}
//----------------
function Tree_selectNode(nodeID)
{
var node=Tree_node_array[nodeID];
if(node==null||node.parent==null)return;
var tree=node.getTreeView();
var td=document.getElementById("Tree_td_"+nodeID);
var tdOld=document.getElementById("Tree_td_"+tree.selectID);
node.selected=true;//select node
if(tree.selectID!=null)
{
Tree_node_array[tree.selectID].selected=false;//unselect node
if(tree.showSelect && tdOld)
tdOld.className=Tree_node_array[tree.selectID].childCount>0?
tree.folderClass1:tree.fileClass1;//reset to normal class
}
tree.selectID=nodeID;
if(tree.showSelect && td)
td.className=Tree_node_array[tree.selectID].childCount>0?
tree.folderClass3:tree.fileClass3;
}
//--------------------
function Tree_clickNode(nodeID)
{
var node=Tree_node_array[nodeID];
if(node==null||node.parent==null)return;//root
var tree=node.getTreeView();
var div=document.getElementById("Tree_expand_"+nodeID);
var img=document.getElementById("Tree_img_"+nodeID);
var td=document.getElementById("Tree_td_"+nodeID);
//---------
if(!node.expanded && node.childCount>0 &&tree.flag==false)
if(tree.callback_expanding(nodeID)==false)//cancel expand
return;
if(node.expanded && node.childCount>0 &&tree.flag==false)
if(tree.callback_collapsing(nodeID)==false)//cancel collapse
return;
node.expanded=!node.expanded && node.childCount>0;
if(tree.flag==false)Tree_selectNode(nodeID);
if(node.childCount>0)//folder
{
if(div)div.style.display=node.expanded?"block":"none";
if(img) img.src=Tree_imgSrc(node);
var line=document.getElementById("Tree_line_"+nodeID);
if(line)line.src=Tree_GetLineImg(node);
}
if(tree.callback_click(nodeID)==true &&tree.flag==false)//do action
Tree_on_action(node.action);
//------
if(node.expanded && node.childCount>0 &&tree.flag==false)
tree.callback_expanded(nodeID);
if(!node.expanded && node.childCount>0 &&tree.flag==false)
tree.callback_collapsed(nodeID);
}
//----------------------------
function Tree_buildTree(node,treeView)//init treeView from array
{
Tree_treeView_array[treeView.id]=treeView;
treeView.flag=true;
var nLen = node.length-1;
var index = 0;
var count = 0;
var nodeChild=null;
var nodeParent=null;
while( index <= nLen )
{
switch( node[index] ){
case Tree_const_end:
break;
case Tree_const_begin_folder:
count++;
break;
case Tree_const_end_folder:
nodeParent=nodeParent.parent;
count--;
break;
case Tree_const_file:
var action = new Tree_action(node[index+5],node[index+6],node[index+7],node[index+8],treeView.id);
nodeChild=new Tree_node(node[index+1],node[index+2],node[index+3],node[index+4],node[index+4],action);
if(count==0) treeView.container.add(nodeChild,Tree_LAST);
else nodeParent.add(nodeChild,Tree_LAST);
break;
case Tree_const_folder:
var action = new Tree_action(node[index+6],node[index+7],node[index+8],node[index+9],treeView.id);
nodeChild=new Tree_node(node[index+1],node[index+2],node[index+3],node[index+4],node[index+5],action);
if(count==0) treeView.container.add(nodeChild,Tree_LAST);
else nodeParent.add(nodeChild,Tree_LAST);
nodeParent=nodeChild;
break;
}
index ++;
}
treeView.flag=false;
treeView.refresh();
}
//---------
function Tree_imgSrc(node)
{
var tree=node.getTreeView();
var src1=node.img1.length>0?node.img1:tree.folderImg1;
var src2=node.img2.length>0?node.img2:tree.folderImg2;
var src3=node.img1.length>0?node.img1:tree.fileImg;
return node.childCount>0?(node.expanded?src2:src1):src3;
}
//-------------------------------------------
function Tree_img(node)
{
var src=Tree_imgSrc(node);
if( node.getTreeView().useImage && src.length > 0 )
return ("<IMG style='cursor: pointer;cursor: hand;' SRC=\"" + src + "\" id='Tree_img_"+node.id+"'></IMG>");
return "";
}
//-------------
function Tree_table(node)
{
var tree=node.getTreeView();
var html="<TABLE border=0 cellspacing=0 cellpadding=0 ><TBODY><TR>";
var level=node.level();var count=1;
if(tree.showLine){
while(count<level){
var parent=node.getParentEx(count++);
if( parent && parent.index==parent.parent.childCount-1)
html+="<TD NAME=Tree_td_line_"+parent.id+" id=Tree_td_line_"+parent.id+"><IMG style='width:19px;height:20px;visibility:hidden'></TD>";
else html+="<TD NAME=Tree_td_line_"+parent.id+" id=Tree_td_line_"+parent.id+"><IMG src="+tree.lineFolder+"tree_I.gif></TD>";
}
html+="<TD oncontextmenu='return Tree_treeView_array["+tree.id+"].callback_rightClick("+node.id+
")' onclick=Tree_clickNode("+node.id+") style='cursor: pointer;cursor: hand;'>"+
"<IMG id=Tree_line_"+node.id+" src="+Tree_GetLineImg(node)+"></TD>";
}
else {
while(count++<level){
html+="<TD><IMG style='height:0;width:"+tree.Indent+"pt;visibility:hidden'></TD>";
}
}
html+="<TD oncontextmenu='return Tree_treeView_array["+tree.id+"].callback_rightClick("+node.id+
")' onclick=Tree_clickNode("+node.id+")>"+Tree_img(node)+"</TD>";
html+=Tree_td(node)+"</TR></TBODY></TABLE>";
return html;
}
//-------------------------------------------
function Tree_td(node)
{
var tree=node.getTreeView();
var ret = "<TD oncontextmenu='return Tree_treeView_array["+tree.id+"].callback_rightClick("+node.id+
")' onclick=Tree_clickNode("+node.id+") style='cursor: pointer;cursor: hand;' NOWRAP id='Tree_td_"+node.id+"' onmouseover=Tree_mouseover(this,"+node.id+
") onmouseout=Tree_mouseout(this,"+node.id+") class=\"";
if(node.childCount>0)//folder
ret += (node.selected?tree.folderClass3:tree.folderClass1)+"\">";
else //file
ret += (node.selected?tree.fileClass3:tree.fileClass1)+"\">";
return (ret+Tree_formatText(node.text)+"</TD>");
}
//--------
function Tree_formatText(text)
{
text=text.replace(/</g,"<");
text=text.replace(/>/g,">");
text=text.replace(/ /g," ");
return text.replace(/\"/g,""");
}
//-------------------------------------------
function Tree_mouseover(obj,nodeID)
{
if(Tree_isIE && document.readyState!="complete") return;
var node=Tree_node_array[nodeID];
var tree = node.getTreeView();
if(node.childCount>0)//folder
obj.className=tree.folderClass2;
else
obj.className=tree.fileClass2;
if(tree.useStatus)
window.status=tree.useTitleAsStatus==false?node.status:
(node.status!=""?node.status:node.text);
obj.title=(tree.useHint==false?"":
(tree.useTitleAsHint==false?node.hint:
(node.hint==""?node.text:node.hint)));
}
//-------------------------------------------
function Tree_mouseout(obj,nodeID)
{
if(Tree_isIE && document.readyState!="complete") return;
var node=Tree_node_array[nodeID];
var tree = node.getTreeView();
if(tree.showSelect && nodeID==tree.selectID )
obj.className = node.childCount>0?tree.folderClass3:tree.fileClass3;
else if(node.childCount>0)//folder
obj.className=tree.folderClass1;
else
obj.className=tree.fileClass1;
}
//-------------------------------------------
function Tree_GetLineImg(node)
{
var tree=node.getTreeView();
if(tree.showLine==false||node.parent==null) return "";
if(node.childCount>0){
if(node.expanded)
return tree.lineFolder+((node.index==node.parent.childCount-1)?"tree_Lminus.gif":"tree_Tminus.gif");
else
return tree.lineFolder+((node.index==node.parent.childCount-1)?"tree_Lplus.gif":"tree_Tplus.gif");
}
else return tree.lineFolder+((node.index==node.parent.childCount-1)?"tree_L.gif":"tree_T.gif");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -