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

📄 treeview.js

📁 原名JSPackager
💻 JS
📖 第 1 页 / 共 2 页
字号:
YAHOO.widget.TreeView = function (id) {if (id) {this.init(id);}};YAHOO.widget.TreeView.nodeCount = 0;YAHOO.widget.TreeView.prototype = {id:null, _el:null, _nodes:null, locked:false, _expandAnim:null, _collapseAnim:null, _animCount:0, maxAnim:2, setExpandAnim:function (type) {if (YAHOO.widget.TVAnim.isValid(type)) {this._expandAnim = type;}}, setCollapseAnim:function (type) {if (YAHOO.widget.TVAnim.isValid(type)) {this._collapseAnim = type;}}, animateExpand:function (el) {if (this._expandAnim && this._animCount < this.maxAnim) {var tree = this;var a = YAHOO.widget.TVAnim.getAnim(this._expandAnim, el, function () {tree.expandComplete();});if (a) {++this._animCount;a.animate();}return true;}return false;}, animateCollapse:function (el) {if (this._collapseAnim && this._animCount < this.maxAnim) {var tree = this;var a = YAHOO.widget.TVAnim.getAnim(this._collapseAnim, el, function () {tree.collapseComplete();});if (a) {++this._animCount;a.animate();}return true;}return false;}, expandComplete:function () {--this._animCount;}, collapseComplete:function () {--this._animCount;}, init:function (id) {this.id = id;if ("string" !== typeof id) {this._el = id;this.id = this.generateId(id);}this._nodes = [];YAHOO.widget.TreeView.trees[this.id] = this;this.root = new YAHOO.widget.RootNode(this);}, draw:function () {var html = this.root.getHtml();this.getEl().innerHTML = html;this.firstDraw = false;}, getEl:function () {if (!this._el) {this._el = document.getElementById(this.id);}return this._el;}, regNode:function (node) {this._nodes[node.index] = node;}, getRoot:function () {return this.root;}, setDynamicLoad:function (fnDataLoader, iconMode) {this.root.setDynamicLoad(fnDataLoader, iconMode);}, expandAll:function () {if (!this.locked) {this.root.expandAll();}}, collapseAll:function () {if (!this.locked) {this.root.collapseAll();}}, getNodeByIndex:function (nodeIndex) {var n = this._nodes[nodeIndex];return (n) ? n : null;}, getNodeByProperty:function (property, value) {for (var i in this._nodes) {var n = this._nodes[i];if (n.data && value == n.data[property]) {return n;}}return null;}, getNodesByProperty:function (property, value) {var values = [];for (var i in this._nodes) {var n = this._nodes[i];if (n.data && value == n.data[property]) {values.push(n);}}return (values.length) ? values : null;}, removeNode:function (node, autoRefresh) {if (node.isRoot()) {return false;}var p = node.parent;if (p.parent) {p = p.parent;}this._deleteNode(node);if (autoRefresh && p && p.childrenRendered) {p.refresh();}return true;}, removeChildren:function (node) {while (node.children.length) {this._deleteNode(node.children[0]);}node.childrenRendered = false;node.dynamicLoadComplete = false;node.expand();node.collapse();}, _deleteNode:function (node) {this.removeChildren(node);this.popNode(node);}, popNode:function (node) {var p = node.parent;var a = [];for (var i = 0, len = p.children.length; i < len; ++i) {if (p.children[i] != node) {a[a.length] = p.children[i];}}p.children = a;p.childrenRendered = false;if (node.previousSibling) {node.previousSibling.nextSibling = node.nextSibling;}if (node.nextSibling) {node.nextSibling.previousSibling = node.previousSibling;}delete this._nodes[node.index];}, toString:function () {return "TreeView " + this.id;}, generateId:function (el) {var id = el.id;if (!id) {id = "yui-tv-auto-id-" + YAHOO.widget.TreeView.counter;YAHOO.widget.TreeView.counter++;}return id;}, onExpand:function (node) {}, onCollapse:function (node) {}};YAHOO.widget.TreeView.trees = [];YAHOO.widget.TreeView.counter = 0;YAHOO.widget.TreeView.getTree = function (treeId) {var t = YAHOO.widget.TreeView.trees[treeId];return (t) ? t : null;};YAHOO.widget.TreeView.getNode = function (treeId, nodeIndex) {var t = YAHOO.widget.TreeView.getTree(treeId);return (t) ? t.getNodeByIndex(nodeIndex) : null;};YAHOO.widget.TreeView.addHandler = function (el, sType, fn, capture) {capture = (capture) ? true : false;if (el.addEventListener) {el.addEventListener(sType, fn, capture);} else {if (el.attachEvent) {el.attachEvent("on" + sType, fn);} else {el["on" + sType] = fn;}}};YAHOO.widget.TreeView.preload = function (prefix) {prefix = prefix || "ygtv";var styles = ["tn", "tm", "tmh", "tp", "tph", "ln", "lm", "lmh", "lp", "lph", "loading"];var sb = [];for (var i = 0; i < styles.length; ++i) {sb[sb.length] = "<span class=\"" + prefix + styles[i] + "\">&#160;</span>";}var f = document.createElement("DIV");var s = f.style;s.position = "absolute";s.top = "-1000px";s.left = "-1000px";f.innerHTML = sb.join("");document.body.appendChild(f);};YAHOO.widget.TreeView.addHandler(window, "load", YAHOO.widget.TreeView.preload);YAHOO.widget.Node = function (oData, oParent, expanded) {if (oData) {this.init(oData, oParent, expanded);}};YAHOO.widget.Node.prototype = {index:0, children:null, tree:null, data:null, parent:null, depth:-1, href:null, target:"_self", expanded:false, multiExpand:true, renderHidden:false, childrenRendered:false, dynamicLoadComplete:false, previousSibling:null, nextSibling:null, _dynLoad:false, dataLoader:null, isLoading:false, hasIcon:true, iconMode:0, _type:"Node", init:function (oData, oParent, expanded) {this.data = oData;this.children = [];this.index = YAHOO.widget.TreeView.nodeCount;++YAHOO.widget.TreeView.nodeCount;this.expanded = expanded;if (oParent) {oParent.appendChild(this);}}, applyParent:function (parentNode) {if (!parentNode) {return false;}this.tree = parentNode.tree;this.parent = parentNode;this.depth = parentNode.depth + 1;if (!this.href) {this.href = "javascript:" + this.getToggleLink();}if (!this.multiExpand) {this.multiExpand = parentNode.multiExpand;}this.tree.regNode(this);parentNode.childrenRendered = false;for (var i = 0, len = this.children.length; i < len; ++i) {this.children[i].applyParent(this);}return true;}, appendChild:function (childNode) {if (this.hasChildren()) {var sib = this.children[this.children.length - 1];sib.nextSibling = childNode;childNode.previousSibling = sib;}this.children[this.children.length] = childNode;childNode.applyParent(this);return childNode;}, appendTo:function (parentNode) {return parentNode.appendChild(this);}, insertBefore:function (node) {var p = node.parent;if (p) {if (this.tree) {this.tree.popNode(this);}var refIndex = node.isChildOf(p);p.children.splice(refIndex, 0, this);if (node.previousSibling) {node.previousSibling.nextSibling = this;}this.previousSibling = node.previousSibling;this.nextSibling = node;node.previousSibling = this;this.applyParent(p);}return this;}, insertAfter:function (node) {var p = node.parent;if (p) {if (this.tree) {this.tree.popNode(this);}var refIndex = node.isChildOf(p);if (!node.nextSibling) {return this.appendTo(p);}p.children.splice(refIndex + 1, 0, this);node.nextSibling.previousSibling = this;this.previousSibling = node;this.nextSibling = node.nextSibling;node.nextSibling = this;this.applyParent(p);}return this;}, isChildOf:function (parentNode) {if (parentNode && parentNode.children) {for (var i = 0, len = parentNode.children.length; i < len; ++i) {if (parentNode.children[i] === this) {return i;}}}return -1;}, getSiblings:function () {return this.parent.children;}, showChildren:function () {if (!this.tree.animateExpand(this.getChildrenEl())) {if (this.hasChildren()) {this.getChildrenEl().style.display = "";}}}, hideChildren:function () {if (!this.tree.animateCollapse(this.getChildrenEl())) {this.getChildrenEl().style.display = "none";}}, getElId:function () {return "ygtv" + this.index;}, getChildrenElId:function () {return "ygtvc" + this.index;}, getToggleElId:function () {return "ygtvt" + this.index;}, getEl:function () {return document.getElementById(this.getElId());}, getChildrenEl:function () {return document.getElementById(this.getChildrenElId());}, getToggleEl:function () {return document.getElementById(this.getToggleElId());}, getToggleLink:function () {return "YAHOO.widget.TreeView.getNode('" + this.tree.id + "'," + this.index + ").toggle()";}, collapse:function () {if (!this.expanded) {return;}var ret = this.tree.onCollapse(this);if ("undefined" != typeof ret && !ret) {return;}if (!this.getEl()) {this.expanded = false;return;}this.hideChildren();this.expanded = false;if (this.hasIcon) {this.getToggleEl().className = this.getStyle();}}, expand:function () {if (this.expanded) {return;}var ret = this.tree.onExpand(this);if ("undefined" != typeof ret && !ret) {return;}if (!this.getEl()) {this.expanded = true;return;}if (!this.childrenRendered) {this.getChildrenEl().innerHTML = this.renderChildren();} else {}this.expanded = true;if (this.hasIcon) {this.getToggleEl().className = this.getStyle();}if (this.isLoading) {this.expanded = false;return;}if (!this.multiExpand) {var sibs = this.getSiblings();for (var i = 0; i < sibs.length; ++i) {if (sibs[i] != this && sibs[i].expanded) {sibs[i].collapse();}}}this.showChildren();}, getStyle:function () {if (this.isLoading) {return "ygtvloading";} else {var loc = (this.nextSibling) ? "t" : "l";var type = "n";if (this.hasChildren(true) || (this.isDynamic() && !this.getIconMode())) {type = (this.expanded) ? "m" : "p";}return "ygtv" + loc + type;}}, getHoverStyle:function () {var s = this.getStyle();if (this.hasChildren(true) && !this.isLoading) {s += "h";}return s;}, expandAll:function () {for (var i = 0; i < this.children.length; ++i) {var c = this.children[i];if (c.isDynamic()) {alert("Not supported (lazy load + expand all)");break;} else {if (!c.multiExpand) {alert("Not supported (no multi-expand + expand all)");break;} else {c.expand();c.expandAll();}}}}, collapseAll:function () {for (var i = 0; i < this.children.length; ++i) {this.children[i].collapse();this.children[i].collapseAll();}}, setDynamicLoad:function (fnDataLoader, iconMode) {if (fnDataLoader) {this.dataLoader = fnDataLoader;this._dynLoad = true;

⌨️ 快捷键说明

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