栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

xtree.js 代码

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

xtree.js 代码

复制代码 代码如下:
/



treeItem.prototype.getFirstChild = function()
{
    if(this.childNodes.length>0 && this.open)
        return this.childNodes[0];
    return this;
}

treeItem.prototype.getLastChild = function()
{
    if(this.childNodes.length>0 && this.open)
        return this.childNodes[this.childNodes.length-1].getLastChild();
    return this;
}

treeItem.prototype.getPreviousSibling = function()
{
    if(!this.parent) return null;
    for(var i=0;i        if(this.parent.childNodes[i] == this)break;
    if(i == 0) 
        return this.parent;
    else
        return this.parent.childNodes[i-1].getLastChild();
}

treeItem.prototype.getNextSibling = function()
{
    if(!this.parent) return null;
    for(var i=0;i        if(this.parent.childNodes[i] == this)break;
    if(i == this.parent.childNodes.length-1)
        return this.parent.getNextSibling();
    else
        return this.parent.childNodes[i+1];
}

treeItem.prototype.KeyDown=function(e){
    var code,o;
    if(!e) e = window.event;
    code = e.which ? e.which : e.keyCode;
    o = this;
    if(code == 37)
    {
        if(o.open) o.collapse();
        else
        {
            if(o.parent) o.parent.select();
        }
        return false;
    }
    else if(code == 38)
    {
        var tmp = o.getPreviousSibling();
        if(tmp) tmp.select();
        return false;
    }
    else if(code == 39)
    {
        if(o.childNodes.length>0)
        {
            if(!o.open) o.expand();
            else
            {
                var tmp = o.getFirstChild();
                if(tmp) tmp.select();
            }
        }
        return false;
    }
    else if(code == 40)
    {
        if(o.open&&o.childNodes.length>0)o.getFirstChild().select();
        else
        {
            var tmp = o.getNextSibling();
            if(tmp) tmp.select();
        }
        return false;
    }
    else if(code == 13)
    {
        o.toggle();
        o.openURL();
        return false;
    }
    return true;
}

Array.prototype.indexOf=function(o){
    for(var i=0;i        if(this[i]==o)return i;
    return -1;
}

Array.prototype.removeAt=function(i){
    return this.slice(0,i).concat(this.slice(i+1))
}

Array.prototype._remove=function(o){
    var i=this.indexOf(o);
    if(i!= -1) return this.removeAt(i)
    return this
}






function xtreeItem(uid,text,action,target,title,Icon,xml){
    this.uid=uid;
    this.base=treeItem;
    this.base(text,action,target,title,Icon);
    this.Xml=xml;
}
xtreeItem.prototype=new treeItem;

xtreeItem.prototype.parseElement=function(dom){
    return dom.selectSingleNode("/TreeNode");
}

xtreeItem.prototype.addNodesLoop = function(oItem)
{
    for(var i=0;i    {
        var o = oItem.childNodes[i];
        var tmp = new xtreeItem(o.getAttribute("id"),o.getAttribute("text"),o.getAttribute("href"),o.getAttribute("target"),o.getAttribute("title"),o.getAttribute("icon"),o.getAttribute('Xml'));
        this.add(tmp);
        if(o.getAttribute("Xml")) tmp.add(new treeItem("Loading..."));
        else
        {
            tmp.load=true;
            tmp.addNodesLoop(o);
        }
    }
}

xtreeItem.prototype.loadChildren=function()
{
    var oItem = this;
    var oLoad = oItem.childNodes[0];
    var XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    XmlHttp.onreadystatechange=function(){
        if(XmlHttp.readyState==4){
            if(XmlHttp.status==200){
                if(XmlHttp.responseXML.xml == ""){ oLoad.setText("unavaible1");return;}
                var XmlItem=oItem.parseElement(XmlHttp.responseXML.documentElement);
                if(XmlItem.childNodes.length == 0){ oLoad.setText("unavaible") }
                else
                {
                    oItem.addNodesLoop(XmlItem);
                    for(var i=0;i                    {

                        if(parseInt(getcookie("item"+oItem.childNodes[i].id)) ==1)
                        { oItem.childNodes[i].expand();}
                    }
                    if(Global.selectedItem == oItem.childNodes[0])oItem.select();
                    oLoad.remove();
                }
            }
            else{
                oLoad.setText("unavaible");
            }
            XmlHttp = null;
            oItem.select(1);
        }
    }
    try{
        XmlHttp.open("get",this.Xml+(/?/g.test(this.Xml)?"&":"?")+"temp="+Math.random(),true);
        XmlHttp.send();
    }catch(e){ oLoad.setText("unavaible");}
}
xtreeItem.prototype.setup=function(oTarget){
    this.add(new treeItem("Loading..."));
    oTarget.appendChild(this.toString());
    this.setuped=true;
    if(this.childNodes.length>0 || this.open) this.expand();
}

function setcookie(name,value)
{
    var Days = 7; 
    var exp  = new Date();
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getcookie(name)
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
    if(arr != null) return unescape(arr[2]); return null;
}
function delcookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getcookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/120372.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号