|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 "use strict"; |
|
5 |
|
6 var self = require("sdk/self"); |
|
7 var { Panel } = require("sdk/panel"); |
|
8 var { ToggleButton } = require("sdk/ui"); |
|
9 |
|
10 function replaceMom(html) { |
|
11 return html.replace("World", "Mom"); |
|
12 } |
|
13 exports.replaceMom = replaceMom; |
|
14 |
|
15 exports.main = function(options, callbacks) { |
|
16 console.log("My ID is " + self.id); |
|
17 |
|
18 // Load the sample HTML into a string. |
|
19 var helloHTML = self.data.load("sample.html"); |
|
20 |
|
21 // Let's now modify it... |
|
22 helloHTML = replaceMom(helloHTML); |
|
23 |
|
24 // ... and then create a panel that displays it. |
|
25 var myPanel = Panel({ |
|
26 contentURL: "data:text/html," + helloHTML, |
|
27 onHide: handleHide |
|
28 }); |
|
29 |
|
30 // Create a widget that displays the image. We'll attach the panel to it. |
|
31 // When you click the widget, the panel will pop up. |
|
32 var button = ToggleButton({ |
|
33 id: "test-widget", |
|
34 label: "Mom", |
|
35 icon: './mom.png', |
|
36 onChange: handleChange |
|
37 }); |
|
38 |
|
39 // If you run cfx with --static-args='{"quitWhenDone":true}' this program |
|
40 // will automatically quit Firefox when it's done. |
|
41 if (options.staticArgs.quitWhenDone) |
|
42 callbacks.quit(); |
|
43 } |
|
44 |
|
45 function handleChange(state) { |
|
46 if (state.checked) { |
|
47 myPanel.show({ position: button }); |
|
48 } |
|
49 } |
|
50 |
|
51 function handleHide() { |
|
52 button.state('window', { checked: false }); |
|
53 } |