Marakana HTML5 Training I
Total Page:16
File Type:pdf, Size:1020Kb
Marakana HTML5 Training i Marakana HTML5 Training Marakana HTML5 Training ii Copyright © 2011 Marakana, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of Marakana Inc. We took every precaution in preparation of this material. However, the we assumes no responsibility for errors or omis- sions, or for damages that may result from the use of information, including software code, contained herein. Firefox® is a registered trademark of the Mozilla Foundation. Opera® is a registered trademark of Opera Software. Google Chrome™ is a trademark of Google Inc. Safari® is a registered trademark of Apple Inc., registered in the U.S. and other countries. Internet Explorer® is a registered trademark of Microsoft Corporation in the United States and/or other countries. All other names are used for identification purposes only and are trademarks of their respective owners. Marakana offers a whole range of training courses, both on public and private. For list of upcoming courses, visit http://marakana.com Marakana HTML5 Training iii Contents 1 History, Vision And Future Of HTML51 1.1 What Is HTML5?...............................................1 1.2 History And Major Actors..........................................1 1.2.1 A Little Retrospective........................................2 1.2.2 What Is The W3C?..........................................2 1.2.3 What Is The WHATWG?.......................................3 1.3 Vision And Philosophy Behind HTML5...................................3 1.3.1 Compatibility.............................................3 1.3.2 Utility.................................................4 1.3.3 Interoperability............................................4 1.3.4 Universal Access...........................................5 1.4 Future Of HTML5..............................................5 1.4.1 Timeline...............................................5 2 Getting Started With HTML5 6 2.1 The State Of Browser Support........................................6 2.1.1 Browsers In Mobile Devices.....................................6 2.1.2 Feature Detection...........................................7 2.2 Support For Legacy Browsers........................................8 2.2.1 Graceful Degradation.........................................9 2.2.2 Emulation...............................................9 2.3 Developer Tools................................................9 2.4 Quiz...................................................... 10 Marakana HTML5 Training iv 3 Structure Of A Web Page 11 3.1 HTML5 DOCTYPE.............................................. 11 3.2 Page Encoding................................................ 12 3.3 HTML5 Markup............................................... 12 3.3.1 New And Updated Elements..................................... 13 3.3.2 Structural Elements.......................................... 13 3.3.3 New Attributes............................................ 15 3.3.4 Deprecated Elements And Attributes................................. 16 3.4 HTML5 And CSS3.............................................. 16 3.5 Browser Support............................................... 17 3.6 Quiz...................................................... 17 3.7 Lab: Converting a blog to HTML5...................................... 19 4 Forms 23 4.1 What Are The Needs For Web Applications?................................ 23 4.2 Current Solutions............................................... 24 4.3 New Input Types............................................... 24 4.4 New Attributes................................................ 25 4.5 Form Validation................................................ 26 4.6 Browser Support............................................... 28 4.7 Quiz...................................................... 28 4.8 Lab: Creating the form for our site...................................... 28 5 Audio And Video 32 5.1 The State of Web Audio And Video Based On Plugins........................... 32 5.2 The State Of Audio And Video Codecs (e.g. H.264, WebM, etc.)...................... 32 5.2.1 Video/Audio Codecs And Browser Support............................. 33 5.3 New Audio/Video Markup.......................................... 34 5.4 Attributes And Methods........................................... 35 5.5 Understanding Audio/Video Events..................................... 35 5.6 Customizing Audio/Video Controls..................................... 35 5.7 Quiz...................................................... 36 5.8 Lab: Create a custom video player...................................... 36 Marakana HTML5 Training v 6 HTML5 Canvas 39 6.1 Overview Of Graphics In The Browser.................................... 39 6.1.1 Canvas Vs. SVG........................................... 39 6.1.2 Accessibility............................................. 40 6.2 Using A Canvas................................................ 40 6.3 Context And Coordinates........................................... 41 6.4 Drawing Shapes................................................ 41 6.5 Working With Paths.............................................. 42 6.5.1 Drawing Straight Lines........................................ 42 6.5.2 Drawing Circles Or Arcs....................................... 43 6.6 Drawing Text................................................. 44 6.7 Drawing Images................................................ 45 6.8 Working With Pixels............................................. 46 6.9 Understanding Transforms.......................................... 48 6.9.1 Translation.............................................. 49 6.9.2 Rotation................................................ 50 6.9.3 Scaling................................................ 51 6.10 Browser Support............................................... 52 6.11 Quiz...................................................... 52 6.12 Lab: Create a drawing application...................................... 52 7 Data Storage 55 7.1 Problems With The Existing Cookie-based Model.............................. 55 7.2 Hacks Prior To HTML5............................................ 55 7.3 New Storage Options............................................. 56 7.3.1 Web Storage............................................. 56 7.3.2 Browser Support........................................... 57 7.3.3 Web SQL Storage.......................................... 57 7.3.4 Browser Support........................................... 59 7.4 Quiz...................................................... 59 7.5 Lab: Playing with the localStorage ................................... 59 8 HTML5 Offline Applications 60 8.1 The Need For Offline Mode.......................................... 60 8.2 The Manifest File............................................... 60 8.3 The applicationCache Events......................................... 61 8.4 Deployments And Updates.......................................... 63 8.5 Browser Support............................................... 63 8.6 Quiz...................................................... 63 8.7 Lab: Putting an application offline...................................... 63 Marakana HTML5 Training vi 9 HTML5 Geolocation 68 9.1 Introduction To Geolocation......................................... 68 9.2 Privacy Considerations............................................ 68 9.3 Many Ways To Get User Location...................................... 69 9.4 Two Main Methods.............................................. 69 9.5 The Position Object.............................................. 70 9.6 Handling Errors................................................ 71 9.7 The PositionOptions Object.......................................... 72 9.8 Browser Support............................................... 72 9.9 Quiz...................................................... 72 9.10 Lab: Getting our location to display it on a map............................... 73 10 HTML5 Web Workers 74 10.1 The Current JavaScript Execution Model................................... 74 10.2 Introduction To Web Workers......................................... 74 10.3 Usage Of Web Workers............................................ 75 10.4 Communication APIs............................................. 75 10.5 Handling Errors................................................ 76 10.6 Browser Support............................................... 76 10.7 Quiz...................................................... 76 10.8 Lab: Create and see a worker in action.................................... 76 11 HTML5 Messaging APIs 78 11.1 Understanding the same origin policy.................................... 78 11.2 Workaround to the same origin policy.................................... 79 11.3 Cross-document messaging.......................................... 79 11.3.1 Sending a message.......................................... 79 11.3.2 Receiving a message......................................... 80 11.3.3 Browser support........................................... 80 11.4 XMLHttpRequest Level 2.......................................... 80 11.4.1 Making a request........................................... 80 11.4.2 Progress Event............................................ 81 11.4.3 Browser Support........................................... 82 Marakana HTML5 Training vii 12 Web Sockets 83