Tree2.jsp
<% @ Page contenttype = "text/html; charset = gb2312" Language = "Java" %>
<% @ Page import = "Java. SQL. *" %>
<HTML>
<Head>
<Title> #. Admin </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<LINK rel = "stylesheet" href = "CSS/dtree.css" type = "text/CSS">
<SCRIPT type = "text/JavaScript" src = "JS/dtree. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "JS/OP. js"> </SCRIPT>
</Head>
<Body bgcolor = "ffffff" text = "#000000">
<A href = "javascript: D. openall (); "> open all </a> | <a href =" javascript: D. closeall (); "> close all </a>
<SCRIPT type = "text/JavaScript">
<! --
D = new dtree ('D ');
D. config. folderlinks = true;
// ID, PID, name, URL, title, target, icon, iconopen, open
D. Add ("root0",-1, 'system', 'pages/treejs. jsp '); // Add the root node
D. add ("root1", "root0", 'Central device', 'pages/treejs. JSP ', '','', 'images/cd.gif', 'images/cd.gif '); // Add a subnode
D. add ("root2", "root0", 'Central device 2', 'pages/treejs. JSP ', '','', 'images/cd.gif', 'images/cd.gif ');
Document. Write (d );
// -->
</SCRIPT>
</Body>
</Html>
Under the JS folder
Dtree. js
/* -------------------------------------------------- |
| Dtree 2.05 | www.destroydrop.com/javascript/tree/ |
| ------------------------------------------------- |
| Copyright (c) 2002-2003 Geir landr? |
|
| This script can be used freely as long as all |
| Copyright messages are intact. |
|
| Updated: 172.164.2003 |
| --------------------------------------------------*/
// Node object
Function node (ID, PID, name, URL, title, target, icon, iconopen, open ){
This. ID = ID;
This. PID = PID;
This. Name = Name;
This. url = URL;
This. Title = title;
This.tar get = target;
This. Icon = icon;
This. iconopen = iconopen;
This. _ IO = open | false;
This. _ Is = false;
This. _ ls = false;
This. _ Hc = false;
This. _ AI = 0;
This. _ P;
};
// Tree object
Function dtree (objname ){
This. Config = {
Target: NULL,
Folderlinks: True,
Useselection: True,
Usecookies: True,
Uselines: True,
Useicons: True,
Usestatustext: false,
Closesamelevel: false,
Inorder: false
}
This. Icon = {
Root: 'img/base.gif ',
Folder: 'img/folder.gif ',
Folderopen: 'img/folderopen.gif ',
Node: 'img/page.gif ',
Empty: 'img/empty.gif ',
Line: 'img/line.gif ',
Join: 'img/join.gif ',
Joinbottom: 'img/joinbottom.gif ',
Plus: 'img/plus.gif ',
Plusbottom: 'img/plusbottom.gif ',
Minus: 'img/minus.gif ',
Minusbottom: 'img/minusbottom.gif ',
Nlplus: 'img/nolines_plus.gif ',
Nlminus: 'img/nolines_minus.gif'
};
This. OBJ = objname;
This. anodes = [];
This. aindent = [];
This. Root = new node (-1 );
This. selectednode = NULL;
This. selectedfound = false;
This. Completed = false;
};
// Adds a new node to the node Array
Dtree. Prototype. Add = function (ID, PID, name, URL, title, target, icon, iconopen, open ){
This. anodes [This. anodes. Length] = new node (ID, PID, name, URL, title, target, icon, iconopen, open );
};
// Open/close all nodes
Dtree. Prototype. openall = function (){
This. Oall (true );
};
Dtree. Prototype. closeall = function (){
This. Oall (false );
};
// Outputs the tree to the page
Dtree. Prototype. tostring = function (){
VaR STR = '<Div class = "dtree">/N ';
If (document. getelementbyid ){
If (this. config. usecookies) This. selectednode = This. getselected ();
STR + = This. addnode (this. Root );
} Else STR + = 'browser not supported .';
STR + = '</div> ';
If (! This. selectedfound) This. selectednode = NULL;
This. Completed = true;
Return STR;
};
// Creates the Tree Structure
Dtree. Prototype. addnode = function (pnode ){
VaR STR = '';
VaR n = 0;
If (this. config. Inorder) n = pnode. _ AI;
For (N; n <this. anodes. length; n ++ ){
If (this. anodes [N]. PID = pnode. ID ){
VaR Cn = This. anodes [N];
CN. _ p = pnode;
CN. _ AI = N;
This. setcs (CN );
If (! Cn.tar get & this.config.tar get) cn.tar get = this.config.tar get;
If (CN. _ HC &&! CN. _ IO & this. config. usecookies) Cn. _ IO = This. isopen (CN. ID );
If (! This. config. folderlinks & CN. _ HC) Cn. url = NULL;
If (this. config. useselection & CN. ID = This. selectednode &&! This. selectedfound ){
CN. _ Is = true;
This. selectednode = N;
This. selectedfound = true;
}
STR + = This. node (CN, N );
If (CN. _ ls) break;
}
}
Return STR;
};
// Creates the node icon, URL and text
Dtree. Prototype. node = function (node, nodeid ){
VaR STR = '<Div class = "dtreenode">' + this. indent (node, nodeid );
If (this. config. useicons ){
If (! Node. Icon) node. Icon = (this. Root. ID = node. PID )? This. Icon. Root: (node. _ HC )? This. Icon. Folder: This. Icon. node );
If (! Node. iconopen) node. iconopen = (node. _ HC )? This. Icon. folderopen: This. Icon. node;
If (this. Root. ID = node. PID ){
Node. Icon = This. Icon. root;
Node. iconopen = This. Icon. root;
}
STR + = ' ';
}
If (node. url ){
STR + = '<a id = "s' + this. OBJ + nodeid + '" class = "' + (this. config. useselection )? (Node. _ is? 'Nodesel ': 'node') +' "href =" '+ node. url + '"';
If (node. Title) STR + = 'title = "'+ node. Title + '"';
If (node.tar get) STR + = 'target = "'+ node.tar get + '"';
If (this. config. usestatustext) STR + = 'onmouseover = "window. status =/''+ node. name + '/'; return true; "onmouseout =" window. status =/'; return true ;"';
If (this. config. useselection & (node. _ HC & this. config. folderlinks) |! Node. _ HC ))
STR + = 'onclick = "javascript: '+ this. OBJ +'. s ('+ nodeid + ');"';
STR + = '> ';
}
Else if ((! This. config. folderlinks |! Node. url) & node. _ HC & node. PID! = This. Root. ID)
STR + = '<a href = "javascript:' + this. OBJ + '. O (' + nodeid + ');" class = "Node"> ';
STR + = node. Name;
If (node. url | ((! This. config. folderlinks |! Node. url) & node. _ HC) STR + = '</a> ';
STR + = '</div> ';
If (node. _ HC ){
STR + = '<Div id = "D' + this. OBJ + nodeid + '"class =" clip "style =" display:' + (this. root. id = node. PID | node. _ IO )? 'Block': 'None') + '; "> ';
STR + = This. addnode (node );
STR + = '</div> ';
}
This. aindent. Pop ();
Return STR;
};
// Adds the empty and line icons
Dtree. Prototype. indent = function (node, nodeid ){
VaR STR = '';
If (this. Root. ID! = Node. PID ){
For (VAR n = 0; n <this. aindent. length; n ++)
STR + = ' ';
(Node. _ ls )? This. aindent. Push (0): This. aindent. Push (1 );
If (node. _ HC ){
STR + = '<a href = "javascript:' + this. OBJ + '. O ('+ nodeid +'); ">
If (! This. config. uselines) STR + = (node. _ IO )? This. Icon. nlminus: This. Icon. nlplus;
Else STR + = (node. _ IO )? (Node. _ ls & this. config. uselines )? This. Icon. minusbottom: This. Icon. Minus): (node. _ ls & this. config. uselines )? This. Icon. plusbottom: This. Icon. Plus ));
STR + = '"alt =" "/> </a> ';
} Else STR + = ' ';
}
Return STR;
};
// Checks if a node has any children and if it is the last sibling
Dtree. Prototype. setcs = function (node ){
VaR lastid;
For (VAR n = 0; n <this. anodes. length; n ++ ){
If (this. anodes [N]. PID = node. ID) node. _ Hc = true;
If (this. anodes [N]. PID = node. PID) lastid = This. anodes [N]. ID;
}
If (lastid = node. ID) node. _ ls = true;
};
// Returns the selected node
Dtree. Prototype. getselected = function (){
VaR Sn = This. getcookie ('cs '+ this. OBJ );
Return (SN )? SN: NULL;
};
// Highlights the selected node
Dtree. Prototype. S = function (ID ){
If (! This. config. useselection) return;
VaR Cn = This. anodes [ID];
If (CN. _ HC &&! This. config. folderlinks) return;
If (this. selectednode! = ID ){
If (this. selectednode | this. selectednode = 0 ){
Eold = Document. getelementbyid ("S" + this. OBJ + this. selectednode );
Eold. classname = "Node ";
}
Enew = Document. getelementbyid ("S" + this. OBJ + id );
Enew. classname = "nodesel ";
This. selectednode = ID;
If (this. config. usecookies) This. setcookie ('cs '+ this. OBJ, CN. ID );
}
};
// Toggle open or close
Dtree. Prototype. O = function (ID ){
VaR Cn = This. anodes [ID];
This. nodestatus (! CN. _ IO, ID, CN. _ ls );
CN. _ IO =! CN. _ IO;
If (this. config. closesamelevel) This. closelevel (CN );
If (this. config. usecookies) This. updatecookie ();
};
// Open or close all nodes
Dtree. Prototype. Oall = function (Status ){
For (VAR n = 0; n <this. anodes. length; n ++ ){
If (this. anodes [N]. _ HC & this. anodes [N]. PID! = This. Root. ID ){
This. nodestatus (status, N, this. anodes [N]. _ ls)
This. anodes [N]. _ IO = status;
}
}
If (this. config. usecookies) This. updatecookie ();
};
// Opens the tree to a specific node
Dtree. Prototype. opento = function (NID, bselect, bfirst ){
If (! Bfirst ){
For (VAR n = 0; n <this. anodes. length; n ++ ){
If (this. anodes [N]. ID = NID ){
Nid = N;
Break;
}
}
}
VaR Cn = This. anodes [NID];
If (CN. PID = This. Root. ID |! CN. _ p) return;
CN. _ IO = true;
CN. _ Is = bselect;
If (this. Completed & CN. _ HC) This. nodestatus (true, CN. _ AI, CN. _ ls );
If (this. Completed & bselect) This. S (CN. _ AI );
Else if (bselect) This. _ Sn = cn. _ AI;
This. opento (CN. _ p. _ AI, false, true );
};
// Closes all nodes on the same level as certain Node
Dtree. Prototype. closelevel = function (node ){
For (VAR n = 0; n <this. anodes. length; n ++ ){
If (this. anodes [N]. PID = node. PID & this. anodes [N]. ID! = Node. ID & this. anodes [N]. _ HC ){
This. nodestatus (false, N, this. anodes [N]. _ ls );
This. anodes [N]. _ IO = false;
This. closeallchildren (this. anodes [N]);
}
}
}
// Closes all children of a node
Dtree. Prototype. closeallchildren = function (node ){
For (VAR n = 0; n <this. anodes. length; n ++ ){
If (this. anodes [N]. PID = node. ID & this. anodes [N]. _ HC ){
If (this. anodes [N]. _ IO) This. nodestatus (false, N, this. anodes [N]. _ ls );
This. anodes [N]. _ IO = false;
This. closeallchildren (this. anodes [N]);
}
}
}
// Change the status of a node (open or closed)
Dtree. Prototype. nodestatus = function (status, ID, bottom ){
Ediv = Document. getelementbyid ('D' + this. OBJ + id );
Ejoin = Document. getelementbyid ('J' + this. OBJ + id );
If (this. config. useicons ){
Eicon = Document. getelementbyid ('I' + this. OBJ + id );
Eicon. src = (Status )? This. anodes [ID]. iconopen: This. anodes [ID]. Icon;
}
Ejoin. src = (this. config. uselines )?
(Status )? (Bottom )? This. Icon. minusbottom: This. Icon. Minus) :( (bottom )? This. Icon. plusbottom: This. Icon. Plus )):
(Status )? This. Icon. nlminus: This. Icon. nlplus );
Ediv. style. Display = (Status )? 'Block': 'none ';
};
// [Cookie] clears a cookie
Dtree. Prototype. clearcookie = function (){
VaR now = new date ();
VaR yesterday = new date (now. gettime ()-1000*60*60*24 );
This. setcookie ('co' + this. OBJ, 'cookievalue ', yesterday );
This. setcookie ('cs '+ this. OBJ, 'cookievalue', yesterday );
};
// [Cookie] sets value in a cookie
Dtree. Prototype. setcookie = function (cookiename, cookievalue, expires, path, domain, secure ){
Document. Cookie =
Escape (cookiename) + '=' + escape (cookievalue)
+ (Expires? '; Expires =' + expires. togmtstring ():'')
+ (Path? '; Path =' + path :'')
+ (Domain? '; Domain =' + domain :'')
+ (Secure? '; Secure ':'');
};
// [Cookie] gets a value from a cookie
Dtree. Prototype. getcookie = function (cookiename ){
VaR cookievalue = '';
VaR posname = Document. Cookie. indexof (escape (cookiename) + '= ');
If (posname! =-1 ){
VaR posvalue = posname + (escape (cookiename) + '='). length;
VaR endpos = Document. Cookie. indexof (';', posvalue );
If (endpos! =-1) cookievalue = Unescape (document. Cookie. substring (posvalue, endpos ));
Else cookievalue = Unescape (document. Cookie. substring (posvalue ));
}
Return (cookievalue );
};
// [Cookie] returns IDs of open nodes as a string
Dtree. Prototype. updatecookie = function (){
VaR STR = '';
For (VAR n = 0; n <this. anodes. length; n ++ ){
If (this. anodes [N]. _ IO & this. anodes [N]. PID! = This. Root. ID ){
If (STR) STR + = '.';
STR + = This. anodes [N]. ID;
}
}
This. setcookie ('co' + this. OBJ, STR );
};
// [Cookie] checks if a node ID is in a cookie
Dtree. Prototype. isopen = function (ID ){
VaR aopen = This. getcookie ('co' + this. OBJ). Split ('.');
For (VAR n = 0; n <aopen. length; n ++)
If (aopen [N] = ID) return true;
Return false;
};
// If push and pop is not implemented by the browser
If (! Array. Prototype. Push ){
Array. Prototype. Push = function array_push (){
For (VAR I = 0; I <arguments. length; I ++)
This [This. Length] = arguments [I];
Return this. length;
}
};
If (! Array. Prototype. Pop ){
Array. Prototype. Pop = function array_pop (){
Lastelement = This [This. Length-1];
This. Length = math. Max (this. Length-1, 0 );
Return lastelement;
}
};
Under the JS folder
Op. js
Function showsubmenu (SID ){
Whichel = eval ("submenu" + Sid );
If (whichel. style. Display = "NONE "){
Eval ("submenu" + Sid + ". style. Display = /"/";");
} Else {
Eval ("submenu" + Sid + ". style. Display =/" NONE /";");
}
}
Function CWIN (){
If (parent. testframeset. Cols! = '1970 ,*'){
Parent. testframeset. Cols = '2017 ,*';
} Else {
Parent. testframeset. Cols = '-10 ,*';
}
}
Function closenavi (){
W-= 10;
If (W>-10 ){
Window. Parent. testframeset. Cols = ''+ W + ', *'; repeat = setTimeout (" closenavi () ", 100 );
} Else {
Cleartimeout (Repeat); W = 220;
}
Source code see http://www.114look.com/downfiles/jsptree.rar
Http://d.download.csdn.net/down/358426/facepp