//获得解释结果并回到
this.getTree = function(){
this.parseXML(DOMRoot);
DOMRoot = null;//释放DOM对象
return result.join(“”);
}
/*************静态属性***************/
JXTree.curText = null;//当前文件的id
TreeView.prototype.setContext = function () {
this.context = new Array();
for (var i=arguments.length-1,j=0; i>=0; i–,j++) {
this.context[j] = arguments[i];
}
};
/*****************************
*ElementNode对象,承继自抽象对象TreeNode
*新扩展属性:
*_nodeName 节点名称
******************************/
var ElementNode = function(node,level)
{
TreeNode.apply(this,arguments);
this._nodeName = XMLDom.getAttribute(node,”name”) ? XMLDom.getAttribute(node,”name”) : “”;
this.toHTML = function(){
var result = “”;
if(this.isLast) result += “<div><div class=’minus_bottom'”;
else result += “<div><div class=’minus'”;
result += ” id='”+this.id+”_join’ onclick=\”JXTree.changeState(‘”+this.id+”‘)\”></div><div id='”+this.id+”_folder’ class=’folder_open’></div><span class=’text’ onclick=\””+this._click+”\”>”+this._nodeName+”</span></div>”;
return result;
}
}
CheckBoxTreeNode.prototype.setCheckedChildren = function (b) {
for (var i=0,j=0; i<this.childNodes.length; i++) {
if (this.childNodes[i] instanceof CheckBoxTreeNode)
this.childNodes[i].setCheckedChildren(b);
}
this._checkbox.checked = b;
};
var DOMRoot=XMLDom.loadXML(xmlU奥迪Q7L).documentElement;//同步加载XML文件
var level = -1;//root节点level
var stack = new Array(1);
result.push(“<div><div class=’root’></div><span class=’text’>”+XMLDom.getAttribute(DOMRoot,”name”)+”</span></div>”);
//解释xml文件内容成树状态实行的HTML代码,递归调用
this.parseXML = function(node){
stack.push(level);
level++;
var element = new ElementNode(node,level);
var elements = node.childNodes;
if(level != 0){
if(element.isLast)
result.push(“<div id='”+element.id+”_body’ class=’body_empty’>”);
else
result.push(“<div id='”+element.id+”_body’ class=’body_line’>”);
}
for(var i=0;i<elements.length;i++){
if(elements.item(i).nodeName == “item”){//节点为树叶
var textNode = new TextNode(elements.item(i),level);
result.push(textNode.toHTML());
textNode = null;//及时放出对象
}
else if(elements.item(i).nodeType ==1){//节点为树枝
var elementNode = new ElementNode(elements.item(i),level);
result.push(elementNode.toHTML());
elementNode = null;//及时放出对象
this.parseXML(elements.item(i));
}
}
if(level != 0)result.push(“</div>”);
level = stack.pop();
}
TreeView.prototype.create = function (oTarget) {
oTarget.appendChild(this.toHTML());
this._rendered = true;
if (this.childNodes.length>0 || this.open || this.src)
this.expand();
};
/******************************************
*JXTree对象,读取外界xml文件数量,生成树
*@author brull
*@email brull@163.com
*@date 2007-03-27
*******************************************/
TreeNode.prototype.unselect = function () {
this._anchor.className = “TreeNode-Anchor”;
var selected = this._tree.getSelectedNode();
if (selected == this) this._tree.setSelectedNode(null);
};
/*
*@param xmlU瑞鹰L XML文件的地点
*/
var JXTree = function(xmlURL)
{
var result = new Array();
function CheckBoxTreeNode(sKey, sName, sText, sHref, sTarget, sTitle, sIcon, sOpenIcon, sXMLSrc) {
this._base = TreeNode;
this._base(sKey, sText, sHref, sTarget, sTitle, sIcon, sOpenIcon, sXMLSrc);
this.name = sName;
this.checked = false;
};
/*****************************
*TexNode对象,继承自抽象对象TreeNode
*属性和TreeNode一样
*增加产量属性:
*_nodeValue 节点值
******************************/
var TextNode = function(node,level)
{
TreeNode.apply(this,arguments);
this._nodeValue = node.firstChild.nodeValue;
this.toHTML = function(){
var result = “”;
if(this.isLast) result += “<div><div class=’join_bottom’></div>”;
else result += “<div><div class=’join’></div>”;
result += “<div class=’page’></div><span class=’text’ id='”+this.id +”_item’ onclick=\”JXTree.setFocus(this.id);”+this._click+”\”>”+this._nodeValue+”</span></div>”;
return result;
}
}
TreeNode.prototype.setOpen = function (v) {
this.open = v;
if (TreeConfig.useCookie) {
WebCookie.setValue(“o” + this.id, v);
}
};
/**********Node 节点塑造截至,伊始解释XML文件************/
TreeNode.prototype.recalIndent = function (nLevel, b) {
for (var i = 0; i<this.childNodes.length; i++) {
this.childNodes[i]._item.childNodes[nLevel-1].src = b ? TreeConfig.TreeIcon.blank : TreeConfig.TreeIcon.line;
this.childNodes[i].recalIndent(nLevel, b);
}
};
/************静态方法***************/
JXTree.changeState = function (id){//张开或然收缩节点内容
var _body = document.getElementById(id + “_body”);
var _join = document.getElementById(id+”_join”);
var folder = document.getElementById(id+”_folder”);
(_body.style.display == “none”) ? (
_body.style.display = “block”,
_join.className = _join.className.replace(“plus”,”minus”),
folder.className = “folder_open”
) : (
_body.style.display = “none”,
_join.className = _join.className.replace(“minus”,”plus”),
folder.className = “folder_close”
)
};//changeState
JXTree.setFocus = function(id){
if(JXTree.curText)
with(document.getElementById(JXTree.curText).style){
backgroundColor = “”;
color = “#000”;
}
with( document.getElementById(id).style){
backgroundColor = “#003366”;
color = “#FFF”;
}
JXTree.curText = id;
}
}
TreeNode.prototype.getLastChild = function() {
if (this.childNodes.length>0 && this.open)
return this.childNodes[this.childNodes.length-1].getLastChild();
return this;
};
/*****************************
*第一定义TreeNode抽象对象
*TreeNode对象属性:
*id 独一编号,必需在xml文件里定义为节点属性
*level 节点档次,从-1起先(即根节点)
*_click 节点click,在xml文件定义为节点属性[可选]
*isLast 是不是为本节点所在档期的顺序最后五个节点
*parent_isLast 父节点是或不是为父节点所在等级次序的终极一个节点
*toHTML 本节点转成HTML代码的法子
*******************************/
var TreeNode = function (node,level)
{
var parent_elements = node.parentNode ? (node.parentNode.parentNode ? node.parentNode.parentNode.childNodes : null) : null;
var elements = node.parentNode ? node.parentNode.childNodes : null;
this.id = XMLDom.getAttribute(node,”id”) ? XMLDom.getAttribute(node,”id”) : “”;
this.level = level;//节点的档期的顺序
this.isLast = elements ? ((elements.item(elements.length-2) === node) ? true : false) : false;
this._click = XMLDom.getAttribute(node,’click’) ? XMLDom.getAttribute(node,’click’) : “”;
this.toHTML = null;//function
}
//**************
// TreeNode
//**************
Array.prototype.Remove = function(o){
for (var i=0; i<this.length; i++) {
if (this[i] == o) break;
}
if (i != this.length) return this.slice(0,i).concat(this.slice(i+1,this.length));
return this;
};
TreeNode.prototype.resetTree = function (oTree) {
for (var i=0; i<this.childNodes.length; i++)
this.childNodes[i].resetTree(oTree);
this._tree = oTree;
};
TreeNode.prototype.add = function(oItem) {
var tree = this._tree;
oItem.parentNode = this;
var len = this.childNodes.length;
this.childNodes[len] = oItem;
if (len > 0) {
var o = this.childNodes[len-1];
o.recalIndent(o.level, false);
o.reloadIcon();
} else if (tree) {
if (tree._rendered) this.open = 0;
this.reloadIcon();
}
if (tree) this.resetTree(tree);
this._container.style.display = this.open ? “” : “none”;
this._container.appendChild(oItem.toHTML());
return oItem;
};
TreeNode.prototype.toHTML = function() {
var o = this._item;
this.indent();
this.reloadIcon();
if (this.parentNode == null) o.removeChild(this._handler);
return o;
};
TreeNode.prototype.getXML = function () {
var oLoad = this.loader;
var oThis = this;
this._xmlhttp = null;
try{
if (window.XMLHttpRequest)
this._xmlhttp = new XMLHttpRequest();
else if (window.ActiveXObject)
this._xmlhttp = new ActiveXObject(“Microsoft.XMLHTTP”);
}catch (e){}
if (this._xmlhttp == null) throw new Error(‘Your browser doesn\’t support!’);
this._xmlhttp.onreadystatechange = function () { oThis.XMLHttpCallBack(); };
try {
var temp = (/\?/g.test(this.src)?”&”:”?”) + “temp=” + String(new Date().getTime())
this._xmlhttp.open(“get”, this.src + temp, true);
this._xmlhttp.send(null);
}catch(e){ oLoad.setText(TreeConfig.unavaibleText);}
};
TreeView.prototype.getSelectedNode = function () {
生成树的函数。 if (window.selectedNode) return window.selectedNode;
return null;
};
TreeNode.prototype.contextMenu = function (e) {
e = e || window.event;
if (e.button == 2) {
if (typeof TreeConfig.contextmenu == “function”)
TreeConfig.contextmenu();
return false;
}
return true;
};
TreeNode.prototype.getNextSibling = function() {
if (!this.parentNode) return null;
for (var i=0;i<this.parentNode.childNodes.length;i++)
if (this.parentNode.childNodes[i] == this)break;
if (i == this.parentNode.childNodes.length-1)
return this.parentNode.getNextSibling();
else
return this.parentNode.childNodes[i+1];
}
TreeNode.prototype.getRoot = function() {
var root = this;
while (root.parentNode) root = root.parentNode;
return root;
};
CheckBoxTreeNode.prototype = new TreeNode;
var TreeConfig = {
TreeIcon :{
root :’root.gif’,
folderopen :’folderopen.gif’,
folder :’folder.gif’,
file :’file.gif’,
Rplus :’Rplus.gif’,
Rminus :’Rminus.gif’,
join :’T.gif’,
joinbottom :’L.gif’,
plus :’Tplus.gif’,
plusbottom :’Lplus.gif’,
minus :’Tminus.gif’,
minusbottom :’Lminus.gif’,
blank :’blank.gif’,
line :’I.gif’
},
defaultText :”New”,
defaultHref :”javascript:void(0)”,
defaultTarget :”_blank”,
loadingText :”Loading…”,
unavaibleText :”Unavaible”,
useCookie :true,
contextmenu :null
};
function TreeNode(sKey, sText, sHref, sTarget, sTitle, sIcon, sOpenIcon, sXMLSrc) {
this.id = TreeHandler.getId(this, sKey);
this.level = 0;
this.text = sText ? sText : TreeConfig.defaultText;
this.href = sHref ? sHref : TreeConfig.defaultHref;
this.target = sHref ? (sTarget ? sTarget : TreeConfig.defaultTarget) : “_self”;
this.title = sTitle ? sTitle : this.text;
this.childNodes = new Array();
this.parentNode = null;
this.open = TreeConfig.useCookie ? this.getOpen() : 0;
this.shown = false;
this.icon = sIcon;
this.openIcon = sOpenIcon;
this.src = sXMLSrc;
this._tree = null;
this.onexpand = null;
this.oncollapse = null;
this.onselect = null;
this.toElement();
if (sXMLSrc) {
this.open = 0;
this.loader = new this.constructor(null, TreeConfig.loadingText, null, null, null);
this.add(this.loader);
}
};
TreeView.prototype = new TreeNode;
TreeNode.prototype.reloadIcon = function () {
var l = this.isLast(), o = this.open, m = TreeConfig.TreeIcon;
if (this.parentNode) {
this._handler.src = this.childNodes.length>0 ? (o ? (l ? m.minusbottom : m.minus) : (l ? m.plusbottom : m.plus)) : (l ? m.joinbottom : m.join);
}
this._icon.src = this.childNodes.length>0 ? (o ? (this.openIcon ? this.openIcon : (this.icon ? this.icon : m.folderopen)) : (this.icon ? this.icon : m.folder)) : (this.icon ? this.icon : m.file);
};
var TreeHandler = {
id :0,
all :{},
getId :function (obj, key) {
var ID = key == null ? this.id :key;
this.all[ID] = obj;
return key==null ? this.id++ : key;
},
setImagePath :function(sPath){
for (i in TreeConfig.TreeIcon) {
var tem = new Image();
tem.src = sPath + TreeConfig.TreeIcon[i];
TreeConfig.TreeIcon[i] = tem.src;
}
}
};
TreeNode.prototype.isLast = function () {
var p = this.parentNode;
if (p == null) return false;
return p.childNodes[p.childNodes.length – 1] == this;
};
TreeNode.prototype.HTMLtoText = function (s) {
return String(s).replace(/&/g, “&”).replace(/\”/g, ‘”‘).replace(/</g,'<‘).replace(/>/g, ‘>’);
};
TreeNode.prototype.getOpen = function () {
var o = WebCookie.getValue(“o” + this.id);
if (o != null)
return parseInt(o);
return 0;
钱柜678,};
TreeNode.prototype.expandAll = function() {
if (this.childNodes.length>0 && !this.open) this.expand();
this.expandChildren();
};
TreeNode.prototype.getPreviousSibling = function() {
if (!this.parentNode) return null;
for (var i=0;i<this.parentNode.childNodes.length;i++)
if (this.parentNode.childNodes[i] == this) break;
if (i == 0)
return this.parentNode;
else
return this.parentNode.childNodes[i-1].getLastChild();
};
PoweredbyFason
Email:[email protected]
HomePage: Version:3.0
=========================================*/ varTr…
/*=========================================
Powered by Fason
Email: [email protected]
HomePage:
Version:3.0
=========================================*/