addon-sdk/source/examples/toolbar-api/lib/main.js

branch
TOR_BUG_9701
changeset 10
ac0c01689b40
equal deleted inserted replaced
-1:000000000000 0:7f6cab28f180
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 const { Toolbar } = require("sdk/ui/toolbar");
7 const { Frame } = require("sdk/ui/frame");
8 const { ActionButton } = require("sdk/ui/button/action");
9
10 let button = new ActionButton({
11 id: "button",
12 label: "send!",
13 icon: "./favicon.ico",
14 onClick: () => {
15 frame.postMessage({
16 hello: "content"
17 });
18 }
19 });
20
21 let frame = new Frame({
22 url: "./index.html",
23 onAttach: () => {
24 console.log("frame was attached");
25 },
26 onReady: () => {
27 console.log("frame document was loaded");
28 },
29 onLoad: () => {
30 console.log("frame load complete");
31 },
32 onMessage: (event) => {
33 console.log("got message from frame content", event);
34 if (event.data === "ping!")
35 event.source.postMessage("pong!", event.source.origin);
36 }
37 });
38 let toolbar = new Toolbar({
39 items: [frame],
40 title: "Addon Demo",
41 hidden: false,
42 onShow: () => {
43 console.log("toolbar was shown");
44 },
45 onHide: () => {
46 console.log("toolbar was hidden");
47 }
48 });

mercurial