
Stephen Walther ® Windows 8.1 Apps with HTML5 and JavaScript UNLEASHED 800 East 96th Street, Indianapolis, Indiana 46240 USA Windows® 8.1 Apps with HTML5 and JavaScript Unleashed Editor-in-Chief Copyright © 2014 by Pearson Education Greg Wiegand All rights reserved. No part of this book shall be reproduced, 8.1d in a retrieval system, Executive Editor or transmitted by any means, electronic, mechanical, photocopying, recording, or other- Neil Rowe wise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has Development Editor been taken in the preparation of this book, the publisher and author assume no respon- Mark Renfrow sibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein. Managing Editor ISBN-13: 978-0-672-33711-6 Kristy Hart ISBN-10: 0-672-33711-8 Library of Congress Control Number 2013951680 Project Editor Elaine Wiley Printed in the United States on America First Printing December 2013 Indexer Tim Wright Trademarks All terms mentioned in this book that are known to be trademarks or service marks have Proofreader been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this Charlotte HKughen information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark. Technical Editors Jeff Burtoft Warning and Disclaimer James Boddie Every effort has been made to make this book as complete and as accurate as possi- ble, but no warranty or fitness is implied. The information provided is on an “as is” Publishing Coordinator basis. The author(s) and the publisher shall have neither liability nor responsibility to Cindy Teeters any person or entity with respect to any loss or damages arising from the information contained in this book or from the use of the programs accompanying it. Senior Compositor Gloria Schurick Special Sales For information about buying this title in bulk quantities, or for special sales opportuni- ties (which may include electronic versions; custom cover designs; and content particu- lar to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at [email protected] or (800) 382-3419. For government sales inquiries, please contact [email protected]. For questions about sales outside the U.S., please contact [email protected]. Contents at a Glance Introduction ........................................................................................ 1 1 Building Windows Store Apps ............................................................... 5 2 WinJS Fundamentals .......................................................................... 45 3 Observables, Bindings, and Templates ................................................. 81 4 Using WinJS Controls ....................................................................... 113 5 Creating Forms ................................................................................. 149 6 Menus and Flyouts ............................................................................ 169 7 Using the ItemContainer, Repeater, and FlipView Controls ................. 197 8 Using the ListView Control ............................................................... 223 9 Creating Data Sources ....................................................................... 263 10 Storing Data with Windows Azure ...................................................... 295 11 App Events and States ....................................................................... 311 12 Page Fragments and Navigation ......................................................... 333 13 Creating Share and Search Contracts .................................................. 353 14 Using the Live Connect API ............................................................... 387 15 Graphics and Games ......................................................................... 417 16 Creating a Task List App .................................................................... 431 Index ...............................................................................................449 Table of Contents Introduction 1 Updated for Windows 8.1 ..................................................................... 2 Prerequisites for This Book .................................................................... 3 Source Code ........................................................................................ 3 1 Building Windows Store Apps 5 What Is a Windows Store App? ............................................................. 5 Microsoft Design Style Principles .................................................. 6 Common Features of Windows Store Apps ..................................... 7 Creating Your First Windows Store App ............................................... 13 Creating the Visual Studio Project ............................................... 14 Declaring App Capabilities ......................................................... 15 Creating the HTML Page ............................................................ 17 Creating the Style Sheet ............................................................. 18 Creating the JavaScript File ......................................................... 18 Running the App ....................................................................... 21 Elements of a Windows Store App ....................................................... 21 JavaScript .................................................................................. 21 HTML5 ..................................................................................... 22 Cascading Style Sheets 3 ............................................................. 22 Windows Runtime ..................................................................... 23 Windows Library for JavaScript ................................................... 23 What About jQuery? .................................................................. 24 Building Windows Store Apps with Visual Studio ................................. 26 Windows Store App Project Templates ......................................... 27 Running a Windows Store App ................................................... 31 Debugging a Windows Store App ........................................................ 33 Using the Visual Studio JavaScript Console Window ..................... 33 Setting Breakpoints .................................................................... 34 Using the DOM Explorer ............................................................ 35 Publishing to the Windows Store ........................................................ 36 Register as a Windows Developer ................................................ 36 Submitting Your App ................................................................. 37 Passing App Certification ........................................................... 39 Migrating from Windows 8 to Windows 8.1 ......................................... 41 Summary .......................................................................................... 42 Contents v 2 WinJs Fundamentals 45 Namespaces, Modules, and Classes ...................................................... 45 Using Namespaces ..................................................................... 46 Using the Module Pattern........................................................... 48 Using Classes ............................................................................ 51 Asynchronous Programming with Promises .......................................... 56 Using Promises .......................................................................... 57 Using then() Versus done() ........................................................ 59 Creating Promises ...................................................................... 60 Creating a Timeout Promise ....................................................... 61 Canceling Promises .................................................................... 62 Composing Promises.................................................................. 63 Retrieving DOM Elements with Query Selectors .................................... 63 Performing Queries with the WinJS.Utilities.query() Method .... 64 Retrieving a Single Element with the WinJS.Utilities.id() Method .................................................................................. 66 Using the WinJS.Utilities.children() method .......................... 67 Working with the QueryCollection Class .................................... 68 Performing Ajax Calls with the xhr Function ....................................... 69 Specifying Different Response Types ............................................ 72 Customizing the Properties of the XmlHttpRequest Object ............. 73 Using the Scheduler to Prioritize Jobs .................................................. 75 Setting Job Priorities .................................................................. 77 Yielding to a Higher Priority Job ................................................. 77 Summary .......................................................................................... 80 3 Observables, Bindings, and Templates 81 Understanding Observables ................................................................ 81 Creating an Observable .............................................................
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages73 Page
-
File Size-