SlideShare a Scribd company logo
1 of 101
Download to read offline
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')
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.
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" />
<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>
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)
<!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);
ctx.toDataURL("image/png");
ctx.toDataURL("image/png");
data:image/
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/
gTBAjyBGXv8bYECPK21Qn+BAGCPEHZe7wtAYK8bXWCP0GAIE9Q9h5vS+C6v6TXm/r8O1/j/vHla9y/vRo
+Qb7F4pcI/E
+AIG4CAgMBggxwLCFAEHcAgYEAQQY4lhAgiDuAwECAIAMcSwgQxB1AYCBAkAGOJQQI4g4gMBAgyADHEgIEcQcQGAg
QZIBjCQGCuAMIDAQIMsCxhABB3AEEBgIEGeBYQoAg7gACAwGCDHAsIUAQdwCBgQBBBjiWECCIO4DAQIAgAxxLCBDE
HUBgIECQAY4lBAjiDiAwECDIAMcSAgRxBxAYCBBkgGMJAU93j90BT1lvFeITpNWHNDECBIkVIk6LAEFafUgTI0CQW
CHitAgQpNWHNDECBIkVIk6LAEFafUgTI0CQWCHitAgQpNWHNDECBIkVIk6LAEFafUgTI0CQWCHitAgQpNWHNDECBI
kVIk6LAEFafUgTI0CQWCHitAgQpNWHNDECBIkVIk6LAEFafUgTI0CQWCHitAgQpNWHNDECBIkVIk6LAEFafUgTI0C
QWCHitAgQpNWHNDECBIkVIk6LAEFafUgTI0CQWCHitAgQpNWHNDECBIkVIk6LAEFafUgTI0CQWCHitAgQpNWHNDEC
BIkVIk6LAEFafUgTI0CQWCHitAgQpNWHNDECBIkVIk6LAEFafUgTI0CQWCHitAgQpNWHNDECBIkVIk6LAEFafUgTI
0CQWCHitAgQpNWHNDECBIkVIk6LAEFafUgTI0CQWCHitAgQpNWHNDECBIkVIk6LAEFafUgTI0CQWCHitAgQpNWHND
ECBIkVIk6LAEFafUgTI0CQWCHitAgQpNWHNDECBIkVIk6LAEFafUgTI0CQWCHitAgQpNWHNDECBIkVIk6LAEFafUg
TI0CQWCHitAgQpNWHNDECBIkVIk6LAEFafUgTI0CQWCHitAgQpNWHNDECvwHnaxGSkEUPVAAAAABJRU5ErkJggg==
data:image/png;base64,...
Canvas
+
drawImage
+
Video
=
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
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
});
});
Geolocation
Geolocation
Not always accurate!
navigator
.geolocation
.getCurrentPosition(
success,
err
);
Web Workers
•"Threads"
•Native or via Gears (or
setTimeout hack?)
•Sandboxed
•Debugging?
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

Js set timeout & setinterval
Js set timeout & setintervalJs set timeout & setinterval
Js set timeout & setinterval
ARIF MAHMUD RANA
 
02. prak.-pemrograman-berorientasi-objek
02. prak.-pemrograman-berorientasi-objek02. prak.-pemrograman-berorientasi-objek
02. prak.-pemrograman-berorientasi-objek
Jamil Jamil
 

What's hot (20)

Js set timeout & setinterval
Js set timeout & setintervalJs set timeout & setinterval
Js set timeout & setinterval
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
String Matching with Finite Automata and Knuth Morris Pratt Algorithm
String Matching with Finite Automata and Knuth Morris Pratt AlgorithmString Matching with Finite Automata and Knuth Morris Pratt Algorithm
String Matching with Finite Automata and Knuth Morris Pratt Algorithm
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning Libraries
 
Python Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String FormattingPython Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String Formatting
 
Introduction to OOP in Python
Introduction to OOP in PythonIntroduction to OOP in Python
Introduction to OOP in Python
 
Infix to postfix expression in ds
Infix to postfix expression in dsInfix to postfix expression in ds
Infix to postfix expression in ds
 
Optional in Java 8
Optional in Java 8Optional in Java 8
Optional in Java 8
 
Function in Python
Function in PythonFunction in Python
Function in Python
 
Sequence and Traverse - Part 1
Sequence and Traverse - Part 1Sequence and Traverse - Part 1
Sequence and Traverse - Part 1
 
