Created
January 21, 2016 09:50
-
-
Save ZER0/af4888bf6fdb7251c0ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<div> | |
<button>click A</button> | |
<button>click B</button> | |
</div> | |
<output></output> | |
<script> | |
let buttons = document.querySelector("div"); | |
let output = document.querySelector("output"); | |
addon.port.on("clicked-received", (message) => { | |
output.textContent = message; | |
}); | |
buttons.addEventListener("click", (event) => { | |
addon.port.emit("button-clicked", event.target.textContent); | |
}); | |
</script> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { ToggleButton } = require('sdk/ui/button/toggle'); | |
const { Panel } = require("sdk/panel"); | |
let button = ToggleButton({ | |
id: "my-button", | |
label: "my button", | |
icon: "./icon.png", | |
onChange({checked}) { | |
if (checked) panel.show({position: this}); | |
} | |
}); | |
let panel = Panel({ | |
// `./` is a shortcut for add-on's "data" folder | |
// so there is no need to use `self` module | |
contentURL: './content.html', | |
onHide() { | |
button.state('window', {checked: false}); | |
} | |
}); | |
panel.port.on("button-clicked", (message) => { | |
console.log(message); | |
panel.port.emit("clicked-received", "Got " + message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment