📄 treenodev3.js
字号:
/* Copyright (c) 2004-2006, The Dojo Foundation All Rights Reserved. Licensed under the Academic Free License version 2.1 or above OR the modified BSD license. For more information on Dojo licensing, see: http://dojotoolkit.org/community/licensing.shtml*/dojo.provide("dojo.widget.TreeNodeV3");dojo.require("dojo.html.*");dojo.require("dojo.event.*");dojo.require("dojo.io.*");dojo.require("dojo.widget.TreeWithNode");dojo.widget.defineWidget( "dojo.widget.TreeNodeV3", [dojo.widget.HtmlWidget, dojo.widget.TreeWithNode], function() { this.actionsDisabled = []; this.object = {}; },{ tryLazyInit: true, /* * Basic actions one can perform on nodes and, some(addchild) on trees */ actions: { MOVE: "MOVE", DETACH: "DETACH", EDIT: "EDIT", ADDCHILD: "ADDCHILD", SELECT: "SELECT" }, labelClass: "", contentClass: "", expandNode: null, labelNode: null, /** * can't call it nodeType cause of IE problems */ nodeDocType: "", selected: false, getnodeDocType: function() { return this.nodeDocType; }, cloneProperties: ["actionsDisabled","tryLazyInit","nodeDocType","objectId","object", "title","isFolder","isExpanded","state"], /** * copy cloneProperties with recursion into them * contains "copy constructor" */ clone: function(deep) { var ret = new this.constructor(); //dojo.debug("start cloning props "+this); for(var i=0; i<this.cloneProperties.length; i++) { var prop = this.cloneProperties[i]; //dojo.debug("cloning "+prop+ ":" +this[prop]); ret[prop] = dojo.lang.shallowCopy(this[prop], true); } if (this.tree.unsetFolderOnEmpty && !deep && this.isFolder) { ret.isFolder = false; } //dojo.debug("cloned props "+this); ret.toggleObj = this.toggleObj; dojo.widget.manager.add(ret); ret.tree = this.tree; ret.buildRendering({},{}); ret.initialize({},{}); if (deep && this.children.length) { //dojo.debug("deeper copy start"); for(var i=0; i<this.children.length; i++) { var child = this.children[i]; //dojo.debug("copy child "+child); if (child.clone) { ret.children.push(child.clone(deep)); } else { ret.children.push(dojo.lang.shallowCopy(child, deep)); } } //dojo.debug("deeper copy end"); ret.setChildren(); } return ret; }, markProcessing: function() { this.markProcessingSavedClass = dojo.html.getClass(this.expandNode); dojo.html.setClass(this.expandNode, this.tree.classPrefix+'ExpandLoading'); }, unmarkProcessing: function() { dojo.html.setClass(this.expandNode, this.markProcessingSavedClass); }, /** * get information from args & parent, then build rendering */ buildRendering: function(args, fragment, parent) { //dojo.debug("Build for "+args.toSource()); if (args.tree) { this.tree = dojo.lang.isString(args.tree) ? dojo.widget.manager.getWidgetById(args.tree) : args.tree; } else if (parent && parent.tree) { this.tree = parent.tree; } if (!this.tree) { dojo.raise("Can't evaluate tree from arguments or parent"); } //dojo.profile.start("buildRendering - cloneNode"); this.domNode = this.tree.nodeTemplate.cloneNode(true); this.expandNode = this.domNode.firstChild; this.contentNode = this.domNode.childNodes[1]; this.labelNode = this.contentNode.firstChild; if (this.labelClass) { dojo.html.addClass(this.labelNode, this.labelClass); } if (this.contentClass) { dojo.html.addClass(this.contentNode, this.contentClass); } //dojo.profile.end("buildRendering - cloneNode"); this.domNode.widgetId = this.widgetId; //dojo.profile.start("buildRendering - innerHTML"); this.labelNode.innerHTML = this.title; //dojo.profile.end("buildRendering - innerHTML"); }, isTreeNode: true, object: {}, title: "", isFolder: null, // set by widget depending on children/args contentNode: null, // the item label expandClass: "", isExpanded: false, containerNode: null, getInfo: function() { // No title here (title may be widget) var info = { widgetId: this.widgetId, objectId: this.objectId, index: this.getParentIndex() } return info; }, setFolder: function() { //dojo.debug("SetFolder in "+this); this.isFolder = true; this.viewSetExpand(); if (!this.containerNode) { // maybe this node was unfolderized and still has container this.viewAddContainer(); // all folders have container. } //dojo.debug("publish "+this.tree.eventNames.setFolder); dojo.event.topic.publish(this.tree.eventNames.afterSetFolder, { source: this }); }, initialize: function(args, frag, parent) { //dojo.profile.start("initialize"); /** * first we populate current widget from args, * then use its data to initialize * args may be empty, all data inside widget for copy constructor */ if (args.isFolder) { this.isFolder = true; } if (this.children.length || this.isFolder) { //dojo.debug("children found"); //dojo.debug(this.children); //dojo.debug("isFolder "+args.isFolder); // viewSetExpand for Folder is set here also this.setFolder(); } else { // set expandicon for leaf this.viewSetExpand(); } for(var i=0; i<this.actionsDisabled.length;i++) { this.actionsDisabled[i] = this.actionsDisabled[i].toUpperCase(); } //dojo.debug("publish "+this.tree.eventNames.changeTree); dojo.event.topic.publish(this.tree.eventNames.afterChangeTree, {oldTree:null, newTree:this.tree, node:this} ); //dojo.profile.end("initialize"); //dojo.debug("initialize out "+this); //dojo.debug(this+" parent "+parent); }, unsetFolder: function() { this.isFolder = false; this.viewSetExpand(); dojo.event.topic.publish(this.tree.eventNames.afterUnsetFolder, { source: this }); }, insertNode: function(parent, index) { if (!index) index = 0; //dojo.debug("insertNode "+this+" parent "+parent+" before "+index); if (index==0) { dojo.html.prependChild(this.domNode, parent.containerNode); } else { dojo.html.insertAfter(this.domNode, parent.children[index-1].domNode); } }, updateTree: function(newTree) { if (this.tree === newTree) { return; } var oldTree = this.tree; dojo.lang.forEach(this.getDescendants(), function(elem) { elem.tree = newTree; }); /** * UNTESTED * changes class prefix for all domnodes when moving between trees */ if (oldTree.classPrefix != newTree.classPrefix) { var stack = [this.domNode] var elem; var reg = new RegExp("(^|\\s)"+oldTree.classPrefix, "g"); while (elem = stack.pop()) { for(var i=0; i<elem.childNodes.length; i++) { var childNode = elem.childNodes[i] if (childNode.nodeDocType != 1) continue; // change prefix for classes dojo.html.setClass(childNode, dojo.html.getClass(childNode).replace(reg, '$1'+newTree.classPrefix)); stack.push(childNode); } } } var message = {oldTree:oldTree, newTree:newTree, node:this} dojo.event.topic.publish(this.tree.eventNames.afterChangeTree, message ); dojo.event.topic.publish(newTree.eventNames.afterChangeTree, message ); }, /** * called every time the widget is added with createWidget or created wia markup * from addChild -> registerChild or from postInitialize->registerChild * not called in batch procession * HTML & widget.createWidget only * Layout MUST be removed when node is detached * */ addedTo: function(parent, index, dontPublishEvent) { //dojo.profile.start("addedTo"); //dojo.debug(this + " addedTo "+parent+" index "+index); //dojo.debug(parent.children); //dojo.debug(parent.containerNode.innerHTML); //dojo.debug((new Error()).stack); if (this.tree !== parent.tree) { this.updateTree(parent.tree); } if (parent.isTreeNode) { if (!parent.isFolder) { //dojo.debug("folderize parent "+parent); parent.setFolder(); parent.state = parent.loadStates.LOADED; } } var siblingsCount = parent.children.length; // setFolder works BEFORE insertNode this.insertNode(parent, index); this.viewAddLayout(); //dojo.debug("siblings "+parent.children); if (siblingsCount > 1) { if (index == 0 && parent.children[1] instanceof dojo.widget.Widget) { parent.children[1].viewUpdateLayout(); } if (index == siblingsCount-1 && parent.children[siblingsCount-2] instanceof dojo.widget.Widget) { parent.children[siblingsCount-2].viewUpdateLayout(); } } else if (parent.isTreeNode) { // added as the first child //dojo.debug("added as first"); parent.viewSetHasChildren(); } if (!dontPublishEvent) { var message = {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -