⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jscript.js.bak

📁 javascript脚本实现的树型控件,改善了大数据量时创建树的效率问题
💻 BAK
📖 第 1 页 / 共 3 页
字号:
    "target='"+ target +"' "+
	//提示
    "title='"+ node.hint +"' "+
    "onfocus=\""+ this.name +".focusLink('"+ id +"')\" "+
    //右键点击节点出现 上下文关联菜单
	"oncontextmenu=\" return "+ this.name +".showcontextmenu(event)\" "+
    "onclick=\"return "+ this.name +".nodeClick('"+ id +"')\">"+ node.text +
  "</A></NOBR></DIV>";
  if(isRoot && node.text=="") HTML = "";
  
  HTML = "\r\n<SPAN id='"+ this.name +"_tree_"+ id +"'>" + HTML;
  HTML += "<SPAN style='DISPLAY: none;'></SPAN></SPAN>";
  return HTML;
};

//在使用图片的时候对 node.childAppend 的转换
MzTreeView.prototype.word2image = function(word)
{
  var str = "";
  for(var i=0; i<word.length; i++)
  {
    var img = "";
    switch (word.charAt(i))
    {
      case "│" : img = "L4"; break;
      case "└" : img = "L2"; break;
      case " " : img = "empty"; break;
      case "├" : img = "L1"; break;
      case "─" : img = "L3"; break;
      case "┌" : img = "L0"; break;
    }
    if(img!="")
      str += "<IMG align='absMiddle' src='"+ this.icons[img].src +"' height='20'>";
  }
  return str;
}

//获取当前节点在客户端的完整HTML标记
MzTreeView.prototype.getNodeHTML = function(id)
{
    return "\r\n<SPAN id='"+ this.name +"_tree_"+ id +"'>" + this.getElementById(this.name +"_tree_"+ id).innerHTML + "</SPAN>";
};

//将某个节点下的所有子节点转化成详细的<HTML>元素,并显示
//id 树的客户端节点 id
MzTreeView.prototype.buildChildNodesHTML = function(id)
{
  if(this.node[id].hasChild)
  {
    var childNodes = this.node[id].childNodes, str = "";
    for (var i=0; i<childNodes.length; i++)
      str += this.nodeToHTML(childNodes[i], i==childNodes.length-1);   
    this.getChildNodeSpan(this.node[id]).innerHTML = str;
  }
};

//聚集到客户端生成的某个节点上
//id  客户端树节点的id
MzTreeView.prototype.focusClientNode = function(id)
{
  if(!this.currentNode) this.currentNode=this.node["0"];

  var currentLink = this.getElementById(this.name +"_link_"+ id); 
  if(currentLink){ 
    var previousLink = this.getElementById(this.name +"_link_"+ this.currentNode.id);
    if(previousLink) with(previousLink.style){color="";   backgroundColor="";}   
    currentLink.focus();
    with(currentLink.style){color = this.colors.highLightText; backgroundColor = this.colors.highLight;}
    this.currentNode= this.node[id];
  }
};

//焦点聚集到树里的节点链接时的处理
//id 客户端节点 id
MzTreeView.prototype.focusLink = function(id)
{
  if(this.currentNode && this.currentNode.id==id) return;
  this.focusClientNode(id);
};

//节点链接单击事件处理方法
//id 客户端树节点的 id
MzTreeView.prototype.nodeClick = function(id)
{
  var source = this.nodes[this.node[id].sourceIndex];
  eval(this.getAttribute(source, "method"));
  return !(!this.getAttribute(source, "url") && this.url=="#");
};

//为配合系统初始聚集某节点而写的函数, 得到某节点在数据源里的路径
//sourceId 数据源里的节点 id
MzTreeView.prototype.getPath= function(sourceId)
{
  Array.prototype.indexOf = function(item)
  {
    for(var i=0; i<this.length; i++)
    {
      if(this[i]==item) return i;
    }
    return -1;
  };
  var _d = this._d, d = this.divider;
  var A = new Array(), id=sourceId; A[0] = id;
  while(id!="0" && id!="")
  {
    var str = "(^|"+_d+")([^"+_d+d+"]+"+d+ id +")("+_d+"|$)";
    if (new RegExp(str).test(this.names))
    {
      id = RegExp.$2.substring(0, RegExp.$2.indexOf(d));
      if(A.indexOf(id)>-1) break;
      A[A.length] = id;
    }
    else break;
  }
  return A.reverse();
};

//在源代码里指定 MzTreeView 初始聚集到某个节点
//sourceId 节点在数据源里的 id
MzTreeView.prototype.focus = function(sourceId, defer)
{
  if (!defer)
  {
    setTimeout(this.name +".focus('"+ sourceId +"', true)", 100);
    return;
  }
  var path = this.getPath(sourceId);
  if(path[0]!="0")
  {
    alert("节点 "+ sourceId +" 没有正确的挂靠有效树节点上!\r\n"+
      "节点 id 序列 = "+ path.join(this.divider));
    return;
  }
  var root = this.node["0"], len = path.length;
  for(var i=1; i<len; i++)
  {
    if(root.hasChild)
    {
      var sourceIndex= path[i-1] + this.divider + path[i];
      for (var k=0; k<root.childNodes.length; k++)
      {
        if (root.childNodes[k].sourceIndex == sourceIndex)
        {
          root = root.childNodes[k];
          if(i<len - 1) this.toggle(root.id);
          else this.focusClientNode(root.id);
          break;
        }
      }
    }
  }
};

