Академический Документы
Профессиональный Документы
Культура Документы
Senior Developer / Team Lead Head of Open Source Labs @ MAYFLOWER GMBH @ThorstenRinne
HTML5 for PHP Developers I Mayower GmbH I 23. September 2010 I 2
Topic:
HTML5 is about moving from documents to applications and from hacks to solutions.
Christian Heilmann on Twitter
HTML5 for PHP Developers I Mayower GmbH I 23. September 2010 I 10
1999:
PHP 3.0 - MySQL 3.22 Apache 1.3
HTML5 for PHP Developers I Mayower GmbH I 23. September 2010 I 13
1999:
Internet Explorer 5.0 XMLHttpRequest Object
HTML5 for PHP Developers I Mayower GmbH I 23. September 2010 I 14
since 5.0 (1999) since 1.0 (2004) since 1.2 (2004) since 7.6 (2004)
HTML5 for PHP Developers I Mayower GmbH I 23. September 2010 I 16
2005:
Ajax: A New Approach to Web Applications
Jesse James Garrett: http://www.adaptivepath.com/ideas/essays/archives/000385.php
HTML5 for PHP Developers I Mayower GmbH I 23. September 2010 I 17
2006:
Comet
Jesse James Garrett: http://www.adaptivepath.com/ideas/essays/archives/000385.php
HTML5 for PHP Developers I Mayower GmbH I 23. September 2010 I 20
Push
Ajax
Push
Facebook is an application!
Twitter is an application!
Applications?
Apps!
I ... is identical to the desktop browser I ... speaks HTML5 Geolocation support Websockets support Ofine apps I Faster update cycles than on the desktop I its a
WebSockets
var ws = new WebSocket("ws://example.com/service"); ws.onopen = function() { ws.send("message to send"); .... }; ws.onmessage = function (event) { var received_msg = event.data; ... }; ws.onclose = function() { // websocket is closed. };
Web Worker
I Multi-threaded JavaScript I Easy example:
main.js: var worker = new Worker('backgroundtask.js'); worker.onmessage = function(event) { alert(event.data); };
Web Messaging
<iframe src="http://www.example.org/message/" id="iframe"> </iframe> <form id="form"> <input type="text" id="msg" value="Message to send"/> <input type="submit"/> </form> <script> window.onload = function() { var win = document.getElementById("iframe").contentWindow; document.getElementById("form").onsubmit = function(e) { win.postMessage(document.getElementById("msg").value); e.preventDefault(); }; }; </script>
Web Messaging
<strong>This iframe is located on www.example.com</strong> <div id="test">Hello, World!</div> <script> document.addEventListener("message", function(e){ document.getElementById("test").textContent = e.domain + " said: " + e.data; }, false); </script>
WebStorage
I Short living data I sessionStorage object I will be deleted after closing the browser I Long living data I localStorage object I will not be deleted after closing the browser
Safari 2 MB Firefox 5 MB ~ 200 MB IE 5 MB
HTML5 for PHP Developers I
Opera 4 MB ~
Mayower GmbH I 23. September 2010 I 43
WebStorage
if (!sessionStorage['counter']) { sessionStorage['counter'] = 0; } else { sessionStorage['counter']++; } document.querySelector('#content').innerHTML = '<p>This sample has been run ' + sessionStorage.getItem('counter') + ' times</p>' + '<p>(The value will be available until ' + we close the tab)</p>';
Geolocation
if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { var lat = position.coords.latitude; var lng = position.coords.longitude; var options = { position: new google.maps.LatLng(lat, lng) } var marker = new google.maps.Marker(options); marker.setMap(map); }); }
function drag(target, e) { e.dataTransfer.setData('Text', target.id); } function drop(target, e) { var id = e.dataTransfer.getData('Text'); target.appendChild(document.getElementById(id)); e.preventDefault(); }
HTML5 for PHP Developers I Mayower GmbH I 23. September 2010 I 47
xhr.upload.addEventListener("progress", function(e) { if (e.lengthComputable) { var percentage = Math.round((e.loaded * 100) / e.total); // do something } }, false);
The LAMP stack gets a bust of Janus real time web component web application component
HTML5 for PHP Developers I Mayower GmbH I 23. September 2010 I 53
<!DOCTYPE html>
WebForms
<input placeholder="Search Bookmarks and History">
after clicking...
WebForms
<input maxlength="256" name="q" value="" autofocus>
WebForms
<input type="tel"> for telephone numbers <input type="url"> for web addresses <input type="email"> for email addresses
WebForms
<input type="number" min="0" max="10" step="2" value="6">
0 2 4 6 8 10
HTML5 for PHP Developers I Mayower GmbH I 23. September 2010 I 65
WebForms
<input type="range" min="0" max="10" step="2" value="6">
Datepicker WebForms
<input <input <input <input <input <input type="date"> type="month"> type="week"> type="time"> type="datetime"> type="datetime-local">
contenteditable
<p contenteditable="true">Edit foobar!</p>
I Save it with I sessionStorage I localStorage I PHP powered backend with Ajax :-)
<canvas>
<canvas id="canvas" width="838" height="220"></canvas> <script> var canvasContext = $("#canvas").getContext("2d"); canvasContext.fillRect(250, 25, 150, 100); canvasContext.beginPath(); canvasContext.arc(450, 110, 100, Math.PI * 1/2, Math.PI * 3/2); canvasContext.lineWidth = 15; canvasContext.lineCap = 'round'; canvasContext.strokeStyle = 'rgba(255, 127, 0, 0.5)'; canvasContext.stroke(); </script>
<canvas>
WebGL
New selectors
@font-face { font-family: 'FuturaNew'; src: url(FuturaNew.otf); } header { font-family: 'LeagueGothic'; colour: red; }
I better font support I better text wrapping I columns I opacity I Hue/saturation/luminance color model I Rounded corners, nally! ;-) I Gradients I Shadows I better backgrounds I transitions and animations
HTML5 readiness
HTML5 readiness
62% 46% 53% 69% 72%
9%
IE8 Firefox 3.6 Opera 10.6 Mobile Safari (iOS 4)
Safari 5.0
Chrome 6.0
html5test.com
HTML5 for PHP Developers I Mayower GmbH I 23. September 2010 I 79
HTML5 readiness
Crossdocument messaging content editable New semantic tags getElementsBy ClassName() <video> <audio>
HTML5 readiness
Basic <canvas> support Text API for Ofine Web Drag n Drop Applications <canvas> HTML5 Inline SVG WebForms
HTML5 readiness
Crossdocument messaging content editable New semantic tags getElementsBy ClassName() <video> <audio>
HTML5 readiness
Basic <canvas> support Text API for Ofine Web Drag n Drop Applications <canvas> HTML5 Inline SVG WebForms
But...
29,0% 24,0% 13,0% 7,5% 6,4% 4,5% 4,4% 2,9% 2,4% 1,4% 0,8% 0,4% 2,9%
Questions?
Contact
Thorsten Rinne thorsten.rinne@mayower.de +49 89 242054-31 Mayower GmbH Mannhardtstr. 6 80538 Mnchen