?? i_treebuilder.asp
字號:
<%
' COPYRIGHT NOTICE
' Copyright 2003 David Swigger All Rights Reserved.
' email : dswigger@yahoo.com
'
' i_treebuilder.asp may be used and modified free of charge by anyone so long as
' this copyright notice remains intact. By using this
' code you agree to indemnify David Swigger from any liability that
' might arise from its use.
'
' Selling the code for this script without prior written consent is
' expressly forbidden.
' (END OF COPYRIGHT NOTICE)
' If you add something useful to this,improve it, or use it in something really
' interesting then please send me a note.
%>
<STYLE>
DIV.tree_parent
{
font-family : Arial, serif;
font-size : 12px;
font-weight : normal;
color: black;
cursor: hand;
}
DIV.tree_child
{
font-family : Arial, serif;
font-size : 12px;
font-weight : normal;
display:none;
}
.tree_icon
{
margin-right: 5 ;
}
A.tree_pitem
{
color: black;
text-decoration:none;
cursor: hand;
}
A.tree_pitem:HOVER {
color: blue;
}
A.tree_citem
{
color: black;
text-decoration:none;
cursor: hand;
}
A.tree_citem:HOVER {
color: blue;
}
SPAN.tree_data {
visibility : hidden;
display :none;
z-index : 0;
}
</STYLE>
<script language="javascript">
// preload the tree images.... (add any specials)
var bTreeMultiSelect = false;
var bTreeAllowDeselect = false;
var oTreeLastSelectedItem = null;
var oTreeLastSelectedData = null;
var TreeItemDispatch=null;
var Img1 = new Image();Img1.src = "images/tree/I.gif";
var Img2 = new Image();Img2.src = "images/tree/L.gif";
var tree_lMinus = new Image();tree_lMinus.src = "images/tree/Lminus.gif";
var tree_lPlus = new Image();tree_lPlus.src = "images/tree/Lplus.gif";
var Img5 = new Image();Img5.src = "images/tree/T.gif";
var tree_TMinus = new Image();tree_TMinus.src = "images/tree/Tminus.gif";
var tree_TPlus = new Image();tree_TPlus.src = "images/tree/Tplus.gif";
var Img8 = new Image();Img8.src = "images/tree/white.gif";
// expand or collapse function
function tree_iconclick(sNodeID)
{
oChild = document.getElementById(sNodeID + "Child");
oController_O = document.getElementById(sNodeID + "_o");
if (oChild.style.display == "none" || oChild.style.display =="")
{
// expanding (which means it has a plus next to it right now)
oChild.style.display= "block";
if(oController_O.src == tree_TPlus.src)
oController_O.src = tree_TMinus.src;
else
oController_O.src = tree_lMinus.src;
}
else
{
// Collapse (has minus next to it)
oChild.style.display= "none";
if(oController_O.src == tree_TMinus.src)
oController_O.src = tree_TPlus.src;
else
oController_O.src = tree_lPlus.src;
}
}
// Item click
function tree_itemclick(sNodeID,sKey)
{
//background : #C5C5C5;
oItem = document.getElementById(sNodeID + "Item");
oItemData = document.getElementById(sNodeID + "Data");
// See if its selected....
if(oItemData.style.zIndex == 0)// nope
{
oItemData.style.zIndex =1;
oItem.style.background = "#C5C5C5";
if(!bTreeMultiSelect && oTreeLastSelectedItem != null)
{
// deselect the last one
oTreeLastSelectedData.style.zIndex =0;
oTreeLastSelectedItem.style.background = "#FFFFFF";
TreeItemDispatch(false,false,oTreeLastSelectedData.innerText);
}
oTreeLastSelectedItem = oItem;
oTreeLastSelectedData =oItemData;
TreeItemDispatch(false,true,oItemData.innerText);
}
else// yup
{
if(bTreeAllowDeselect)
{
oItemData.style.zIndex =0;
oItem.style.background = "#FFFFFF";
TreeItemDispatch(false,false,oItemData.innerText);
oTreeLastSelected = null;
oTreeLastSelectedData =null;
}
else
TreeItemDispatch(true,true,oItemData.innerText);
}
}
// Generic tree item function handler
// use as prototype then assign your own after including the script....
function def_TreeItemDispatch(bReslect,bSelected,sKey)
{
if(bSelected || bReslect)
{
alert(sKey);
}
}
// assign default
TreeItemDispatch = def_TreeItemDispatch;
</script>
<%
'========================================================================================================
' Tree Builder variables
'========================================================================================================
Const tTRUE = 1
Const tFALSE = 0
Dim arrBranches(10)' maximum depth of tree before page will bomb
Dim arrBTypes(10,2)' 10 different types of branches can be made.....
Dim arrLTypes(10,2)' 10 different types of leaves can be made.....
Dim arrSpacers(2)
Dim itree_depth
Dim itree_exdp
Dim iTreeID
Dim sBranchlst
Dim sBranch
Dim sLeaf
Dim sLeaflst
Dim sTreeTop
Dim sTree
sTreeTop = "<div ID=""mParent"" class=parent><img name=""mTree"" src=""~icon~"" class=icon align=""absmiddle"" border=0>~txt~</div><div ID=""mChild"">"
arrSpacers(0) = "<img src=""images/tree/I.gif"" align=""absmiddle"">"
arrSpacers(1) = "<img src=""images/tree/white.gif"" align=""absmiddle"">"
sLeaf = "<DIV>~hist~<img src=""images/tree/T.gif"" align=""absmiddle""><img src=""~icon~"" align=""absmiddle"" class=""tree_icon"" border=0><a HREF=""#"" ID=""m~id~Item"" onClick=""tree_itemclick('m~id~')"" class=tree_citem>~txt~</a><SPAN ID=""m~id~Data"" class=tree_data>~key~</SPAN></DIV>"
sLeaflst = "<DIV>~hist~<img src=""images/tree/L.gif"" align=""absmiddle""><img src=""~icon~"" align=""absmiddle"" class=""tree_icon"" border=0><a HREF=""#"" ID=""m~id~Item"" onClick=""tree_itemclick('m~id~','~key~')"" class=tree_citem>~txt~</a><SPAN ID=""m~id~Data"" class=tree_data>~key~</SPAN></DIV>"
sBranchlst = "<div ID=""m~id~Parent"" class=""tree_parent"">~hist~<a name=""m~id~a"" href=""#"" onClick=""tree_iconclick('m~id~')""><img name=""m~id~_o"" src=""images/tree/Lplus.gif"" align=""absmiddle"" border=""0""><img src=""~icon~"" class=""tree_icon"" align=""absmiddle"" border=0></a><a HREF=""#"" ID=""m~id~Item"" onClick=""tree_itemclick('m~id~')"" class=tree_pitem>~txt~</a><SPAN ID=""m~id~Data"" class=tree_data>~key~</SPAN></div><div ID=""m~id~Child"" CLASS=""tree_child"">"
sBranch = "<div ID=""m~id~Parent"" class=""tree_parent"">~hist~<a name=""m~id~a"" href=""#"" onClick=""tree_iconclick('m~id~')""><img name=""m~id~_o"" src=""images/tree/Tplus.gif"" align=""absmiddle"" border=""0""><img src=""~icon~"" class=""tree_icon"" align=""absmiddle"" border=0></a><a HREF=""#"" ID=""m~id~Item"" onClick=""tree_itemclick('m~id~')"" class=tree_pitem>~txt~</a><SPAN ID=""m~id~Data"" class=tree_data>~key~</SPAN></div><div ID=""m~id~Child"" CLASS=""tree_child"">"
'========================================================================================================
' Tree Builder functions I am assuming the top item will NOT be dynamic
'========================================================================================================
' register a branch type....
function tree_RegisterBranchType(nType,strImgSrc)
arrBTypes(nType,0) = replace(sBranch,"~icon~",strImgSrc)
arrBTypes(nType,1) = replace(sBranchlst,"~icon~",strImgSrc)
end function
' register a leaf type....
function tree_RegisterLeafType(nType,strImgSrc)
arrLTypes(nType,0) = replace(sLeaf,"~icon~",strImgSrc)
arrLTypes(nType,1) = replace(sLeaflst,"~icon~",strImgSrc)
end function
'Write out start node
function tree_Start(sNodeText,sTopImgSrc)
sTree = replace(sTreeTop,"~icon~",sTopImgSrc)
sTree = replace(sTree,"~txt~",sNodeText)
itree_depth = 0
itree_exdp = 1
iTreeID =1
end function
' end
function tree_End()
sTree = sTree & "</div>"
Response.Write sTree'"</div>"
sTree=""
end function
' tree_StartBranch
function tree_StartBranch(nType,nIsLast,sNodeText,sKey)
sItem = replace(arrBTypes(nType,nIsLast),"~id~",iTreeID)
sItem = replace(sItem,"~hist~",arrBranches(itree_depth))
sItem = replace(sItem,"~txt~",sNodeText)
sItem = replace(sItem,"~key~",sKey)
'Response.Write sItem
sTree = sTree & sItem
arrBranches(itree_exdp) = arrBranches(itree_depth) & arrSpacers(nIsLast)
itree_depth = itree_depth + 1 ' deeper anda deeper we go
itree_exdp = itree_depth + 1
iTreeID = iTreeID + 1
end function
' Add a leaf to the tree
function tree_AddLeaf(nType,nIsLast,sNodeText,sKey)
sItem = replace(arrLTypes(nType,nIsLast),"~id~",iTreeID)
sItem = replace(sItem,"~hist~",arrBranches(itree_depth))
sItem = replace(sItem,"~txt~",sNodeText)
sItem = replace(sItem,"~key~",sKey)
'Response.Write sItem
sTree = sTree & sItem
iTreeID = iTreeID + 1
end function
' end node (really simple)
function tree_EndBranch()
sTree = sTree & "</div>"
'Response.Write sCurBranch
itree_depth = itree_depth - 1
itree_exdp = itree_depth + 1
end function
%>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -