OLD | NEW |
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 let {gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", null); | |
8 | |
9 let InspectorObserver = | 7 let InspectorObserver = |
10 { | 8 { |
11 init: function() | 9 init: function() |
12 { | 10 { |
| 11 let gDevTools; |
| 12 try |
| 13 { |
| 14 ({gDevTools}) = Cu.import("resource:///modules/devtools/gDevTools.jsm", nu
ll); |
| 15 } |
| 16 catch(e) |
| 17 { |
| 18 // No developer tools or unsupported version - ignore. |
| 19 return; |
| 20 } |
| 21 |
13 gDevTools.on("inspector-ready", this.inspectorReady); | 22 gDevTools.on("inspector-ready", this.inspectorReady); |
14 onShutdown.add(function() | 23 onShutdown.add(function() |
15 { | 24 { |
16 gDevTools.off("inspector-ready", this.inspectorReady); | 25 gDevTools.off("inspector-ready", this.inspectorReady); |
17 }.bind(this)); | 26 }.bind(this)); |
18 }, | 27 }, |
19 | 28 |
20 get inspectorButtonTooltip() | 29 get inspectorButtonTooltip() |
21 { | 30 { |
22 // Randomize URI to work around bug 719376 | 31 // Randomize URI to work around bug 719376 |
23 let stringBundle = Services.strings.createBundle("chrome://elemhidehelper/lo
cale/global.properties?" + Math.random()); | 32 let stringBundle = Services.strings.createBundle("chrome://elemhidehelper/lo
cale/global.properties?" + Math.random()); |
24 let result = stringBundle.GetStringFromName("inspector.button.tooltiptext"); | 33 let result = stringBundle.GetStringFromName("inspector.button.tooltiptext"); |
25 | 34 |
26 delete this.inspectorButtonTooltip; | 35 delete this.inspectorButtonTooltip; |
27 this.__defineGetter__("inspectorButtonTooltip", function() result); | 36 this.__defineGetter__("inspectorButtonTooltip", function() result); |
28 return this.inspectorButtonTooltip; | 37 return this.inspectorButtonTooltip; |
29 }, | 38 }, |
30 | 39 |
31 inspectorReady: function(eventName, toolbox, panel) | 40 inspectorReady: function(eventName, toolbox, panel) |
32 { | 41 { |
33 let panelWindow = panel.panelWin; | 42 let panelWindow = panel.panelWin; |
34 let inspectBtn = panelWindow.document.getElementById("inspector-inspect-tool
button"); | 43 let inspectBtn = panelWindow.document.getElementById("inspector-inspect-tool
button"); |
35 if (!inspectBtn) | 44 if (!inspectBtn) |
36 return; | 45 return; |
37 | 46 |
38 let tooltiptext = InspectorObserver.inspectorButtonTooltip; | 47 let tooltiptext = InspectorObserver.inspectorButtonTooltip; |
39 button = panelWindow.document.createElement("toolbarbutton"); | 48 button = panelWindow.document.createElement("toolbarbutton"); |
40 button.setAttribute("id", "inspector-abp-elemhide-toolbutton"); | 49 button.setAttribute("id", "inspector-abp-elemhide-toolbutton"); |
41 button.style.listStyleImage = "url('chrome://adblockplus/skin/abp-status-16.
png')"; | 50 button.style.listStyleImage = "url('chrome://adblockplus/skin/abp-status-16.
png')"; |
42 button.style.MozImageRegion = "rect(0px, 16px, 16px, 0px)"; | 51 button.style.MozImageRegion = "rect(0px, 16px, 16px, 0px)"; |
43 button.style.paddingTop = "4px"; | 52 button.style.paddingTop = "4px"; |
44 button.setAttribute("class", "devtools-toolbarbutton"); | 53 button.setAttribute("class", "devtools-toolbarbutton"); |
45 button.setAttribute("tooltiptext", tooltiptext); | 54 button.setAttribute("tooltiptext", tooltiptext); |
46 button.setAttribute("tabindex", "0"); | 55 button.setAttribute("tabindex", "0"); |
47 button.addEventListener("command", function() | 56 button.addEventListener("command", function() |
48 { | 57 { |
49 panelWindow.openDialog("chrome://elemhidehelper/content/composer.xul", "_b
lank", | 58 panelWindow.openDialog("chrome://elemhidehelper/content/composer.xul", "_b
lank", |
50 "chrome,centerscreen,resizable,dialog=no", panel.se
lection.node); | 59 "chrome,centerscreen,resizable,dialog=no", panel.se
lection.node); |
51 }, false); | 60 }, false); |
52 inspectBtn.parentNode.insertBefore(button, inspectBtn.nextSibling); | 61 inspectBtn.parentNode.insertBefore(button, inspectBtn.nextSibling); |
53 } | 62 } |
54 }; | 63 }; |
55 | 64 |
56 InspectorObserver.init(); | 65 InspectorObserver.init(); |
OLD | NEW |