Last active
May 20, 2019 17:46
-
-
Save eCosinus/7119078 to your computer and use it in GitHub Desktop.
FirefoxOS WebActivities Examples
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
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" | |
} | |
} | |
}); | |
} | |
} |
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
var dial = document.querySelector("#dial"); | |
if (dial) { | |
dial.onclick = function () { | |
var call = new MozActivity({ | |
name: "dial", | |
data: { | |
number: "+46777888999" | |
} | |
}); | |
} | |
} |
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
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"); | |
}; | |
} | |
} |
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
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"); | |
}; | |
} | |
} | |
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
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