forked from digitalpalireader/digitalpalireader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.js
108 lines (83 loc) · 3 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
var Cc = Components.classes;
var Ci = Components.interfaces;
function createTestDriver(window)
{
}
var testDriver = null;
function loadIntoWindow(window) {
if (!window) return;
// 1
var doc = window.document;
// Get the add-on bar for that window
var addonBar = doc.getElementById("addon-bar");
// Construct the new toolbar item
var newItem = doc.createElement("toolbaritem");
var itemLabel = doc.createElement("label");
// Add the item to the toolbar and set its text label
newItem.appendChild(itemLabel);
addonBar.appendChild(newItem);
itemLabel.value = "Hello world!";
// 2
let anchor = window.document.getElementById("status-bar");
let button = window.document.createElement("button");
button.setAttribute("id", "DPRStatusBar");
button.setAttribute("value", "test");
button.setAttribute("tooltiptext", "Digital Pali Reader");
button.setAttribute("role", "button");
button.addEventListener("click", function() {
var theTab = window.gBrowser.addTab(DPR_PAL.toWebUrl('chrome://digitalpalireader/content/index.htm'));
theTab.label = "Digital Pali Reader";
gBrowser.selectedTab = theTab;
var func = function () { window.gBrowser.setIcon(theTab, "chrome://digitalpalireader/skin/icons/logo.png"); };
setTimeout(func, 500);
}, false);
let image = window.document.createElement('image');
image.setAttribute('id', 'dpr-button');
button.appendChild(image);
anchor.appendChild(button);
}
function unloadFromWindow(window) {
if (!window) return;
if (testDriver)
testDriver.deactivateJSD();
}
/*
bootstrap.js API
*/
function startup(aData, aReason) {
/*
Components.utils.import("resource://firebug/firebug-trace-service.js");
var FBTrace = traceConsoleService.getTracer("extensions.firebug");
FBTrace.sysout("startup "); */
let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
// Load into any existing windows
let enumerator = wm.getEnumerator("navigator:browser");
while(enumerator.hasMoreElements()) {
let win = enumerator.getNext();
loadIntoWindow(win);
}
// Load into any new windows
wm.addListener({
onOpenWindow: function(aWindow) {
// Wait for the window to finish loading
let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal);
domWindow.addEventListener("load", function() {
domWindow.removeEventListener("load", arguments.callee, false);
loadIntoWindow(domWindow);
}, false);
},
onCloseWindow: function(aWindow) { },
onWindowTitleChange: function(aWindow, aTitle) { }
});
}
function shutdown(aData, aReason) {
let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
// Unload from any existing windows
let enumerator = wm.getEnumerator("navigator:browser");
while(enumerator.hasMoreElements()) {
let win = enumerator.getNext();
unloadFromWindow(win);
}
}
function install(aData, aReason) { }
function uninstall(aData, aReason) { }