-
Notifications
You must be signed in to change notification settings - Fork 39
/
bootstrap.js
77 lines (66 loc) · 3.24 KB
/
bootstrap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
let NS_XUL = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',
LOCALE_URI = 'chrome://resteasy/locale/resteasy.properties',
CHROME_URI = 'chrome://resteasy/content/resteasy.html',
ICON16_URI = 'chrome://resteasy/content/img/icon16.png',
ICON32_URI = 'chrome://resteasy/content/img/icon32.png',
BUTTON_ID = 'resteasy';
// Currently, there are no tasks that need to be run exclusively at
// (un)installation time, so these have empty function bodies
function install(data, reason) {}
function uninstall(data, reason) {}
// This method is run each time the add-on is initialized
// - immediately after installation
// - when enabled from the add-ons page
// - after Firefox startup
function startup(data, reason) {
// Create a string bundle representing the current locale
Components.utils.import('resource://gre/modules/Services.jsm');
let bundle = Services.strings.createBundle(LOCALE_URI);
// Register the toolbar button
Components.utils.import("resource:///modules/CustomizableUI.jsm");
CustomizableUI.createWidget({
id: BUTTON_ID,
type: 'custom',
defaultArea: CustomizableUI.AREA_NAVBAR,
onBuild: function(document) {
// Create the toolbar button
let toolbarButton = document.createElementNS(NS_XUL, 'toolbarbutton');
toolbarButton.setAttribute('id', BUTTON_ID);
toolbarButton.setAttribute('class', 'toolbarbutton-1 chromeclass-toolbar-additional');
toolbarButton.setAttribute('label', bundle.GetStringFromName('application.title'));
toolbarButton.setAttribute('tooltiptext', bundle.GetStringFromName('application.tooltip'));
toolbarButton.addEventListener('command', function(event) {
event.view.gBrowser.selectedTab = event.view.gBrowser.addTab(CHROME_URI);
}, true);
// Set the currently displayed icon based on the widget placement
function setIcon() {
let inToolbar = false,
placement = CustomizableUI.getPlacementOfWidget(BUTTON_ID);
if(placement)
inToolbar = CustomizableUI.getAreaType(placement.area) === CustomizableUI.TYPE_TOOLBAR;
toolbarButton.setAttribute('image', inToolbar ? ICON16_URI : ICON32_URI);
}
setIcon();
// Change the icon if it is added to a toolbar or removed
CustomizableUI.addListener({
onWidgetAfterDOMChange: function(node, nextNode, container) {
if(node.id === BUTTON_ID)
setIcon();
}
});
return toolbarButton;
}
});
}
// This method is run whenever the add-on is shutting down
// - immediately before completing uninstallation of the add-on
// - when disabled from the add-ons page
// - before quitting Firefox
function shutdown(data, reason) {
// Remove the toolbar button
Components.utils.import("resource:///modules/CustomizableUI.jsm");
CustomizableUI.destroyWidget(BUTTON_ID);
}