addon-sdk/source/examples/reddit-panel/lib/main.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4 "use strict";
michael@0 5
michael@0 6 var { data } = require("sdk/self");
michael@0 7 var { ToggleButton } = require("sdk/ui");
michael@0 8
michael@0 9 var base64png = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYA" +
michael@0 10 "AABzenr0AAAASUlEQVRYhe3O0QkAIAwD0eyqe3Q993AQ3cBSUKpygfsNTy" +
michael@0 11 "N5ugbQpK0BAADgP0BRDWXWlwEAAAAAgPsA3rzDaAAAAHgPcGrpgAnzQ2FG" +
michael@0 12 "bWRR9AAAAABJRU5ErkJggg%3D%3D";
michael@0 13
michael@0 14 var reddit_panel = require("sdk/panel").Panel({
michael@0 15 width: 240,
michael@0 16 height: 320,
michael@0 17 contentURL: "http://www.reddit.com/.mobile?keep_extension=True",
michael@0 18 contentScriptFile: [data.url("jquery-1.4.4.min.js"),
michael@0 19 data.url("panel.js")],
michael@0 20 onHide: handleHide
michael@0 21 });
michael@0 22
michael@0 23 reddit_panel.port.on("click", function(url) {
michael@0 24 require("sdk/tabs").open(url);
michael@0 25 });
michael@0 26
michael@0 27 let button = ToggleButton({
michael@0 28 id: "open-reddit-btn",
michael@0 29 label: "Reddit",
michael@0 30 icon: base64png,
michael@0 31 onChange: handleChange
michael@0 32 });
michael@0 33
michael@0 34 exports.main = function(options, callbacks) {
michael@0 35 // If you run cfx with --static-args='{"quitWhenDone":true}' this program
michael@0 36 // will automatically quit Firefox when it's done.
michael@0 37 if (options.staticArgs.quitWhenDone)
michael@0 38 callbacks.quit();
michael@0 39 };
michael@0 40
michael@0 41 function handleChange(state) {
michael@0 42 if (state.checked) {
michael@0 43 reddit_panel.show({ position: button });
michael@0 44 }
michael@0 45 }
michael@0 46
michael@0 47 function handleHide() {
michael@0 48 button.state('window', { checked: false });
michael@0 49 }

mercurial