michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: "use strict"; michael@0: michael@0: var self = require("sdk/self"); michael@0: var { Panel } = require("sdk/panel"); michael@0: var { ToggleButton } = require("sdk/ui"); michael@0: michael@0: function replaceMom(html) { michael@0: return html.replace("World", "Mom"); michael@0: } michael@0: exports.replaceMom = replaceMom; michael@0: michael@0: exports.main = function(options, callbacks) { michael@0: console.log("My ID is " + self.id); michael@0: michael@0: // Load the sample HTML into a string. michael@0: var helloHTML = self.data.load("sample.html"); michael@0: michael@0: // Let's now modify it... michael@0: helloHTML = replaceMom(helloHTML); michael@0: michael@0: // ... and then create a panel that displays it. michael@0: var myPanel = Panel({ michael@0: contentURL: "data:text/html," + helloHTML, michael@0: onHide: handleHide michael@0: }); michael@0: michael@0: // Create a widget that displays the image. We'll attach the panel to it. michael@0: // When you click the widget, the panel will pop up. michael@0: var button = ToggleButton({ michael@0: id: "test-widget", michael@0: label: "Mom", michael@0: icon: './mom.png', michael@0: onChange: handleChange michael@0: }); michael@0: michael@0: // If you run cfx with --static-args='{"quitWhenDone":true}' this program michael@0: // will automatically quit Firefox when it's done. michael@0: if (options.staticArgs.quitWhenDone) michael@0: callbacks.quit(); michael@0: } michael@0: michael@0: function handleChange(state) { michael@0: if (state.checked) { michael@0: myPanel.show({ position: button }); michael@0: } michael@0: } michael@0: michael@0: function handleHide() { michael@0: button.state('window', { checked: false }); michael@0: }