(function () { window.addEventListener("tizenhwkey", function (ev) { var activePopup = null, page = null, pageId = ""; if (ev.keyName === "back") { activePopup = document.querySelector(".ui-popup-active"); page = document.getElementsByClassName("ui-page-active")[0]; pageId = page ? page.id : ""; if ((pageId === "page_0" || pageId === "page_unnamed") && !activePopup) { try { tizen.application.getCurrentApplication().exit(); } catch (ignore) { } } else { window.history.back(); } } }); }()); __page_count = 0; __unnamed_page = $('
') .addClass('ui-page') .prop('id', 'page_unnamed') .append($('
').addClass('ui-header').text("Main")) .append($('
').addClass('ui-content').prop('id', 'frame_unnamed')); function parseSitemap(sitemap, status) { parseWidgets(sitemap.homepage.widgets, __unnamed_page); if (__page_count === 0) { __unnamed_page.addClass('ui-page-active'); } $("body").append(__unnamed_page); var elPageIndicator = document.getElementById("pageIndicator"), pageIndicator = tau.widget.PageIndicator(elPageIndicator, {numberOfPages: __page_count+1}), index = 0; pageIndicator.setActive(0); } function createFrame(wdg, sitemap) { var newframe = $('
') .addClass('ui-content') .prop('id', 'frame_' + __page_count.toString()); var newpage = $('
') .addClass('ui-page') .prop('id', 'page_' + __page_count.toString()) .append($('
').addClass('ui-header').text(wdg.label)) .append(newframe); if (__page_count === 0) { newpage.addClass('ui-page-active'); } __page_count += 1; $("body").append(newpage); return newframe; } function createSwitch(wdg, page) { } function createSelection(wdg, page) { } function createSlider(wdg, page) { var value = 0; if (wdg.item.state !== null) { value = wdg.item.state; } page.append($('
') .append($('').text(wdg.label)) .append($('') .prop('data-link', wdg.item.link) .prop('data-item', wdg.item.name) .prop('type','range') .prop('data-freq','200') .prop('data-state',value) .prop('min','0') .prop('max','100') .prop('value',value) .change(function(){ updateItem($(this).prop('data-link'),$(this).val()); })) ); } function createText(wdg, page) { page.append($('
').text(wdg.label)); } function parseWidgets(widgets, parent) { widgets.forEach(function (wdg) { switch (wdg.type) { case "Frame": var newframe = createFrame(wdg, null); if (("widgets" in wdg) && wdg.widgets.length > 0) { parseWidgets(wdg.widgets, newframe); } break; case "Switch": // if (wdg.mappings.length === 0) { // s += createElement( // wdg.label, // wdg.item.name, // wdg.item.link, // '
' // + '' // + '
' // + '
'); // // //
// //
// // Single Toggle // //
// //
// // // //
// //
// //
// // Toggle state // //
// //
// } else if (wdg.mappings.length === 1) { // s += createElement(wdg.label, wdg.item.name, // wdg.item.link, ''); // } break; case "Slider": createSlider(wdg, parent); break; case "Selection": // var items = ''; // wdg.mappings.forEach(function(entry) { // items += '
'; // }); // s+= createElement(wdg.label, // wdg.item.name, // wdg.item.link, // '
'+items+'
'); break; case "Text": createText(wdg, parent); break; default: parent.append($('
'.text = "other")); break; } }); } function updateToggle(event) { var item = event.target.parentElement.parentElement .getAttribute('data-link'); var value = event.target.checked === true ? "ON" : "OFF"; updateItem(item, value); } function updateSelector(event) { var s = 3; return true; } function updateSimple(event) { var item = event.target.parentElement.getAttribute('data-link'); var value = event.target.value; updateItem(item, value); } function updateItem(item, value) { $.post({url:item, data: value.toString(), contentType: 'text/plain'}); } function loadgui() { $.get("http://habctrl:8080/rest/sitemaps/default", parseSitemap); } $(document).ready(loadgui);