//树的单击事件处理函数
MzTreeView.prototype.clickHandle = function(e)
{
  e = window.event || e; e = e.srcElement || e.target;
  switch(e.tagName)
  {
    case "IMG" :
      if(e.id)
      {
        if(e.id.indexOf(this.name +"_icon_")==0)
          this.focusClientNode(e.id.substr(e.id.lastIndexOf("_") + 1));
        else if (e.id.indexOf(this.name +"_expand_")==0)
          this.toggle(e.id.substr(e.id.lastIndexOf("_") + 1));
      }
      break;
    case "A" :
      if(e.id) this.focusClientNode(e.id.substr(e.id.lastIndexOf("_") + 1));
      break;
    case "SPAN" :
      if(e.className=="pm")
        this.toggle(e.id.substr(e.id.lastIndexOf("_") + 1));
      break;
    default :
      if(this.navigator=="netscape") e = e.parentNode;
      if(e.tagName=="SPAN" && e.className=="pm")
        this.toggle(e.id.substr(e.id.lastIndexOf("_") + 1));
      break;
  }
};

//MzTreeView 双击事件的处理函数
MzTreeView.prototype.dblClickHandle = function(e)
{
  e = window.event || e; e = e.srcElement || e.target;
  if((e.tagName=="A" || e.tagName=="IMG")&& e.id)
  {
    var id = e.id.substr(e.id.lastIndexOf("_") + 1);
    if(this.node[id].hasChild) this.toggle(id);
  }
};

//展开树节点的对应方法
//id 客户端节点 id
MzTreeView.prototype.expand = function(id)
{ 
  var node  = this.node[id];
    
  if (!node.hasChild) return;
  var childNodesSpan = this.getChildNodeSpan(node);
  if (childNodesSpan)
  {
    var icon  = this.icons[node.icon];
    var iconE = this.iconsExpand[node.icon];
    var img   = this.getElementById(this.name +"_icon_"+ id);
    if (img)  img.src = typeof(iconE)=="undefined" ? icon.src : iconE.src;
    var exp   = this.icons[node.iconExpand];
    var expE  = this.iconsExpand[node.iconExpand];
    var expand= this.getElementById(this.name +"_expand_"+ id);
    if (expand)
    {
      expand.src = typeof(expE) =="undefined" ? exp.src  : expE.src;
    }
    
    childNodesSpan.style.display = "block";

    if(!node.isLoad)
    {
      this.load(id);
      if(node.id=="0") return;   //如果是虚拟的根节点,则退出不需要加载
      //当子节点过多时, 给用户一个正在加载的提示语句
      if(node.hasChild && node.childNodes.length>200)
      {
        setTimeout(this.name +".buildChildNodesHTML('"+ id +"')", 1);
        childNodesSpan.innerHTML = "<DIV noWrap><NOBR><SPAN>"+ this.word2image(node.childAppend +"└") +"</SPAN>"+
        "<IMG border='0' height='16' align='absmiddle' src='"+this.icons["file"].src+"'>"+
        "<A style='background-Color: "+ this.colors.highLight +"; color: "+
        this.colors.highLightText +"; font-size: 9pt'>请稍候...</A></NOBR></DIV>";
      }
      else this.buildChildNodesHTML(id);     
    }
  }
};

//折叠树节点的对应方法
//id 客户端节点 id
MzTreeView.prototype.collapse = function(id)
{ 
  var node  = this.node[id];
  if (!node.hasChild) return;
  var childNodesSpan = this.getChildNodeSpan(node);
  if (childNodesSpan)
  {
    var icon  = this.icons[node.icon];
    var iconE = this.iconsExpand[node.icon];
    var img   = this.getElementById(this.name +"_icon_"+ id);
    if (img)  img.src = icon.src;
    var exp   = this.icons[node.iconExpand];
    var expE  = this.iconsExpand[node.iconExpand];
    var expand= this.getElementById(this.name +"_expand_"+ id);
    if (expand)
    {
      expand.src = exp.src;
    }
    if(this.currentNode.path.indexOf(node.path)==0 && this.currentNode.id!=id)
    {
      try{this.getElementById(this.name +"_link_"+ id).click();}
      catch(e){this.focusClientNode(id);}
    }
    childNodesSpan.style.display = "none";
  }
};

//点击展开树节点的对应方法
//id 客户端节点 id
//sureExpand 
MzTreeView.prototype.toggle = function(id,sureExpand)
{ 
  var node  = this.node[id];
  if (!node.hasChild) return;
  var childNodesSpan = this.getChildNodeSpan(node);
  if (childNodesSpan)
  {
    var isCollapse  = sureExpand || childNodesSpan.style.display == "none";
    if(isCollapse)
      this.expand(id);
    else
      this.collapse(id);
  }
};

//展开树的所有节点
MzTreeView.prototype.expandAll = function()
{
  if(this.totalNode>500) if(
    confirm("您是否要停止展开全部节点?\r\n\r\n节点过多!展开很耗时")) return;
  if(this.node["0"].childNodes.length==0) return;
  var e = this.node["0"].childNodes[0];
  var isdo = t = false;
  while(e.id != "0")
  {
    var p = this.node[e.parentId].childNodes, pn = p.length;
    if(p[pn-1].id==e.id && (isdo || !e.hasChild)){e=this.node[e.parentId]; isdo = true;}
    else
    {
      if(e.hasChild && !isdo)
      {
        this.toggle(e.id,true), t = false;
        for(var i=0; i<e.childNodes.length; i++)
        {
          if(e.childNodes[i].hasChild){e = e.childNodes[i]; t = true; break;}
        }
        if(!t) isdo = true;
      }
      else
      {
        isdo = false;
        for(var i=0; i<pn; i++)
        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -