Profile

Click to view full profile
Hi, I'm Veerapat Sriarunrungrueang, an expert in technology field, especially full stack web development and performance testing.This is my coding diary. I usually develop and keep code snippets or some tricks, and update to this diary when I have time. Nowadays, I've been giving counsel to many well-known firms in Thailand.
view more...

Tuesday, July 30, 2013

JavaScript control attributes for Windows Store Apps (data-win-* attributes)

Lately, I have done something mostly related to Windows Store App and I'm also interested in JavaScript. This language is very powerful in so many ways. It's easy to entry, you just have a browser and a text editor then your can start develop something. However, JavaScript is easy to start, but it is not easy to be mastered. I'm not a JavaScript professional, not even a web developer. But when compared the learning curve between JavaScript and Strong-Typed Languages (such as Java, C#). By the way, this post is not about language technologies.

JavaScript is powerful enough to make it be a one of native languages of Windows Store App. In this post would like to give introduction about added-on attributes to make html elements transformed into Windows Store controls.

The first one is "data-win-control". It is a very important attribute to create WinJS controls by giving them a control name then call process UI to apply controls on the startup. This attribute can't not be used on iframe element.
<div data-win-control="controlName" />

(function( ) {

    document.addEventListener("DOMContentLoaded", function(e) {
        WinJS.UI.processAll();
    });

})();


The next one is "data-win-options". It can receive a JavaScript object to set that control properties.
<div 
    data-win-control="control" 
    data-win-options="{ property1 : value1, property2 : value2}">
</div>


It can also do binding data as XAML does using "data-win-bind" (with some code in JavaScript side).
    <element data-win-bind="elementProperty1 : dataSourceProperty1; elementProperty2: dataSourceProperty2" />


To make elements can't be selected, use "data-win-selectable" property. It is just a true / false value. By default, all input elements and elements with the contentEditable attribute set to true are selectable.
<div data-win-selectable="true" ...


The controls can be binded with external resources for localization or other purposes using "data-win-res".
<p data-win-res="{textContent: 'String1'}"></p>


For the "data-win-fragmentLoad" property, the document said that this will be removed from the next version of Windows Library for JavaScript. So, I think we should not use it.

Reference: Windows Library for JavaScript control attributes

No comments:

Post a Comment