




已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、dtree.js源码 /*-| dTree 2.05 | /javascript/tree/ |-| Copyright (c) 2002-2003 Geir Landr? | | This script can be used freely as long as all | copyright messages are intact. | | Updated: 17.04.2003 |-*/* * Node object * 节点对象 */function Node(id, pid, name, url, title, target, icon, iconOpen, open) this.id = id; / 节点id this.pid = pid; / 节点父id = name; / 节点显示名称; this.url = url; / 节点超链接地址; this.title = title; / 节点Tips文本; this.target = target; / 节点链接所打开的目标frame(_blank, _parent, _self, _top) this.icon = icon; / 节点默认图标; this.iconOpen = iconOpen; / 节点展开图标; this._io = open | false; / 节点展开标识; this._is = false; / 节点选中标识; this._ls = false; / 同级最后节点标识; this._hc = false; / 包含子节点标识; this._ai = 0; / 节点在节点数组中的索引值,初始值为0 this._p; / 保存父节点对象; ;/* * Tree object * 树对象 */function dTree(objName,imagePath) this.config = target : null, / 默认的节点链接所打开的目标frame(_blank, _parent, _self, _top) folderLinks : true, / true文件夹节点如果有超链地址,点击节点打开超链接而不是展开节点;false忽略超链展开或折叠节点; useSelection : true, / true高亮显示选中的节点;false反之; useCookies : true, / true使用Cookies保存节点状态;false反之; useLines : true, / true使用虚线连接节点的缩进;false反之; useIcons : true, / true使用图标;false反之; useStatusText : false, / false不在状态栏显示节点名称;true反之; closeSameLevel : false, / true同一级节点只能有一个处于展开状态;false反之; inOrder : false, / false在整个节点数组中查找子节点;true在索引大于本节点的数组元素中查找子节点(如果子节点总是在父节点后面添加的话,设为true将加快tree的构建速度); imagePath : null / 图片路径; this.icon = root : (imagePath=undefined?img/base.gif:imagePath + /img/base.gif), / 根节点图标 folder : (imagePath=undefined?img/folder.gif:imagePath + /img/folder.gif), / 枝节点文件夹图标 folderOpen : (imagePath=undefined?img/folderopen.gif:imagePath + /img/folderopen.gif), / 枝节点打开状态文件夹图标 node : (imagePath=undefined?img/page.gif:imagePath + /img/page.gif), / 叶节点图标 empty : (imagePath=undefined?img/empty.gif:imagePath + /img/empty.gif), / 空白图标 line : (imagePath=undefined?img/line.gif:imagePath + /img/line.gif), / 竖线图标 join : (imagePath=undefined?img/join.gif:imagePath + /img/join.gif), / 丁字线图标 joinBottom : (imagePath=undefined?img/joinbottom.gif:imagePath + /img/joinbottom.gif), / L线图标 plus : (imagePath=undefined?img/plus.gif:imagePath + /img/plus.gif), / 丁字折叠图标 plusBottom : (imagePath=undefined?img/plusbottom.gif:imagePath + /img/plusbottom.gif), / L折叠图标 minus : (imagePath=undefined?img/minus.gif:imagePath + /img/minus.gif), / 丁字展开图标 minusBottom : (imagePath=undefined?img/minusbottom.gif:imagePath + /img/minusbottom.gif), / L展开图标 nlPlus : (imagePath=undefined?img/nolines_plus.gif:imagePath + /img/nolines_plus.gif), / 无线折叠图标 nlMinus : (imagePath=undefined?img/nolines_minus.gif:imagePath + /img/nolines_minus.gif) / 无线展开图标 ; this.obj = objName; / 树对象名称(必须一致) this.aNodes = ; / 节点数组 this.aIndent = ; / 当前节点到根节点次级节点(pid=-1),所有父节点是否是同级节点中的最后一个,如果_ls=true则数组对应元素之为0,反之为1 this.root = new Node(-1); / 默认根节点 this.selectedNode = null; / 选中节点的id(tree初始化之前)或它在字节数组中的索引值_ai(tree初始化之后) this.selectedFound = false; / true存在选中的节点;false反之 pleted = false; / tree html 文本构造完成 ;/* * Adds a new node to the node array * 添加节点到节点数组 */dTtotype.add = function(id, pid, name, url, title, target, icon, iconOpen, open) this.aNodesthis.aNodes.length = new Node(id, pid, name, url, title, target, icon, iconOpen, open);/* * Open all nodes * 展开树上所有节点 */dTtotype.openAll = function() this.oAll(true);/* * Close all nodes * 折叠树上所有节点 */dTtotype.closeAll = function() this.oAll(false);/* * Outputs the tree to the page * 生成tree的html字符串 */dTtotype.toString = function() var str = n; if (document.getElementById) 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; pleted = true; return str;/* * Creates the tree structure * 生成节点及其子节点的html字符串 */dTtotype.addNode = function(pNode) var str = ; var n=0; / 默认在整个数组中搜索子节点 if (this.config.inOrder) n = pNode._ai; / 遍历节点数组 for (n; nthis.aNodes.length; n+) / 只处理直接下级节点 if (this.aNodesn.pid = pNode.id) / 临时变量 var cn = this.aNodesn; / 设置节点的父节点属性 cn._p = pNode; / 设置节点的数组索引属性 cn._ai = n; / 设置节点包含子节点标识_hc和同级最后节点标识_ls this.setCS(cn); / 设置节点target 属性 if (!cn.target & this.config.target) cn.target = this.config.target; / 判断一个包含子节点的节点在Cookie中是否是展开状态 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值由id变为_ai(节点数组索引) this.selectedNode = n; / 初始化tree的选中标志 this.selectedFound = true; str += this.node(cn, n); / 判断本级最后一个节点,结束循环 if (cn._ls) break; return str;/* * Creates the node icon, url and text * 生成节点的html字符串 * param node 节点对象; * param nodeId 节点在节点数组中的索引值; */dTtotype.node = function(node, nodeId) / 节点前的线条或空白图标 var str = + 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 += ; else if (!this.config.folderLinks | !node.url) & node._hc & node.pid != this.root.id) str += ; str += ; if (node.url | (!this.config.folderLinks | !node.url) & node._hc) & node.pid != this.root.id) str += ; str += ; / - 以上是节点面板 - / - 以下是包含子节点的面板 - if (node._hc) str += ; / 延迟加载子节点(前一条件针对普通节点,后一条件针对次级根节点) if (node._hc & node._io & node.pid!=-1) | (node._hc & node.pid=-1) str += this.addNode(node); str += ; this.aIndent.pop(); return str;/* * Adds the empty and line icons * 根据当前节点到次级根节点的所有父节点是否是同级最后一个节点的属性 * 确定节点前面显示图标的数量和种类 * param node 节点对象; * param nodeId 节点在节点数组中的索引值; */dTtotype.indent = function(node, nodeId) var str = ; if (this.root.id != node.pid) for (var n=0; nthis.aIndent.length; n+) str += ; (node._ls) ? this.aIndent.push(0) : this.aIndent.push(1); if (node._hc) str += ; else str += ; return str;/* * Checks if a node has any children and if it is the last sibling * 设置节点包含子节点标识_hc和同级最后节点标识_ls */dTtotype.setCS = function(node) var lastId; for (var n=0; nthis.aNodes.length; n+) if (this.aNodesn.pid = node.id) node._hc = true; if (this.aNodesn.pid = node.pid) lastId = this.aNodesn.id; if (lastId=node.id) node._ls = true;/* * Returns the selected node * 从Cookie中取得被选中节点在节点数组中的索引 */dTtotype.getSelected = function() var sn = this.getCookie(cs + this.obj); return (sn) ? sn : null;/* * Highlights the selected node * 使选中的节点高亮显示 * param id 节点在节点数组中的索引值; */dTtotype.s = function(id) / 判断是否允许选中节点 if (!this.config.useSelection) return; / 根据索引值从节点数组中取出节点对象 var cn = this.aNodesid; / 判断包含子节点的节点是否允许选中 if (cn._hc & !this.config.folderLinks) return; / 交换新旧节点的选中状态,改变css if (this.selectedNode != id) if (this.selectedNode | this.selectedNode=0) eOld = document.getElementById(s + this.obj + this.selectedNode); if(eOld) eOld.className = node; eNew = document.getElementById(s + this.obj + id); if(eNew) eNew.className = nodeSel; this.selectedNode = id; if (this.config.useCookies) this.setCookie(cs + this.obj, cn.id); ;/* * 把折叠状态节点的子节点加载到子节点面板中 * param node 节点对象; */dTtotype.delayOpen = function(node) var cn = node; var id = node._ai; / 延迟加载折叠状态节点的子节点 if(cn._io=false) / 获取展示子节点的div var childrenDIV = document.getElementById(d + this.obj + id); / 该结点从未展开过 if(childrenDIV!=null & childrenDIV.innerHTML=) / 将从当前节点到次级根节点之前所有父节点是否是同级节点的最后一个的标志压栈 var nodeTemp = cn; var indentArray = new Array(); / 循环到次级根节点之前 while(nodeTemp._p.id!=this.root.id) indentArrayindentArray.length = (nodeTemp._ls) ? 0 : 1; nodeTemp = nodeTemp._p; / 反向压栈 for(var i = indentArray.length - 1; i=0; i-) this.aIndent.push(indentArrayi); / 初始化下下级所有结点,并得到所有下一级子节点的html字符串,并将一层孩子写入到页面中 childrenDIV.innerHTML = this.addNode(cn); / 清除临时深度 for(var i = 0; i indentArray.length; i+) this.aIndent.pop(); /* * Toggle Open or close * 展开或折叠包某个含子节点的节点 * param id 节点在节点数组中的索引值; */dTtotype.o = function(id) var cn = this.aNodesid; this.delayOpen(cn); 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 * 展开或折叠包全部含子节点的节点 * param status true展开,false折叠; */dTtotype.oAll = function(status) for (var n=0; nthis.aNodes.length; n+) if (this.aNodesn._hc & this.aNodesn.pid != this.root.id) this.delayOpen(this.aNodesn); this.nodeStatus(status, n, this.aNodesn._ls) this.aNodesn._io = status; if (this.config.useCookies) this.updateCookie();/* * Opens the tree to a specific node * 为选中或看到某一节点而展开其所有父节点 * param nId 节点的id而不是节点数组索引; * param bSelect true展开后选中节点,false反之; */dTtotype.openTo = function(nId, bSelect) / 根据节点id获取节点对象 for (var n=0; nthis.aNodes.length; n+) if (this.aNodesn.id = nId) / 节点id转化为节点在节点数组中的索引值 nId=n; break; var cn=this.aNodesnId; / 保存指定节点及其到次级根节点前的全部父节点的临时数组变量 var parentArray = new Array(); / 从低级到高级把父节点压入堆栈 while(cn.pid!=-1) parentArray.push(cn); for (var n=0; n0) this.delayOpen(cn); this.nodeStatus(true, cn._ai, cn._ls); cn._io = true; if (this.config.closeSameLevel) this.closeLevel(cn); if (this.config.useCookies) this.updateCookie(); ;/* * Closes all nodes on the same level as certain node * 折叠同级的其他包含有子节点的节点,使得只有自己处于展开状态 * param node 节点对象; */dTtotype.closeLevel = function(node) for (var n=0; nthis.aNodes.length; n+) if (this.aNodesn.pid = node.pid & this.aNodesn.id != node.id & this.aNodesn._hc) this.nodeStatus(false, n, this.aNodesn._ls); this.aNodesn._io = false; this.closeAllChildren(this.aNodesn); /* * Closes all children of a node * 折叠同级的其他包含有子节点的节点,使得只有当前节点处于展开状态 * param node 节点对象; */dTtotype.closeAllChildren = function(node) for (var n=0; nthis.aNodes.length; n+) if (this.aNodesn.pid = node.id & this.aNodesn._hc) if (this.aNodesn._io) this.nodeStatus(false, n, this.aNodesn._ls); this.aNodesn._io = false; this.closeAllChildren(this.aNodesn); /* * Change the status of a node(open or closed) * 改变节点的状态(展开或折叠) * param status true展开,false折叠; * param id 节点的数组索引值(_ai); * param bottom 是否是本级最后一个节点(_ls); */dTtotype.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.aNodesid.iconOpen : this.aNodesid.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 * 清空Cookie中保存的展开状态节点id集合、选中的节点id(不是节点的字节数组索引_ai) */dTtotype.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 * 在Cookie中保存一个键值对 */dTtotype.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 * 从Cookie中获取一个键名的值 */dTtotype.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 * 保存展开状态节点的ID到Cookie中 */dTtotype.updateCookie = function() var str = ; for (var n=0; nthis.aNodes.length; n+) if (this.aNodesn._io & this.aNodesn.pid != this.root.id) if (str) str += .; str += this.aNodesn.id; this.setCookie(co + this.obj, str);/* * Cookie Checks if a node id is in a cookie * 检查一个节点的id是否保存在Cookie中,以判断节点展开或折叠 */dTtotype.isOpen = function(id) var aOpen = this.getCookie(co + this.obj).split(.); for (var n=0; naOpen.length; n+) if (aOpenn = id) return true; return false;/ If Push and pop is not implemented by the browser/ 如果数组类型没有定义 Push 和 pop 方法,就使用自定义的Push 和 pop实现 if (!Atotype.push
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024北海市公务员行测附参考答案详解【轻巧夺冠】
- 酒、饮料及精制茶制造人员考试综合练习及答案详解【必刷】
- 2024危险化学品安全作业自我提分评估及完整答案详解(易错题)
- 2024年高职单招综合提升测试卷附完整答案详解【夺冠系列】
- 智慧树知道网课《通风工程施工》课后章节测试满分答案
- 2024安全员考试每日一练试卷附参考答案详解(培优B卷)
- 2024邮政行业职业技能鉴定试题附参考答案详解(夺分金卷)
- 2025年江西省高校毕业生“三支一扶”计划招募(693名)考前自测高频考点模拟试题及答案详解参考
- 2025年水利安全员真题库附含答案
- 2025年高压电工继电保护原理及设备维护保养试题卷(附答案)
- 钢筋混凝土管道施工方案
- 小学数学新教材中“图形与几何”领域的内容结构分析
- DB32-T 4981-2024 公路水运工程平安工地建设规范
- 2025年成人高考成考(专升本)教育理论试题与参考答案
- 垃圾分类标准体系构建研究
- 新建屋顶分布式光伏发电项目施工方案
- 新生儿病房探视制度
- 2024年《13464电脑动画》自考复习题库(含答案)
- 给我一颗原始星球 (小镇舍长)
- 第一次月考卷(扬州专用)-2024-2025学年七年级数学上学期第一次月考模拟卷(江苏专用)
- 09G自动变速箱阀体维修案例
评论
0/150
提交评论