Book Image

Developing Windows Store Apps with HTML5 and JavaScript

By : Rami Sarieddine
Book Image

Developing Windows Store Apps with HTML5 and JavaScript

By: Rami Sarieddine

Overview of this book

Windows 8 has already been launched and been installed on millions of devices while the store is getting populated with apps, and soon enough everyone will want a Windows Store app. So start now and learn how to develop apps for Windows 8 using HTML5, CSS3, and JavaScript and you will be killing two birds with one stone by getting introduced to important features in HTML5 and CSS3 at the same time. You will gain the advantage of utilizing your web development skills to transform your website into an app or the other way round. Developing Windows Store Apps with HTML5 and JavaScript is a practical, hands-on guide that covers the basic and important features of a Windows Store App along with code examples which will show you how to develop these features, all the while learning some of the new features in HTML5 and CSS3 which you can utilize in other areas of development. This book starts with the new features in HTML5 and CSS3 that are incorporated with Windows 8 development, and then moves on to creating a blank Windows Store app and add features to it as we move through the chapters till we package the app and make it ready for publishing. Finally, we will have a look at how similar it is to develop the same app with XAML. You will also learn how to add and use new controls dedicated for Windows 8 and then see how to fetch data for the app and bind it to the controls. We will also take a look at making the app adapt to change in screen sizes and rotation as well as how to make the app live with tiles and allow users to sign in using their email accounts. Also you will learn how to add an app bar, and lastly you learn how to finalize the app and publish it. If you want to leverage your web development skills and utilize it in developing for Windows 8, then you came to the right place. Developing Windows Store Apps with HTML5 and JavaScript is packed with examples and screenshots which will make it easy for you to implement all the things you learned throughout the book.
Table of Contents (19 chapters)
Developing Windows Store Apps with HTML5 and JavaScript
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Assigning custom data attributes


With HTML5, we now have the ability to assign custom data attributes to any HTML5 element. The W3C defines it as:

Attribute that is intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements.

These new custom data attributes consist of two parts:

  • Attribute name: It must start with the prefix data- and should be followed with at least one character and should not contain uppercase characters

  • Attribute value: It must be a string value

Let's add a custom attribute to a <div> tag as shown in the following code:

<div id="bookList" data-category="TechnicalBooks">
Developing for windows 8
</div>

You can see the custom attribute name data-category and the attribute value TechnicalBooks assigned to the <div> element. This data can be retrieved and updated by your JavaScript code using the native getAttribute and setAttribute methods, because the custom data attributes are considered to be part of the page on which they are used. The following is the code sample that shows how to manipulate the custom attributes using native JavaScript:

function getSetCategory() {
  var bookList = document.getElementById("bookList");
//get the value of the attribute
  var bookCategory = bookList.getAttribute('data-category');
//set the value for the attribute
  bookList.setAttribute('data-category', 'HealthBooks');
//remove the attribute
  bookList.removeAttribute('data-category');
}

The HTML5 specification clearly states that the data attributes should not be used to replace an existing attribute or an element that may be more semantically appropriate. For example, it would be inappropriate to add a data-time attribute to specify a time value in a span element as the following code shows:

<span data-time="08:00">8am<span>

The most appropriate and more semantic element to use would be a time element, as the following code shows:

<time datetime="08:00">8am</time>

When developing Windows 8 apps, we can use the Windows library for JavaScript (WinJS) to achieve more advanced binding of data to HTML elements. The Win8 JavaScript library utilizes the HTML data-* attributes to provide an easy way to programmatically implement data binding.