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 { data } = require("sdk/self"); michael@0: var { ToggleButton } = require("sdk/ui"); michael@0: michael@0: var base64png = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYA" + michael@0: "AABzenr0AAAASUlEQVRYhe3O0QkAIAwD0eyqe3Q993AQ3cBSUKpygfsNTy" + michael@0: "N5ugbQpK0BAADgP0BRDWXWlwEAAAAAgPsA3rzDaAAAAHgPcGrpgAnzQ2FG" + michael@0: "bWRR9AAAAABJRU5ErkJggg%3D%3D"; michael@0: michael@0: var reddit_panel = require("sdk/panel").Panel({ michael@0: width: 240, michael@0: height: 320, michael@0: contentURL: "http://www.reddit.com/.mobile?keep_extension=True", michael@0: contentScriptFile: [data.url("jquery-1.4.4.min.js"), michael@0: data.url("panel.js")], michael@0: onHide: handleHide michael@0: }); michael@0: michael@0: reddit_panel.port.on("click", function(url) { michael@0: require("sdk/tabs").open(url); michael@0: }); michael@0: michael@0: let button = ToggleButton({ michael@0: id: "open-reddit-btn", michael@0: label: "Reddit", michael@0: icon: base64png, michael@0: onChange: handleChange michael@0: }); michael@0: michael@0: exports.main = function(options, callbacks) { 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: reddit_panel.show({ position: button }); michael@0: } michael@0: } michael@0: michael@0: function handleHide() { michael@0: button.state('window', { checked: false }); michael@0: }