Last active
December 18, 2015 19:29
-
-
Save erikvold/5833639 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const windowUtils = require("window-utils"); | |
const NS_XUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; | |
exports.Menuitem = function Menuitem(options) { | |
new windowUtils.WindowTracker({ | |
onTrack: function (window) { | |
if ("chrome://browser/content/browser.xul" != window.location) return; | |
// add the new menuitem to a menu | |
var menuitem = window.document.createElementNS(NS_XUL, options.type); | |
menuitem.setAttribute("id", options.id); | |
menuitem.setAttribute("label", options.label); | |
if (options.accesskey) | |
menuitem.setAttribute("accesskey", options.accesskey); | |
if (options.key) | |
menuitem.setAttribute("key", options.key); | |
if (options.image) { | |
menuitem.setAttribute("class", "menuitem-iconic"); | |
menuitem.style.listStyleImage = "url('" + options.image + "')"; | |
} | |
if ( options.type == "menuitem"){ | |
} | |
console.log(options.type); | |
console.log(options.menuid); | |
if (options.menuid) { | |
if (options.type == "menu"){ | |
let ($ = function(id) window.document.getElementById(id)) { | |
$(options.menuid).insertBefore(menuitem, $(options.insertbefore)); | |
} | |
} else { | |
var menu = window.document.getElementById(options.menuid); | |
if ( options.onCommand){ | |
var onCmd = function() { | |
options.onCommand && options.onCommand(); | |
}; | |
menuitem.addEventListener("command", onCmd, true); | |
} | |
menu.appendChild(menuitem); | |
} | |
} | |
// add unloader | |
require("unload+").unload(function() { | |
menuitem.parentNode.removeChild(menuitem); | |
}, window); | |
} | |
}); | |
}; | |
And if you call .. in the main.js of the add on this is examples. | |
Type is type menu (menuitem,menupopup,menu) | |
and menuid is the ID on insert the item. | |
menuitem insert into menupopup and menupopup inster into menu. | |
var menuitem = require("menuitems").Menuitem({ | |
type: "menu", | |
id: "clickme", | |
accesskey : "S", | |
menuid: "menu_ToolsPopup", | |
label: "Sundio ToolsWeb", | |
insertbefore: "menu_pageInfo" | |
}); | |
var menuitem = require("menuitems").Menuitem({ | |
type: "menupopup", | |
id: "menupopup1", | |
menuid: "clickme", | |
label: "Click Me!" | |
}); | |
var menuitem = require("menuitems").Menuitem({ | |
type: "menuitem", | |
id: "menuitem1", | |
menuid: "menupopup1", | |
accesskey : "t", | |
label: "Find missing textResources", | |
onCommand: function() { | |
console.log("clicked"); | |
tabs.activeTab.attach({ | |
contentScriptFile: data.url("showmetextresources.js")}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment