SlideShare a Scribd company logo
APIs
HTML5
HTML5 JavaScript APIs
jsconf.eu 2009
2022
2022 =
two completely
interoperable
implementations
CSS 2.1
HTML5
Web Forms
Audio/Video
Canvas
Offline
Drag & Drop
Editable
History API
Undo
X-Domain
Messaging
HTML5
“HTML5”
“HTML5”
•Web Forms 2.0
•Audio & Video
•Canvas
•Offline
•Storage
•Geolocation
•Workers
“HTML5”
•Web Forms 2.0
•Audio & Video
•Canvas
•Offline
•Storage
•Geolocation
•Workers
“HTML5”
•Web Forms 2.0
•Audio & Video
•Canvas
•Offline
•Storage
•Geolocation
•Workers
Web Forms 2.0
Actual search for "web forms", wtf? http://tr.im/webforms_pic ➙
"JavaScript is only good
for image roll overs &
form validation"
"JavaScript is only good
for image roll overs &
form validation"
:hover
"JavaScript is only good
for image roll overs &
form validation"
.hasFeature('WebForms', '2.0')
"JavaScript is only good
for image roll overs &
form validation"
awesome shit"
.hasFeature('WebForms', '2.0')
HTML5 JavaScript APIs
var f = document.querySelector('form');
f.onsubmit = function () {
if ( this.checkValidity() ) {
alert("It's all okay");
} else {
alert("Something's gone wrong...");
return false;
}
};
Less JavaScript
on donkey work
==
more JavaScript
on awesome work.
HTML5 JavaScript APIs
HTML5 JavaScript APIs
Native Media
Elements
<object classid="clsid:d27cdb6e-a
height="344" codebase="http://dow
flash/swflash.cab#version=6,0,40,
<param name="allowFullScreen" val
<param name="allowscriptaccess" v
<param name="src" value="http://w
<param name="allowfullscreen" val
<embed type="application/x-shockw
src="http://www.youtube.com/v/oHg
allowscriptaccess="always" allowf
</embed>
</object>
<video src="dizzy.ogv" />
HTML5 JavaScript APIs
<video>
<source src="dizzy.ogv" />
<source src="dizzy.mp4" />
</video>
?
<video>
<source src="dizzy.ogv" />
<source src="dizzy.mp4" />
</video>
<video>
<source src="dizzy.ogv" />
<source src="dizzy.mp4" />
<!-- QuickTime support -->
<object><param></object>
</video>
<video>
<source src="dizzy.ogv" />
<source src="dizzy.mp4" />
<!-- QuickTime support -->
<object><param></object>
<!-- down to flash -->
<object><param></object>
</video>
<video>
<source src="dizzy.ogv" />
<source src="dizzy.mp4" />
</video>
HTML5 JavaScript APIs
if (video.paused) {
if (video.ended) {
video.currentTime = 0;
}
video.play();
} else {
video.pause();
}
if (video.paused) {
if (video.ended) {
video.currentTime = 0;
}
video.play();
} else {
video.pause();
}
if (video.paused) {
if (video.ended) {
video.currentTime = 0;
}
video.play();
} else {
video.pause();
}
if (video.paused) {
if (video.ended) {
video.currentTime = 0;
}
video.play();
} else {
video.pause();
}
addEvent(
video,
'timeupdate',
function () {
positon.innerHTML =
➥ asTime(this.currentTime);
}
);
addEvent(
video,
'timeupdate',
function () {
positon.innerHTML =
➥ asTime(this.currentTime);
}
);
addEvent(
video,
'timeupdate',
function () {
positon.innerHTML =
➥ asTime(this.currentTime);
}
);
•play(), pause()
•paused, ended, currentTime
•canplay, timeupdate, ended
•and a bunch more.
•Bugs tend to be rather
quiet...shhh...
•Firefox needs the right
content-type
•Safari will plough ahead
Accessibility?
http://open.bbc.co.uk/rad/demos/html5/rdtv/episode2/
Canvas
(+ excanvas.js)
HTML5 JavaScript APIs
HTML5 JavaScript APIs
<!DOCTYPE html>
<html>
<head>
<title>Canvas</title>
</head>
<body>
<canvas></canvas>
</body>
</html>
var ctx = canvas.getContext('2d');
var ctx = canvas.getContext('2d');
// Create radial gradient
var grad = ctx.createRadialGradient(0,0,0,0,0,600);
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');
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;
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);
HTML5 JavaScript APIs
ctx.toDataURL("image/png");
ctx.toDataURL("image/png");
data:image/
png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAFxUlEQVR4Ae3dQW5jORAEUXvQ97+yez
CzNQpNyPwdIp+XJkVlRTKgheGvz69/fz78IIDAtwT+
+fa3fokAAv8RIIiLgMBAgCADHEsIEMQdQGAgQJABjiUECOIOIDAQIMgAxxICBHEHEBgIEGSAYwkBgrgDCAwECDLAs
YQAQdwBBAYCBBngWEKAIO4AAgMBggxwLCFAEHcAgYEAQQY4lhAgiDuAwECAIAMcSwj8+nEEn58/
fuQfHehf6/8Ik01rBHyCrPGy+zICBLmscOOuESDIGi+7LyNAkMsKN
+4aAYKs8bL7MgIEuaxw464RIMgaL7svI0CQywo37hoBgqzxsvsyAgS5rHDjrhEgyBovuy8jQJDLCjfuGgGCrPGy
+zICBLmscOOuESDIGi+7LyNAkMsKN
+4aAYKs8bL7MgIEuaxw464RIMgaL7svI0CQywo37hoBgqzxsvsyAgS5rHDjrhEgyBovuy8jQJDLCjfuGgGCrPGy
+zICBLmscOOuESDIGi+7LyNAkMsKN+4aAYKs8bL7MgI//3R3T1m/
7AqdPa5PkLP7Nd2LBAjyIkAvP5sAQc7u13QvEiDIiwC9/
GwCBDm7X9O9SIAgLwL08rMJEOTsfk33IgGCvAjQy88mQJCz+zXdiwR+/i/pLwba/fLPj7/zPe5fH1+7R3P+BgI
+QTZAdeQ5BAhyTpcm2UCAIBugOvIcAgQ5p0uTbCBAkA1QHXkOAYKc06VJNhAgyAaojjyHAEHO6dIkGwgQZANUR55D
gCDndGmSDQQIsgGqI88hQJBzujTJBgIE2QDVkecQIMg5XZpkAwGCbIDqyHMIEOScLk2ygQBBNkB15DkECHJOlybZQ
IA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NDECBIkVIk6LAEFafUgTI0CQWCHitAgQpNWHNDECvwHnaxGSkEUPVAAAAABJRU5ErkJggg==
data:image/png;base64,...
Canvas
+
drawImage
+
Video
=
HTML5 JavaScript APIs
HTML5 JavaScript APIs
HTML5 JavaScript APIs
ctx.getImageData()
http://blog.mozbox.org/post/2009/04/12/Firefox-35%3A-a-new-experiment-with-Canvas-Video
frame = ctx.getImageData(0, 0, w, h);
i = 0; // or via loop
r = frame.data[i + 0];
g = frame.data[i + 1];
b = frame.data[i + 2];
ctx.translate(canvas.width/2, canvas.height/2);
ctx.scale(-1, 1);
ctx.translate(-canvas.width/2, -canvas.height/2);
ctx.drawImage(
video, 0, 0,
video.width,
video.height,
0, 0,
canvas.width,
canvas.height);
Don't use for evil
Offline Applications
Offline Applications
Offline Apps
•Application cache
•Events: offline, online
•navigator.onLine property
http://icanhaz.com/rubiks
Enable
<!DOCTYPE html>
<html manifest="my.manifest">
<body>
<!-- my page -->
</body>
</html>
CACHE MANIFEST
images/shade.jpg
images/bin.jpg
#version 13
my.manifest
Cache
•First line: CACHE MANIFEST
•Requires text/cache-manifest
•Recommend using versioning
•window.applicationCache
•Add it last!
The process
Browser: request Server: serve all
Browser: I have a
manifest, cache
assets
Server: serve
manifest assets
Browser:
applicationCache
updated
Browser: reload
Browser: only
request manifest
file
Server: 304 Not
Modified
Browser: serve
locally
Storage
(giant cookies)
SQLite
key/val
key/value
sessionStorage
localStorage
.setItem(key, value);
.getItem(key);
window based
key/value
sessionStorage
localStorage
.setItem(key, value);
.getItem(key);
window based
domain based
HTML5 JavaScript APIs
SQLite
"User agents must
implement the SQL dialect
supported by Sqlite 3.6.19"
Another one that fails
super silently :(
db = openDatabase("demo", "1.0",
"sample", 200000);
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM tweets
WHERE mention = ?', [mention], function
(tx, results) {
// do something with results
});
});
db = openDatabase("demo", "1.0",
"sample", 200000);
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM tweets
WHERE mention = ?', [mention], function
(tx, results) {
// do something with results
});
});
db = openDatabase("demo", "1.0",
"sample", 200000);
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM tweets
WHERE mention = ?', [mention], function
(tx, results) {
// do something with results
});
});
db = openDatabase("demo", "1.0",
"sample", 200000);
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM tweets
WHERE mention = ?', [mention], function
(tx, results) {
// do something with results
});
});
HTML5 JavaScript APIs
Geolocation
Geolocation
HTML5 JavaScript APIs
Not always accurate!
navigator
.geolocation
.getCurrentPosition(
success,
err
);
HTML5 JavaScript APIs
Web Workers
•"Threads"
•Native or via Gears (or
setTimeout hack?)
•Sandboxed
•Debugging?
HTML5 JavaScript APIs
http://html5demos.com/worker
•importScripts
•postMessage
•onmessage
•onconnect
var w = new Worker('worker.js');
w.onmessage = function (event) {
alert("msg: " + event.data);
};
w.postMessage('run');
app.html
importScripts('xhr.js', 'db.js');
onmessage = function (event) {
if (event.data == 'run') {
run();
}
};
function run() {
var data = doCrazyNumberCrunch();
postMessage(data);
}
worker.js
importScripts('xhr.js', 'db.js');
onmessage = function (event) {
if (event.data == 'run') {
run();
}
};
function run() {
var data = doCrazyNumberCrunch();
postMessage(data);
}
worker.js
importScripts('xhr.js', 'db.js');
onmessage = function (event) {
if (event.data == 'run') {
run();
}
};
function run() {
var data = doCrazyNumberCrunch();
postMessage(data);
}
worker.js
And a
lot
more...
Attributes: data-*, itemProp,
sandbox (on iframes)
Microdata API,
datagrid, XHR2 &
upload progress
Drag & Drop,
History manager ARIA overlap
querySelector
<progress>
<meter>
<datalist>
<ruby>
http://www.whatwg.org/html5/
http://tr.im/whatwg_complete
irc://irc.freenode.net/#whatwg
Remy
Sharp
@rem
JavaScript Conference:
full-frontal.org
http://html5demos.com
Links: http://tr.im/rs_jsconfeu
(another)
Pro tip: cats can't
code for crap