02. prak.-pemrograman-berorientasi-objek
02. prak.-pemrograman-berorientasi-objek02. prak.-pemrograman-berorientasi-objek
02. prak.-pemrograman-berorientasi-objek
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 
Core Java - Quiz Questions - Bug Hunt
Core Java - Quiz Questions - Bug HuntCore Java - Quiz Questions - Bug Hunt
Core Java - Quiz Questions - Bug Hunt
 
Java NIO.2
Java NIO.2Java NIO.2
Java NIO.2
 
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
 
pandas: Powerful data analysis tools for Python
pandas: Powerful data analysis tools for Pythonpandas: Powerful data analysis tools for Python
pandas: Powerful data analysis tools for Python
 
Cross-platform UI Engines Rendering Performance
Cross-platform UI Engines Rendering PerformanceCross-platform UI Engines Rendering Performance
Cross-platform UI Engines Rendering Performance
 
19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 

Viewers also liked

Flex security
Flex securityFlex security
Flex security
chengalva
 

Viewers also liked (20)

Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
 
Echo HTML5
Echo HTML5Echo HTML5
Echo HTML5
 
HTML5--The 30,000' View (A fast-paced overview of HTML5)
HTML5--The 30,000' View (A fast-paced overview of HTML5)HTML5--The 30,000' View (A fast-paced overview of HTML5)
HTML5--The 30,000' View (A fast-paced overview of HTML5)
 
Getting Started with HTML5 in Tech Com (STC 2012)
Getting Started with HTML5 in Tech Com (STC 2012)Getting Started with HTML5 in Tech Com (STC 2012)
Getting Started with HTML5 in Tech Com (STC 2012)
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Scalable JavaScript Application Architecture
Scalable JavaScript Application ArchitectureScalable JavaScript Application Architecture
Scalable JavaScript Application Architecture
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Writing Efficient JavaScript
Writing Efficient JavaScriptWriting Efficient JavaScript
Writing Efficient JavaScript
 
Developing architects by design
Developing architects by designDeveloping architects by design
Developing architects by design
 
TEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkTEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of Work
 
JavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New WorldJavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New World
 
FrenchKit: End to End Application Development with Swift
FrenchKit: End to End Application Development with SwiftFrenchKit: End to End Application Development with Swift
FrenchKit: End to End Application Development with Swift
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Flex security
Flex securityFlex security
Flex security
 
HTML5
HTML5HTML5
HTML5
 
Business Interfaces using Virtual Objects, Visual-Force Forms and JavaScript
Business Interfaces using Virtual Objects, Visual-Force Forms and JavaScriptBusiness Interfaces using Virtual Objects, Visual-Force Forms and JavaScript
Business Interfaces using Virtual Objects, Visual-Force Forms and JavaScript
 
Verteilte versionsverwaltung mit Team Foundation Server 2012
Verteilte versionsverwaltung mit Team Foundation Server 2012Verteilte versionsverwaltung mit Team Foundation Server 2012
Verteilte versionsverwaltung mit Team Foundation Server 2012
 
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
 
Angular (v2 and up) - Morning to understand - Linagora
Angular (v2 and up) - Morning to understand - LinagoraAngular (v2 and up) - Morning to understand - Linagora
Angular (v2 and up) - Morning to understand - Linagora
 

More from Remy Sharp

Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQuery
Remy Sharp
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
Remy Sharp
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the new
Remy Sharp
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
Remy Sharp
 

More from Remy Sharp (20)

HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQuery
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Forget the Web
Forget the WebForget the Web
Forget the Web
 
Interaction Implementation
Interaction ImplementationInteraction Implementation
Interaction Implementation
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the new
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & sockets
 
Developing for Mobile
Developing for MobileDeveloping for Mobile
Developing for Mobile
 
Browsers with Wings
Browsers with WingsBrowsers with Wings
Browsers with Wings
 
Webapps without the web
Webapps without the webWebapps without the web
Webapps without the web
 
TwitterLib.js
TwitterLib.jsTwitterLib.js
TwitterLib.js
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?
 
codebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIscodebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIs
 
iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless Apps
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
HTML5 & Friends
HTML5 & FriendsHTML5 & Friends
HTML5 & Friends
 
HTML5 JS APIs
HTML5 JS APIsHTML5 JS APIs
HTML5 JS APIs
 
jQuery Loves Developers - SWDC2009
jQuery Loves Developers - SWDC2009jQuery Loves Developers - SWDC2009
jQuery Loves Developers - SWDC2009
 

HTML5 JavaScript APIs