Login Register

DOM Node clicked to open dijit.Menu

I just had to hack a bit of code in dijit.Menu.js to make it record the DOM node clicked by the user to open the Menu, so I thought it could be nice if Dojo had this functionality included in next revisions.

All I changed were 2 lines, that I added to function _openMyself, circa lines 239 and 245:

var self=this;
self.targetNode = e.target;     // <--- Added this line
var savedFocus = dijit.getFocus(this);
function closeAndRestoreFocus(){
  // user has clicked on a menu or popup
  dijit.focus(savedFocus);
  dijit.popup.close(self);
  self.targetNode = null;       // <--- Added this line
}

That allows me to programmatically find out which DOM Node the user clicked to open up the menu, like this:

.
.
.
function onMenuOpenHandler() {
  var tgt = this.targetNode; // <--- This is the DOM Node the user clicked!
  .
  .
  .

Cheers

ER

You could file and enhancement request in trac.dojotoolkit.org, although you should sign the cla and attach a patch to the bug after filing it. Thanks.