More Related Content

What's hot (20)

PDF
Forget the Web
Remy Sharp
 
PPTX
REST with Eve and Python
PiXeL16
 
KEY
CodeIgniter 3.0
Phil Sturgeon
 
KEY
Building a real life application in node js
fakedarren
 
PDF
Future of Web Apps: Google Gears
dion
 
KEY
Deploying
soon
 
PDF
Django Rest Framework and React and Redux, Oh My!
Eric Palakovich Carr
 
PPTX
Open Source Ajax Solution @OSDC.tw 2009
Robbie Cheng
 
PDF
YouDrup_in_Drupal
tutorialsruby
 
KEY
#NewMeetup Performance
Justin Cataldo
 
PDF
Resource registries plone conf 2014
Ramon Navarro
 
PDF
HTML5 for the Silverlight Guy
David Padbury
 
PPT
Play!ng with scala
Siarzh Miadzvedzeu
 
PDF
Performance Improvements in Browsers
jeresig
 
PDF
Micro app-framework
Michael Dawson
 
ODP
An Introduction to Windows PowerShell
Dale Lane
 
PDF
Meetup Performance
Greg Whalin
 
PDF
Introduction to Flask Micro Framework
Mohammad Reza Kamalifard
 
PDF
Into the ZF2 Service Manager
Chris Tankersley
 
