diff options
author | Kris Maglione <maglione.k@gmail.com> | 2011-09-26 23:10:59 -0400 |
---|---|---|
committer | Kris Maglione <maglione.k@gmail.com> | 2011-09-26 23:10:59 -0400 |
commit | 0f9cb3100bbf32e0d7d89ff9eebe1dac376a4484 (patch) | |
tree | 7768fee9b65ae736964971f754691e37b9551566 /common | |
parent | 775612f66d548f3374faa4e197e5aab905dcea1c (diff) | |
download | pentadactyl-0f9cb3100bbf32e0d7d89ff9eebe1dac376a4484.tar.gz |
:emenu invocation efficiency enhancement.
Diffstat (limited to 'common')
-rw-r--r-- | common/content/dactyl.js | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 533941e4..c649dbd5 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -135,31 +135,27 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { set: function mode(val) modes.main = val }), - get menuItems() { - function dispatch(node, name) { - let event = node.ownerDocument.createEvent("Events"); - event.initEvent(name, false, false); - node.dispatchEvent(event); - } - + getMenuItems: function getMenuItems(targetPath) { function addChildren(node, parent) { DOM(node).createContents(); if (~["menu", "menupopup"].indexOf(node.localName) && node.children.length) - dispatch(node, "popupshowing"); + DOM(node).popupshowing({ bubbles: false }); for (let [, item] in Iterator(node.childNodes)) { if (item.childNodes.length == 0 && item.localName == "menuitem" && !item.hidden && !/rdf:http:/.test(item.getAttribute("label"))) { // FIXME item.dactylPath = parent + item.getAttribute("label"); - items.push(item); + if (!targetPath || targetPath.indexOf(item.dactylPath) == 0) + items.push(item); } else { let path = parent; if (item.localName == "menu") path += item.getAttribute("label") + "."; - addChildren(item, path); + if (!targetPath || targetPath.indexOf(path) == 0) + addChildren(item, path); } } } @@ -169,6 +165,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { return items; }, + get menuItems() this.getMenuItems(), + // Global constants CURRENT_TAB: "here", NEW_TAB: "tab", @@ -1510,7 +1508,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { "Execute the specified menu item from the command line", function (args) { let arg = args[0] || ""; - let items = dactyl.menuItems; + let items = dactyl.getMenuItems(arg); dactyl.assert(items.some(function (i) i.dactylPath == arg), _("emenu.notFound", arg)); |