1、dtree.js源码

function Node(id, pid, name, url, title, target, icon, iconOpen, open) {
this.id = id; // 节点id
this.pid = pid; // 节点父id
this.name = 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; // 保存父节点对象; }; 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反之
this.completed = false; // tree html 文本构造完成
}; dTree.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);
}; dTree.prototype.openAll = function() {
this.oAll(true);
}; dTree.prototype.closeAll = function() {
this.oAll(false);
}; dTree.prototype.toString = function() { var str = '<div class="dtree">\n';
if (document.getElementByIdx) {
if (this.config.useCookies) this.selectedNode = this.getSelected();
str += this.addNode(this.root);
} else str += 'Browser not supported.';
str += '</div>';
if (!this.selectedFound) this.selectedNode = null;
this.completed = true; return str;
}; dTree.prototype.addNode = function(pNode) {
var str = '';
var n=0; // 默认在整个数组中搜索子节点
if (this.config.inOrder) n = pNode._ai; // 遍历节点数组
for (n; n<this.aNodes.length; n++) { // 只处理直接下级节点
if (this.aNodes[n].pid == pNode.id) { // 临时变量
var cn = this.aNodes[n]; // 设置节点的父节点属性
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;
}; dTree.prototype.node = function(node, nodeId) {
// 节点前的线条或空白图标
var str = '<div class="dTreeNode">' + 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 += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />';
}
// 节点文本及动作方法(带超链接、不带超链接)
if (node.url) {
str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"';
if (node.title) str += ' title="' + node.title + '"';
if (node.target) str += ' target="' + node.target + '"';
if (this.config.useStatusText) str += ' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" ';
if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))
str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"';
str += '>';
} else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id){
str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node">'; }
str += node.name;
if ((node.url || ((!this.config.folderLinks || !node.url) && node._hc)) && node.pid != this.root.id) str += '</a>';
str += '</div>';

DTree的改进与使用经验的更多相关文章

  1. dTree

    1.dtree.js源码 /*--------------------------------------------------| | dTree 2.05 | www.destroydrop.co ...

  2. dTree 动态生成树

    http://luohua.iteye.com/blog/451453 dTree 主页:http://destroydrop.com/javascripts/tree/ dTree是个很方便在页面生 ...

  3. .net_DevExpress控件使用经验总结

    (转)DevExpress控件使用经验总结DevExpress是一个比较有名的界面控件套件,提供了一系列的界面控件套件的DotNet界面控件.本文主要介绍我在使用DevExpress控件过程中,遇到或 ...

  4. dTree动态生成树(后台处理,简化前台操作)

    dTree是个很方便在页面生成树的 js 控件,如果你下载了,我猜里在几分钟之内便能在页面上显示出一颗树来. 它本身给的例子是通过一些静态数据构造树,下面我说一种通过查询的数据动态构造树的方法. 例子 ...

  5. 120项改进:开源超级爬虫Hawk 2.0 重磅发布!

    沙漠君在历时半年,修改无数bug,更新一票新功能后,在今天隆重推出最新改进的超级爬虫Hawk 2.0! 啥?你不知道Hawk干吗用的? 这是采集数据的挖掘机,网络猎杀的重狙!半年多以前,沙漠君写了一篇 ...

  6. 基于改进人工蜂群算法的K均值聚类算法(附MATLAB版源代码)

    其实一直以来也没有准备在园子里发这样的文章,相对来说,算法改进放在园子里还是会稍稍显得格格不入.但是最近邮箱收到的几封邮件让我觉得有必要通过我的博客把过去做过的东西分享出去更给更多需要的人.从论文刊登 ...

  7. 挑子学习笔记:两步聚类算法(TwoStep Cluster Algorithm)——改进的BIRCH算法

    转载请标明出处:http://www.cnblogs.com/tiaozistudy/p/twostep_cluster_algorithm.html 两步聚类算法是在SPSS Modeler中使用的 ...

  8. ITTC数据挖掘平台介绍(四) 框架改进和新功能

    本数据挖掘框架在这几个月的时间内,有了进一步的功能增强 一. 超大网络的画布显示虚拟化     如前几节所述,框架采用了三级层次实现,分别是数据,抽象Node和绘图的DataPoint,结构如下:   ...

  9. C# 3.0新语言特性和改进(一)

    引言 关于C#3.0的特性,园子里已经有了一大把,可能大家都很熟悉了,虽然本人开发中使用过,但自己还是需要记录一下,总结一下.同时也是后面写Linq知识的基础.希望有兴趣的朋友,可以看看. C# 3. ...

随机推荐

  1. const分别在C和C++语言里的含义和实现机制

    const的含义        简单地说:const在c语言中表示只读的变量,而在c++语言中表示常量. C语言 const是constant的缩写,是恒定不变的意思,也翻译为常量,但是很多人都认为被 ...

  2. Web前端开发最佳实践(7):使用合理的技术方案来构建小图标

    大家都对网站上使用的小图标肯定都不陌生,这些小图标作为网站内容的点缀,增加了网站的美观度,提高了用户体验,可是你有没有看过在这些网站中使用的图标都是用什么技术实现的?虽然大部分网站还是使用普通的图片实 ...

  3. python根据字典自动生成一组省和市名

    字典如下: dict={ '河北省':['石家庄','唐山','秦皇岛','承德'], '山东省':['济南','青岛','临沂','淄博'], '湖南省':['长沙','衡阳','湘潭','邵阳', ...

  4. matplotlib使用总结

    一.简介 Matplotlib 是一个 Python 的 2D绘图库,它以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形.通过 Matplotlib,开发者可以仅需要几行代码,便可以生成绘图 ...

  5. JPA实体类中的注解

    @Entity 标注于实体类上,通常和@Table是结合使用的,代表是该类是实体类@Table 标注于实体类上,表示该类映射到数据库中的表,没有指定名称的话就表示与数据库中表名为该类的简单类名的表名相 ...

  6. web服务端安全之暴力破解

    一.暴力破解 指攻击者通过遍历或字典的方式,向目标发起大量请求,通过判断返回数据包的特征来找出正确的验证信息,从而绕过验证机制. 二.常见场景 用户登录处的账号密码暴力破解: 人机验证机制容易绕过,如 ...

  7. 【BZOJ 2986】 莫比乌斯函数+容斥原理

    2986: Non-Squarefree Numbers Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 337  Solved: 156 Descri ...

  8. JMS开发指南

    1.JMS消息的异步与同步接收 消息的异步接收: 异步接收是指当消息到达时,主动通知客户端,即当消息到达时转发到客户端.JMS客户端可以通过注册一个实现MessageListener接口的对象到Mes ...

  9. Luogu 4492 [HAOI2018]苹果树 组合数

    https://www.luogu.org/problemnew/show/P4492 找每个编号的点的父边的贡献,组合数和阶乘就能算了. 我考场上怎么就是没想到呢. 调了好久好久好久好久调不出来,样 ...

  10. 奇妙的音乐-----WriteUp

    据说flag就藏在这段音乐中,请仔细听. 格式:CTF{} 解题链接:http://ctf5.shiyanbar.com/crypto/123.zip 下载压缩包后里面有个音乐的zip文件  但是加密 ...