PDF
Introduction To Django (Strange Loop 2011)
Jacob Kaplan-Moss
 
Forget the Web
Remy Sharp
 
REST with Eve and Python
PiXeL16
 
CodeIgniter 3.0
Phil Sturgeon
 
Building a real life application in node js
fakedarren
 
Future of Web Apps: Google Gears
dion
 
Deploying
soon
 
Django Rest Framework and React and Redux, Oh My!
Eric Palakovich Carr
 
Open Source Ajax Solution @OSDC.tw 2009
Robbie Cheng
 
YouDrup_in_Drupal
tutorialsruby
 
#NewMeetup Performance
Justin Cataldo
 
Resource registries plone conf 2014
Ramon Navarro
 
HTML5 for the Silverlight Guy
David Padbury
 
Play!ng with scala
Siarzh Miadzvedzeu
 
Performance Improvements in Browsers
jeresig
 
Micro app-framework
Michael Dawson
 
An Introduction to Windows PowerShell
Dale Lane
 
Meetup Performance
Greg Whalin
 
Introduction to Flask Micro Framework
Mohammad Reza Kamalifard
 
Into the ZF2 Service Manager
Chris Tankersley
 
Introduction To Django (Strange Loop 2011)
Jacob Kaplan-Moss
 

Viewers also liked (20)

PDF
Javascript Best Practices
Christian Heilmann
 
PDF
Echo HTML5
Nathan Smith
 
PDF
HTML5--The 30,000' View (A fast-paced overview of HTML5)
Peter Lubbers
 
PPTX
Getting Started with HTML5 in Tech Com (STC 2012)
Peter Lubbers
 
PPT
JavaScript - An Introduction
Manvendra Singh
 
PDF
Scalable JavaScript Application Architecture
Nicholas Zakas
 
PDF
JavaScript Programming
Sehwan Noh
 
