.hanyeguxing {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 11px;
color: #666;
white-space: nowrap;
}
.hanyeguxing img {
border: 0px;
vertical-align: middle;
}
.hanyeguxing a {
color: #333;
text-decoration: none;
}
.hanyeguxing a.node, .hanyeguxing a.nodeSel {
white-space: nowrap;
padding: 1px 2px 1px 2px;
}
.hanyeguxing a.node:hover, .hanyeguxing a.nodeSel:hover {
color: #333;
text-decoration: underline;
}
.hanyeguxing a.nodeSel {
background-color: #c0d2ec;
}
.hanyeguxing .clip {
overflow: hidden;
}
href="javascript:
d.openAll();">全部展开
| 全部折叠
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.target = 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;
};
function hanyeguxing(objName) {
this.config = {
target : null,
folderLinks : true,
useSelection : true,
useCookies : true,
useLines : true,
useIcons : true,
useStatusText : false,
closeSameLevel : false,
inOrder : false
}
this.icon = {
//图标 gif 图形文件存储在 img/ 子文件夹中
root : 'img/base.gif',
//base.gif,目录图标
folder : 'img/folder.gif',
//folder,折叠图标
folderOpen : 'img/folderopen.gif',
//folderopen,展开图标
node : 'img/page.gif',
//page.gif,文件图标
empty : 'img/empty.gif',
//empty.gif,空图标
line : 'img/line.gif',
//line.gif,竖线图标
join : 'img/join.gif',
//join.gif,┣图标,有后续同级目录
joinBottom : 'img/joinbottom.gif',
//joinbottom.gif,┗图标,无后续同级目录
plus : 'img/plus.gif',
//plus.gif,折叠图标,有子目录,有后续同级目录
plusBottom : 'img/plusbottom.gif',
//plusbottom.gif,折叠图标,有子目录,无后续同级目录
minus : 'img/minus.gif',
//minus.gif,展开图标,有子目录,有后续同级目录
minusBottom : 'img/minusbottom.gif',
//minusbottom.gif,展开图标,有子目录,无后续同级目录
nlPlus : 'img/nolines_plus.gif',
//nolines_plus.gif,折叠图标,无子目录,无其他同级目录
nlMinus : 'img/nolines_minus.gif'
//nolines_minus.gif,展开图标,无子目录,无其他同级目录
};
this.obj = objName;
this.aNodes = [];
this.aIndent = [];
this.root = new Node(-1);
this.selectedNode = null;
this.selectedFound = false;
this.completed = false;
};
hanyeguxing.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);
};
hanyeguxing.prototype.openAll = function() {
this.oAll(true);
};
hanyeguxing.prototype.closeAll = function() {
this.oAll(false);
};
hanyeguxing.prototype.toString = function() {
var str = '
class="hanyeguxing">\n';
if (document.getElementByIdx) {
if (this.config.useCookies) this.selectedNode =
this.getSelected();
str += this.addNode(this.root);
} else str += 'Browser not supported.';
str += '
if (!this.selectedFound) this.selectedNode = null;
this.completed = true;
return str;
};
hanyeguxing.prototype.addNode = function(pNode) {
var str = '';
var n=0;
if (this.config.inOrder) n = pNode._ai;
for (n; n
if (this.aNodes[n].pid == pNode.id) {
var cn = this.aNodes[n];
cn._p = pNode;
cn._ai = n;
this.setCS(cn);
if (!cn.target &&
this.config.target) cn.target = this.config.target;
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;
};
hanyeguxing.prototype.node = function(node, nodeId) {
var str = '
class="hanyeguxingNode">' + 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) {
if (node.title) str += ' title="' + node.title + '"';
if (node.target) str += ' target="' + node.target + '"';
if (this.config.useStatusText) str += '
οnmοuseοver="window.status=\'' + node.name + '\';return true;"
οnmοuseοut="window.status=\'\';return true;" ';
if (this.config.useSelection &&
this.config.folderLinks) || !node._hc))
str += ' οnclick="javascript: ' + this.obj + '.s(' + nodeId +
else if ((!this.config.folderLinks || !node.url)
if (node.url || ((!this.config.folderLinks || !node.url)
';str += '
if (node._hc) {
str += '
class="clip" style="display:' + ((this.root.id == node.pid ||
node._io) ? 'block' : 'none') + ';">';
str += this.addNode(node);
str += '
}
this.aIndent.pop();
return str;
};
hanyeguxing.prototype.indent = function(node, nodeId) {
var str = '';
if (this.root.id != node.pid) {
for (var n=0; n
str += '
/>';
(node._ls) ? this.aIndent.push(0) : this.aIndent.push(1);
if (node._hc) {
str += 'nodeId + ');">
/>
';} else str += '
/>';
}
return str;
};
hanyeguxing.prototype.setCS = function(node) {
var lastId;
for (var n=0; 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;
};
hanyeguxing.prototype.getSelected = function() {
var sn = this.getCookie('cs' + this.obj);
return (sn) ? sn : null;
};
hanyeguxing.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.getElementByIdx("s" + this.obj +
this.selectedNode);
eOld.className = "node";
}
eNew = document.getElementByIdx("s" + this.obj + id);
eNew.className = "nodeSel";
this.selectedNode = id;
if (this.config.useCookies) this.setCookie('cs' + this.obj,
cn.id);
}
};
hanyeguxing.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();
};
hanyeguxing.prototype.oAll = function(status) {
for (var n=0; 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();
};
hanyeguxing.prototype.openTo = function(nId, bSelect, bFirst)
{
if (!bFirst) {
for (var n=0; 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);
};
hanyeguxing.prototype.closeLevel = function(node) {
for (var n=0; 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]);
}
}
}
hanyeguxing.prototype.closeAllChildren = function(node) {
for (var n=0; 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]);
}
}
}
hanyeguxing.prototype.nodeStatus = function(status, id, bottom)
{
eDiv= document.getElementByIdx('d' + this.obj + id);
eJoin= document.getElementByIdx('j' + this.obj + id);
if (this.config.useIcons) {
eIcon= document.getElementByIdx('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';
};
hanyeguxing.prototype.clearCookie = function() {
var now = new Date();
var yesterday = new Date(now.getTime() - 1000 * 60 * 60 *
24);
this.setCookie('co'+this.obj, 'cookiue', yesterday);
this.setCookie('cs'+this.obj, 'cookiue', yesterday);
};
hanyeguxing.prototype.setCookie = function(cookieName, cookiue,
expires, path, domain, secure) {
document.cookie =
escape(cookieName) + '=' + escape(cookiue)
+ (expires ? '; expires=' + expires.toGMTString() : '')
+ (path ? '; path=' + path : '')
+ (domain ? '; domain=' + domain : '')
+ (secure ? '; secure' : '');
};
hanyeguxing.prototype.getCookie = function(cookieName) {
var cookiue = '';
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) cookiue =
unescape(document.cookie.substring(posValue, endPos));
else cookiue = unescape(document.cookie.substring(posValue));
}
return (cookiue);
};
hanyeguxing.prototype.updateCookie = function() {
var str = '';
for (var n=0; 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);
};
hanyeguxing.prototype.isOpen = function(id) {
var aOpen = this.getCookie('co' + this.obj).split('.');
for (var n=0; n
if (aOpen[n] == id) return true;
return false;
};
if (!Array.prototype.push) {
Array.prototype.push = function array_push() {
for(var i=0;i
this[this.length]=arimgments[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;
}
};
hanyeguxingimgxing
d = new hanyeguxing("d");
d.add(0,-1,"目录名称","");
d.add(1,0,"第一级","http://blog.sina.com.cn/hygxchxz");
d.add(2,1,"第二级,1","http://blog.sina.com.cn/hygxchxz");
d.add(3,1,"第二级,2","http://blog.sina.com.cn/hygxchxz");
d.add(4,1,"第二级,3","http://blog.sina.com.cn/hygxchxz");
d.add(5,4,"第二级,3的子目录-1","http://blog.sina.com.cn/hygxchxz");
d.add(6,4,"第二级,3的子目录-2","http://blog.sina.com.cn/hygxchxz");
d.add(7,1,"第二级,4","http://blog.sina.com.cn/hygxchxz");
d.add(8,3,"第二级,2的子目录-1","http://blog.sina.com.cn/hygxchxz");
d.add(9,3,"第二级,2的子目录-2","http://blog.sina.com.cn/hygxchxz");
document.write(d);
//-->
align="left">
class="hanyeguxing">寒夜孤星【初学者】