Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
5 */ | 5 */ |
6 | 6 |
7 Cu.import("resource:///modules/devtools/gDevTools.jsm"); | 7 let {gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", null); |
Wladimir Palant
2014/04/11 11:06:08
While you are at it, please don't use a blind impo
saroyanm
2014/04/11 16:09:10
Got it.
| |
8 | 8 |
9 let InspectorObserver = | 9 let InspectorObserver = |
10 { | 10 { |
11 init: function() | 11 init: function() |
12 { | 12 { |
13 gDevTools.on("inspector-ready", this.inspectorReady); | 13 gDevTools.on("inspector-ready", this.inspectorReady); |
14 onShutdown.add(function() | 14 onShutdown.add(function() |
15 { | 15 { |
16 gDevTools.off("inspector-ready", this.inspectorReady); | 16 gDevTools.off("inspector-ready", this.inspectorReady); |
17 }.bind(this)); | 17 }.bind(this)); |
18 }, | 18 }, |
19 | 19 |
20 get inspectorButton() | 20 get inspectorButton() |
saroyanm
2014/04/12 20:59:38
Not sure if it's make sense to change getter into
Wladimir Palant
2014/04/12 21:05:21
Yes, I think the name should be changed.
| |
21 { | 21 { |
22 // Randomize URI to work around bug 719376 | 22 // Randomize URI to work around bug 719376 |
23 let stringBundle = Services.strings.createBundle("chrome://elemhidehelper/lo cale/global.properties?" + Math.random()); | 23 let stringBundle = Services.strings.createBundle("chrome://elemhidehelper/lo cale/global.properties?" + Math.random()); |
24 let result = [stringBundle.GetStringFromName("inspector.button.label"), stri ngBundle.GetStringFromName("inspector.button.accesskey"), stringBundle.GetString FromName("inspector.button.tooltiptext")]; | 24 let result = stringBundle.GetStringFromName("inspector.button.tooltiptext"); |
25 | 25 |
26 delete this.inspectorButton; | 26 delete this.inspectorButton; |
27 this.__defineGetter__("inspectorButton", function() result); | 27 this.__defineGetter__("inspectorButton", function() result); |
28 return this.inspectorButton; | 28 return this.inspectorButton; |
29 }, | 29 }, |
30 | 30 |
31 inspectorReady: function(eventName, listener) | 31 inspectorReady: function(eventName, toolbox, panel) |
Wladimir Palant
2014/04/11 11:06:08
The second parameter here isn't listener but panel
saroyanm
2014/04/11 16:09:10
Good catch, actually I've tested and seams like th
| |
32 { | 32 { |
33 let toolbox = gDevTools.getToolbox(listener.target); | 33 let panelWindow = panel.panelWin; |
Wladimir Palant
2014/04/11 11:06:08
I checked why the documentation mentions getToolbo
saroyanm
2014/04/11 16:09:10
Good point: I've tested with FF19 and there is an
| |
34 if (!toolbox) | 34 let inspectBtn = panelWindow.document.getElementById("inspector-inspect-tool button"); |
35 if (!inspectBtn) | |
35 return; | 36 return; |
36 | 37 |
37 let panel = toolbox.getToolPanels().get("inspector"); | 38 let tooltiptext = InspectorObserver.inspectorButton; |
38 if (!panel) | |
39 return; | |
Wladimir Palant
2014/04/11 11:06:08
So you are going from the panel to the toolbox to
saroyanm
2014/04/11 16:09:10
Lol :)
| |
40 | |
41 let panelWindow = panel.panelWin; | |
42 let parent = panelWindow.document.getElementById("inspector-toolbar"); | |
43 if (!parent) | |
44 return; | |
45 | |
46 let [label, accesskey, tooltiptext] = InspectorObserver.inspectorButton; | |
47 button = panelWindow.document.createElement("toolbarbutton"); | 39 button = panelWindow.document.createElement("toolbarbutton"); |
48 button.setAttribute("id", "inspector-abp-elemhide-toolbutton"); | 40 button.setAttribute("id", "inspector-abp-elemhide-toolbutton"); |
49 button.setAttribute("label", label); | 41 button.style.listStyleImage = "url('chrome://adblockplus/skin/abp-status-16. png')"; |
42 button.style.MozImageRegion = "rect(0px, 16px, 16px, 0px)"; | |
43 button.style.paddingTop = "4px"; | |
50 button.setAttribute("class", "devtools-toolbarbutton"); | 44 button.setAttribute("class", "devtools-toolbarbutton"); |
51 button.setAttribute("accesskey", accesskey); | 45 button.setAttribute("accesskey", accesskey); |
52 button.setAttribute("tooltiptext", tooltiptext); | 46 button.setAttribute("tooltiptext", tooltiptext); |
53 button.setAttribute("tabindex", "0"); | 47 button.setAttribute("tabindex", "0"); |
54 button.addEventListener("command", function() | 48 button.addEventListener("command", function() |
55 { | 49 { |
56 panelWindow.openDialog("chrome://elemhidehelper/content/composer.xul", "_b lank", | 50 panelWindow.openDialog("chrome://elemhidehelper/content/composer.xul", "_b lank", |
57 "chrome,centerscreen,resizable,dialog=no", panel.se lection.node); | 51 "chrome,centerscreen,resizable,dialog=no", panel.se lection.node); |
58 }, false); | 52 }, false); |
59 parent.appendChild(button); | 53 inspectBtn.parentNode.insertBefore(button, inspectBtn.nextSibling); |
Wladimir Palant
2014/04/11 11:06:08
Adding the button at the end probably isn't the be
saroyanm
2014/04/11 16:09:10
Good point changed. Thanks for pointing.
| |
60 } | 54 } |
61 }; | 55 }; |
62 | 56 |
63 InspectorObserver.init(); | 57 InspectorObserver.init(); |
LEFT | RIGHT |