PDF
Writing Efficient JavaScript
Nicholas Zakas
 
PDF
Developing architects by design
Shyamsunder Namdhari
 
PDF
TEDx Manchester: AI & The Future of Work
Volker Hirsch
 
PDF
FrenchKit: End to End Application Development with Swift
Chris Bailey
 
PDF
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)
Jollen Chen
 
PDF
JavaScript
Bharti Gupta
 
PPT
Flex security
chengalva
 
PPT
HTML5
Doncho Minkov
 
PDF
Business Interfaces using Virtual Objects, Visual-Force Forms and JavaScript
Salesforce Developers
 
PPTX
Verteilte versionsverwaltung mit Team Foundation Server 2012
Daniel Marbach
 
PDF
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Luciano Mammino
 
PDF
Angular (v2 and up) - Morning to understand - Linagora
LINAGORA
 
PDF
Yii PHP MVC Framework presentation silicongulf.com
Christopher Cubos
 
Javascript Best Practices
Christian Heilmann
 
Echo HTML5
Nathan Smith
 
HTML5--The 30,000' View (A fast-paced overview of HTML5)
Peter Lubbers
 
Getting Started with HTML5 in Tech Com (STC 2012)
Peter Lubbers
 
JavaScript - An Introduction
Manvendra Singh
 
Scalable JavaScript Application Architecture
Nicholas Zakas
 
JavaScript Programming
Sehwan Noh
 
Writing Efficient JavaScript
Nicholas Zakas
 
Developing architects by design
Shyamsunder Namdhari
 
TEDx Manchester: AI & The Future of Work
Volker Hirsch
 
FrenchKit: End to End Application Development with Swift
Chris Bailey
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)
Jollen Chen
 
JavaScript
Bharti Gupta
 
Flex security
chengalva
 
Business Interfaces using Virtual Objects, Visual-Force Forms and JavaScript
Salesforce Developers
 
Verteilte versionsverwaltung mit Team Foundation Server 2012
Daniel Marbach
 
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Luciano Mammino
 
Angular (v2 and up) - Morning to understand - Linagora
LINAGORA
 
Yii PHP MVC Framework presentation silicongulf.com
Christopher Cubos
 
Ad

More from Remy Sharp (20)

PDF
HTML5: where flash isn't needed anymore
Remy Sharp
 
PDF
Yearning jQuery
Remy Sharp
 
PDF
Is HTML5 Ready? (workshop)
Remy Sharp
 
PDF
Interaction Implementation
Remy Sharp
 
PDF
jQuery: out with the old, in with the new
Remy Sharp
 
PDF
HTML5: huh, what is it good for?
Remy Sharp
 
PDF
HTML5 tutorial: canvas, offfline & sockets
Remy Sharp
 
PDF
Developing for Mobile
Remy Sharp
 
PDF
Browsers with Wings
Remy Sharp
 
PDF
Webapps without the web
Remy Sharp
 
PDF
TwitterLib.js
Remy Sharp
 
PDF
codebits 2009 HTML5 JS APIs
Remy Sharp
 
PDF
iPhone Appleless Apps
Remy Sharp
 
PDF
jQuery Loves Developers - Oredev 2009
Remy Sharp
 
PDF
Write Less Do More
Remy Sharp
 
PDF
HTML5 & Friends
Remy Sharp
 
PDF
HTML5 JS APIs
Remy Sharp
 
PDF
jQuery Loves Developers - SWDC2009
Remy Sharp
 
PDF
DOM Scripting Toolkit - jQuery
Remy Sharp
 
PDF
Prototype & jQuery
Remy Sharp
 
HTML5: where flash isn't needed anymore
Remy Sharp
 
Yearning jQuery
Remy Sharp
 
Is HTML5 Ready? (workshop)
Remy Sharp
 
Interaction Implementation
Remy Sharp
 
jQuery: out with the old, in with the new
Remy Sharp
 
HTML5: huh, what is it good for?
Remy Sharp
 
HTML5 tutorial: canvas, offfline & sockets
Remy Sharp
 
Developing for Mobile
Remy Sharp
 
Browsers with Wings
Remy Sharp
 
Webapps without the web
Remy Sharp
 
TwitterLib.js
Remy Sharp
 
codebits 2009 HTML5 JS APIs
Remy Sharp
 
iPhone Appleless Apps
Remy Sharp
 
jQuery Loves Developers - Oredev 2009
Remy Sharp
 
Write Less Do More
Remy Sharp
 
HTML5 & Friends
Remy Sharp
 
HTML5 JS APIs
Remy Sharp
 
jQuery Loves Developers - SWDC2009
Remy Sharp
 
DOM Scripting Toolkit - jQuery
Remy Sharp
 
Prototype & jQuery
Remy Sharp
 
Ad

HTML5 JavaScript APIs