Dojo - Programmatically hide popup menu
http://stackoverflow.com/questions/16317142/show-dijit-menu-programatically
HTML
<div>Click a button and within 3 seconds right-click the div to open the popup ... then wait!</div>
<button id="btnPopupClose">After 3s timeout call popup.close()</button>
<button id="btnTriggerBlur">After 3s timeout trigger 'blur'</button>
<div id="progmenu" style="border: 1px red solid">Menu - Right click me</div>
JavaScript
var pMenu;
require(["dojo/ready", "dijit/Menu", "dijit/MenuItem", "dijit/PopupMenuItem"], function (ready, Menu, MenuItem) {
ready(function () {
pMenu = new Menu({
});
pMenu.addChild(new MenuItem({
label: "Simple menu item"
}));
pMenu.startup();
});
});
function waitThenClose(fn, ms) {
setTimeout(function () {
console.log("Timeout " + new Date());
fn();
}, ms);
}
require(["dojo/dom", "dojo/on", "dijit/popup"], function (dom, on, popup) {
var timeout = 3000;
on(dom.byId("btnPopupClose"), "click", function () {
waitThenClose(function () {
if (pMenu) {
console.log("Calling .close()");
popup.close(pMenu);
}
}, timeout);
});
on(dom.byId("btnTriggerBlur"), "click", function () {
waitThenClose(function () {
var opts = {
bubbles: true,
cancelable: true
};
console.log("emitting blur event");
on.emit(pMenu.domNode, "blur", opts);
}, timeout);
});
});