There actually is a function to find the enclosing widget already in the dijit library.
var aWidget = dijit.getEnclosingWidget(e.target); // pass a domNode
You can check out http://dojotoolkit.org/reference-guide/1.9/dijit/getEnclosingWidget.html for the full documentation.
Got something, but is there a better way?
var enclosedContext = this.findEnclosedContext(this.domNode.parentNode);
findEnclosedContext: function (node) {
var count = 2;
while (node) {
if (node.tagName && node.tagName.toLowerCase() == "body") {
return;
} else {
var id = node.getAttribute && node.getAttribute("widgetId"),
widget = id && dijit.byId(id);
if (widget) {
count--;
if (count === 0)
return widget.mxcontext;
}
node = node.parentNode;
}
}
},