HTML5 is all the rage with the cool kids, and although there's a lot of focus on the new language, there's lots of interesting new JavaScript APIs both in the HTML5 spec and separated out. This presentation will take you through demos and code and show off some of the outright crazy bleeding edge demos that are being produced today using the new JavaScript APIs.
5. “HTML5”
Web Forms Offline History API
Audio/Video Drag & Drop Undo
Canvas Editable X-Domain
Messaging
Storage Geolocation
Databases querySelector Workers
Sockets Server Events
36. var ctx = canvas.getContext('2d');
// Create radial gradient
var grad = ctx.createRadialGradient(0,0,0,0,0,600);
37. var ctx = canvas.getContext('2d');
// Create radial gradient
var grad = ctx.createRadialGradient(0,0,0,0,0,600);
grad.addColorStop(0, '#E4E4E4');
grad.addColorStop(1, '#000');
38. var ctx = canvas.getContext('2d');
// Create radial gradient
var grad = ctx.createRadialGradient(0,0,0,0,0,600);
grad.addColorStop(0, '#E4E4E4');
grad.addColorStop(1, '#000');
// assign gradients to fill
ctx.fillStyle = grad;
39. var ctx = canvas.getContext('2d');
// Create radial gradient
var grad = ctx.createRadialGradient(0,0,0,0,0,600);
grad.addColorStop(0, '#E4E4E4');
grad.addColorStop(1, '#000');
// assign gradients to fill
ctx.fillStyle = grad;
// draw 600x600 fill
ctx.fillRect(0,0,600,600);
43. body.onmousemove = function (event) {
var width = window.innerWidth,
height = window.innerHeight,
x = event.clientX,
y = event.clientY,
rx = 600 * x / width,
ry = 600 * y / width;
var xc = parseInt(256 * x / width);
var yc = parseInt(256 * y / height);
grad = ctx.createRadialGradient(rx, ry, 0, rx, ry, 600);
grad.addColorStop(0, '#000');
grad.addColorStop(1, 'rgb('+xc+','+(255-xc)+','+yc+')');
ctx.fillStyle = grad;
ctx.fillRect(0,0,600,600);
};
http://html5demos.com/canvas-grad
44. body.onmousemove = function (event) {
var width = window.innerWidth,
height = window.innerHeight, Caclulate from
x = event.clientX, the mouse the
y = event.clientY,
rx = 600 * x / width, radius and
ry = 600 * y / width; colours
var xc = parseInt(256 * x / width);
var yc = parseInt(256 * y / height);
grad = ctx.createRadialGradient(rx, ry, 0, rx, ry, 600);
grad.addColorStop(0, '#000');
grad.addColorStop(1, 'rgb('+xc+','+(255-xc)+','+yc+')');
ctx.fillStyle = grad;
ctx.fillRect(0,0,600,600);
};
http://html5demos.com/canvas-grad
45. body.onmousemove = function (event) {
var width = window.innerWidth,
height = window.innerHeight,
x = event.clientX,
y = event.clientY,
rx = 600 * x / width,
ry = 600 * y / width;
Re-render the
var xc = gradient
parseInt(256 * x / width);
var yc = parseInt(256 * y / height);
grad = ctx.createRadialGradient(rx, ry, 0, rx, ry, 600);
grad.addColorStop(0, '#000');
grad.addColorStop(1, 'rgb('+xc+','+(255-xc)+','+yc+')');
ctx.fillStyle = grad;
ctx.fillRect(0,0,600,600);
};
http://html5demos.com/canvas-grad
46. body.onmousemove = function (event) {
var width = window.innerWidth,
height = window.innerHeight,
x = event.clientX,
y = event.clientY,
rx = 600 * x / width,
ry = 600 * y / width;
var xc = parseInt(256 * x / width);
var yc = parseInt(256 * y / height);
Set 0, rx, ry, 600);
grad = ctx.createRadialGradient(rx, ry,
the new fill
grad.addColorStop(0, '#000'); style and refill -
the browser
grad.addColorStop(1, 'rgb('+xc+','+(255-xc)+','+yc+')');
ctx.fillStyle = grad;
handles the hard
ctx.fillRect(0,0,600,600); work
};
http://html5demos.com/canvas-grad
47. body.onmousemove = function (event) {
var width = window.innerWidth,
height = window.innerHeight,
x = event.clientX,
y = event.clientY,
rx = 600 * x / width,
ry = 600 * y / width;
var xc = parseInt(256 * x / width);
var yc = parseInt(256 * y / height);
grad = ctx.createRadialGradient(rx, ry, 0, rx, ry, 600);
grad.addColorStop(0, '#000');
grad.addColorStop(1, 'rgb('+xc+','+(255-xc)+','+yc+')');
ctx.fillStyle = grad;
ctx.fillRect(0,0,600,600);
};
http://html5demos.com/canvas-grad
86. app.html
var w = new Worker('worker.js');
w.onmessage = function (event) {
alert("msg: " + event.data);
};
w.postMessage('run');
87. app.html
var w = new Worker('worker.js');
w.onmessage = function (event) {
alert("msg: " + event.data);
};
w.postMessage('run');
88. app.html
var w = new Worker('worker.js');
w.onmessage = function (event) {
alert("msg: " + event.data);
};
w.postMessage('run');
89. app.html
var w = new Worker('worker.js');
w.onmessage = function (event) {
alert("msg: " + event.data);
};
w.postMessage('run');
90. worker.js
onmessage = function (event) {
if (event.data == 'run') {
run();
}
};
function run() {
var data = doCrazyNumberCrunch();
postMessage(data);
}
91. worker.js
onmessage = function (event) {
if (event.data == 'run') {
run();
}
};
function run() {
var data = doCrazyNumberCrunch();
postMessage(data);
}
92. worker.js
onmessage = function (event) {
if (event.data == 'run') {
run();
}
};
function run() {
var data = doCrazyNumberCrunch();
postMessage(data);
}
93. Can dos
•Spawn more workers
•setTimeout/Interval & clear
•Access navigator
•Error handling onerror
•XHR (though responseXML is null)
107. Browser: I have a
Browser: request Server: serve all manifest, cache
assets
Browser:
Server: serve
applicationCache Browser: reload
manifest assets
updated
Browser: only
Browser: serve Server: 304 Not
request manifest
locally Modified
file
108. Browser: I have a
Problem:
Browser: request Server: serve all manifest, cache
assets
Change of content
requires 2 refreshes
Server: serve
Browser:
applicationCache Browser: reload
manifest assets
updated
Browser: only
Browser: serve Server: 304 Not
request manifest
locally Modified
file
109. applicationCache.onUpdateReady =
function () {
applicationCache.swapCache();
notice('reload');
};
window.onOnline =
function () {
// fire an update to the cache
applicationCache.update();
};