59
JavaScript APIs - The Web is the Platform

JavaScript APIs - The Web is the Platform

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: JavaScript APIs - The Web is the Platform

JavaScript APIs - The Web is the

Platform

Page 6: JavaScript APIs - The Web is the Platform

Open Web technologies:

HTML5, CSS, JavaScript

A manifest file

Page 7: JavaScript APIs - The Web is the Platform

Manifest file

Page 8: JavaScript APIs - The Web is the Platform
Page 9: JavaScript APIs - The Web is the Platform

{ "version": "1.0", "name": "ABBAInfo", "description": "Getting some ABBA info", "icons": { "16": "/abbainfo/images/icon-16.png", "48": "/abbainfo/images/icon-48.png", "128": "/abbainfo/images/icon-128.png" }, "developer": { "name": "Robert Nyman", "url": "http://robertnyman.com" }, "installs_allowed_from": [ "*" ], "launch_path": "/abbainfo/", "locales": { }, "default_locale": "en"}

Page 10: JavaScript APIs - The Web is the Platform

MIME type:

application/x-web-app-manifest+json

Page 11: JavaScript APIs - The Web is the Platform

Installing a Web App

Page 12: JavaScript APIs - The Web is the Platform

navigator.mozApps.install( URLToManifestFile, installData, sucessCallback, errorCallback);

Page 13: JavaScript APIs - The Web is the Platform

var mozApps = navigator.mozApps;if (mozApps) { navigator.mozApps.install( "http://localhost/abbainfo/manifest.webapp", { "userID": "Robocop" }, function () { console.log("Worked!"); console.log(result); }, function (result) { console.log("Failed :-("); console.log(result); } );}

Page 14: JavaScript APIs - The Web is the Platform

offline & localStorage

Page 15: JavaScript APIs - The Web is the Platform

<!DOCTYPE html><html manifest="offline.appcache"><head>...

Page 16: JavaScript APIs - The Web is the Platform

CACHE MANIFEST

# VERSION 10

CACHE:offline.htmlbase.css

FALLBACK:online.css offline.css

NETWORK:/live-updates

Page 18: JavaScript APIs - The Web is the Platform

Introducing Web Runtime - WebRT

Page 19: JavaScript APIs - The Web is the Platform

Currently:

WindowsMacAndroid

Page 22: JavaScript APIs - The Web is the Platform
Page 23: JavaScript APIs - The Web is the Platform
Page 24: JavaScript APIs - The Web is the Platform
Page 26: JavaScript APIs - The Web is the Platform
Page 29: JavaScript APIs - The Web is the Platform
Page 31: JavaScript APIs - The Web is the Platform
Page 32: JavaScript APIs - The Web is the Platform
Page 33: JavaScript APIs - The Web is the Platform

<button id="view-fullscreen">Fullscreen</button>

<script type="text/javascript">(function () { var viewFullScreen = document.getElementById("view-fullscreen"); if (viewFullScreen) { viewFullScreen.addEventListener("click", function () { var docElm = document.documentElement; if (docElm.mozRequestFullScreen) { docElm.mozRequestFullScreen(); } else if (docElm.webkitRequestFullScreen) { docElm.webkitRequestFullScreen(); } }, false); }})(); </script>

Page 34: JavaScript APIs - The Web is the Platform

mozRequestFullScreenWithKeys?

Page 35: JavaScript APIs - The Web is the Platform

html:-moz-full-screen { background: red;}

html:-webkit-full-screen { background: red;}

Page 37: JavaScript APIs - The Web is the Platform
Page 38: JavaScript APIs - The Web is the Platform

<input type="file" id="take-picture" accept="image/*">

Page 39: JavaScript APIs - The Web is the Platform

takePicture.onchange = function (event) { // Get a reference to the taken picture or chosen file var files = event.target.files, file; if (files && files.length > 0) { file = files[0]; // Get window.URL object var URL = window.URL || window.webkitURL;

// Create ObjectURL var imgURL = URL.createObjectURL(file);

// Set img src to ObjectURL showPicture.src = imgURL;

// Revoke ObjectURL URL.revokeObjectURL(imgURL); }};

Page 41: JavaScript APIs - The Web is the Platform
Page 42: JavaScript APIs - The Web is the Platform
Page 45: JavaScript APIs - The Web is the Platform

// Telephony objectvar tel = navigator.mozTelephony;

// Check if the phone is muted (read/write property)console.log(tel.muted);

// Check if the speaker is enabled (read/write property)console.log(tel.speakerEnabled);

// Place a callvar call = tel.dial("123456789");

Page 46: JavaScript APIs - The Web is the Platform

// Receiving a calltel.onincoming = function (event) { var incomingCall = event.call;

// Get the number of the incoming call console.log(incomingCall.number);

// Answer the call incomingCall.answer();};

// Disconnect a callcall.hangUp();

Page 47: JavaScript APIs - The Web is the Platform

// SMS objectvar sms = navigator.mozSMS;

// Send a messagesms.send("123456789", "Hello world!");

// Recieve a messagesms.onrecieved = function (event) { // Read message console.log(event.message);};

Page 49: JavaScript APIs - The Web is the Platform
Page 50: JavaScript APIs - The Web is the Platform

// Get battery level in percentagevar batteryLevel = battery.level * 100 + "%";

// Get whether device is charging or notvar chargingStatus = battery.charging;

// Time until the device is fully chargedvar batteryCharged = battery.chargingTime;

// Time until the device is dischargedvar batteryDischarged = battery.dischargingTime;

Page 51: JavaScript APIs - The Web is the Platform

battery.addEventLister("levelchange", function () { // Device's battery level changed}, false);

battery.addEventListener("chargingchange", function () { // Device got plugged in to power, or unplugged}, false);

battery.addEventListener("chargingtimechange", function () { // Device's charging time changed}, false);

battery.addEventListener("dischargingtimechange", function () { // Device's discharging time changed}, false);

Page 53: JavaScript APIs - The Web is the Platform

(function () { document.querySelector("#vibrate-one-second").addEventListener("click", function () { navigator.mozVibrate(1000); }, false);

document.querySelector("#vibrate-twice").addEventListener("click", function () { navigator.mozVibrate([200, 100, 200, 100]); }, false);

document.querySelector("#vibrate-long-time").addEventListener("click", function () { navigator.mozVibrate(5000); }, false);

document.querySelector("#vibrate-off").addEventListener("click", function () { navigator.mozVibrate(0); }, false);})();

Page 55: JavaScript APIs - The Web is the Platform
Page 57: JavaScript APIs - The Web is the Platform