Skip to content

Instantly share code, notes, and snippets.

@eCosinus
Last active May 20, 2019 17:46
Show Gist options
  • Save eCosinus/7119078 to your computer and use it in GitHub Desktop.
Save eCosinus/7119078 to your computer and use it in GitHub Desktop.
FirefoxOS WebActivities Examples
var addContact = document.querySelector("#add-contact");
if (addContact) {
addContact.onclick = function () {
var newContact = new MozActivity({
name: "new", // Possibly add-contact in future versions
data: {
type: "webcontacts/contact",
params: { // Will possibly move to be direct properties under "data"
givenName: "Robert",
lastName: "Nyman",
tel: "+44789",
email: "[email protected]",
address: "San Francisco",
note: "This is a note",
company: "Mozilla"
}
}
});
}
}
var dial = document.querySelector("#dial");
if (dial) {
dial.onclick = function () {
var call = new MozActivity({
name: "dial",
data: {
number: "+46777888999"
}
});
}
}
var pickImage = document.querySelector("#pick-image");
if (pickImage) {
pickImage.onclick = function () {
var pick = new MozActivity({
name: "pick",
data: {
type: ["image/png", "image/jpg", "image/jpeg"]

}
});
pick.onsuccess = function () {

var img = document.createElement("img");
img.src = window.URL.createObjectURL(this.result.blob);
var imagePresenter = document.querySelector("#image-presenter");
imagePresenter.appendChild(img);
imagePresenter.style.display = "block";
};
pick.onerror = function () {

alert("Can't view the image!");
};
}
}
var pickAnything = document.querySelector("#pick-anything");
if (pickAnything) {
pickAnything.onclick = function () {
var pickAny = new MozActivity({
name: "pick"
});
pickAny.onsuccess = function () {

var img = document.createElement("img");
if (this.result.blob.type.indexOf("image") != -1) {
img.src = window.URL.createObjectURL(this.result.blob);
document.querySelector("#image-presenter").appendChild(img);
}
};
pickAny.onerror = function () {

console.log("An error occurred");
};
}
}
var record = document.querySelector("#record");
if (record) {
record.onclick = function () {
var rec = new MozActivity({
name: "record" // Possibly capture in future versions
});
rec.onsuccess = function () {

var img = document.createElement("img");
img.src = window.URL.createObjectURL(this.result.blob);
var imagePresenter = document.querySelector("#image-presenter");
imagePresenter.appendChild(img);
imagePresenter.style.display = "block";
};
rec.onerror = function () {

alert("No taken picture returned");
};
}
}
var share = document.querySelector("#share");
if (share) {
share.onclick = function () {
var sharing = new MozActivity({
name: "share",
data: {
//type: "url", // Possibly text/html in future versions,
number: 1,
url: "http://robertnyman.com"
}
});
}
}
var sendSMS = document.querySelector("#send-sms");
if (sendSMS) {
sendSMS.onclick = function () {
var sms = new MozActivity({
name: "new", // Possible compose-sms in future versions
data: {
type: "websms/sms",
number: "+46777888999"
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment