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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/examples/toolbar-api/lib/main.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,48 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +"use strict";
     1.8 +
     1.9 +const { Toolbar } = require("sdk/ui/toolbar");
    1.10 +const { Frame } = require("sdk/ui/frame");
    1.11 +const { ActionButton } = require("sdk/ui/button/action");
    1.12 +
    1.13 +let button = new ActionButton({
    1.14 +  id: "button",
    1.15 +  label: "send!",
    1.16 +  icon: "./favicon.ico",
    1.17 +  onClick: () => {
    1.18 +    frame.postMessage({
    1.19 +      hello: "content"
    1.20 +    });
    1.21 +  }
    1.22 +});
    1.23 +
    1.24 +let frame = new Frame({
    1.25 +    url: "./index.html",
    1.26 +    onAttach: () => {
    1.27 +      console.log("frame was attached");
    1.28 +    },
    1.29 +    onReady: () => {
    1.30 +      console.log("frame document was loaded");
    1.31 +    },
    1.32 +    onLoad: () => {
    1.33 +      console.log("frame load complete");
    1.34 +    },
    1.35 +    onMessage: (event) => {
    1.36 +      console.log("got message from frame content", event);
    1.37 +      if (event.data === "ping!")
    1.38 +        event.source.postMessage("pong!", event.source.origin);
    1.39 +    }
    1.40 +});
    1.41 +let toolbar = new Toolbar({
    1.42 +  items: [frame],
    1.43 +  title: "Addon Demo",
    1.44 +  hidden: false,
    1.45 +  onShow: () => {
    1.46 +    console.log("toolbar was shown");
    1.47 +  },
    1.48 +  onHide: () => {
    1.49 +    console.log("toolbar was hidden");
    1.50 +  }
    1.51 +});

mercurial