Opened 14 years ago
Closed 13 years ago
#4353 closed defect (wontfix)
TreeNode events afterExpand and afterCollapse not published properly
Reported by: | guest | Owned by: | anonymous |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | Dijit | Version: | 0.9 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
In dojo 0.9.0 release and Firefox 2. I'm trying to catch the 'afterExpand' event of a TreeNode?. After failing with this (code below), I dug into the dijit code and found out weird stuff. setChildren() of a TreeNode? looks like this:
setChildren: function(items){ var ret = dijit.Tree.superclass.setChildren.apply(this, arguments); // create animations for showing/hiding the children this._wipeIn = dojo.fx.wipeIn({node: this.containerNode, duration: 250}); dojo.connect(this.wipeIn, "onEnd", dojo.hitch(this, "_afterExpand")); this._wipeOut = dojo.fx.wipeOut({node: this.containerNode, duration: 250}); dojo.connect(this.wipeOut, "onEnd", dojo.hitch(this, "_afterCollapse")); return ret; }, // 'afterExpand' gets published here _afterExpand: function(){ this.onShow(); this._publish("afterExpand", {node: this}); },
dojo.connect() calls point to non-existing functions .wipeOut and .wipeIn (should be ._wipeOut and ._wipeIn I think).
Here's my attemp to catch the published events
var topics = []; function treeEventHandler(/* Event Message */ message){ if(message.event == "toggleOpen"){ //DEBUG console.debug("treeEventHandler: caught toggleOpen event for node "+message.node); // appears accordingly, so far so good // Add topic for the opened node if(!message.node.isExpanded){ topics.push(dojo.subscribe(message.node.id, null, nodeEventHandler)); } } } function nodeEventHandler(/* EventMessage */ message){ if(message.event == "afterExpand"){ //DEBUG console.debug("nodeEventHandler: caught afterExpand for node "+message.node); // this never gets called } } function init(){ topics.push(dojo.subscribe("mytree", null, treeEventHandler)); // tree event for expanding a node }
And here's my current workaround, which is just a rewrite of the current code, omitting calls to onShow/onHide and so on.
function init_tree_nodes(){ var childNodes = dijit.byId("mytree").getChildren(); dojo.forEach(childNodes, function(child, idx){ // rewrite the nodes setChildren _this = child; child.setChildren = function(items){ var ret = dijit.Tree.superclass.setChildren.apply(_this, arguments); //DEBUG console.debug("New setChildren called, creating animations."); // create animations for showing/hiding the children _this._wipeIn = dojo.fx.wipeIn({node: _this.containerNode, duration: 250}); dojo.connect(_this._wipeIn, "onEnd", _this, _this._afterExpand); _this._wipeOut = dojo.fx.wipeOut({node: _this.containerNode, duration: 250}); dojo.connect(_this._wipeOut, "onEnd", _this, _this._afterCollapse); return ret; }; child._afterExpand = function(){dojo.publish(_this.id, [{event: "afterExpand", node: _this, tree:_this.tree}]);}; child._afterCollapse = function(){dojo.publish(_this.id, [{event: "afterExpand", node: _this, tree:_this.tree}]);}; topics.push(dojo.subscribe(child.id, null, nodeEventHandler)); }); } function init(){ init_tree_nodes(); }
Change History (3)
comment:1 follow-up: 2 Changed 14 years ago by
comment:2 Changed 13 years ago by
Replying to bill:
In the newest version of tree we just don't publish those notifications at all (either via topics or connect points). Is there some reason you need to know when a node has finished loading and expanding?
Yes. I'm building my own DnD for Tree. I cannot apply the DnD classes to Tree nodes until they are actually created. I want to catch the event when they're done, and then modify the node classes. This applies to any class modifications anyone wants to do when TreeNodes? are being toggled open.
comment:3 Changed 13 years ago by
Component: | General → Dijit |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
Oh... well you don't really need topics for that (or for anything related to the tree). You can just connect to the appropriate functions in the tree code. But also, Dustin is working on DnD for the tree and will check in shortly.
In the newest version of tree we just don't publish those notifications at all (either via topics or connect points). Is there some reason you need to know when a node has finished loading and expanding?