(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 === "main" && !activePopup) { try { tizen.application.getCurrentApplication().exit(); } catch (ignore) { } } else { window.history.back(); } } }); }()); function parseSitemap(sitemap) { var output = parseWidgets(sitemap.homepage.widgets); document.getElementById("main_text").innerHTML = output; } function parseWidgets(widgets) { var s=""; widgets.forEach( function(wdg) { switch (wdg.type) { case "Frame": s+="

"+wdg.label+"
"; if (("widgets" in wdg) && wdg.widgets.length >0){ s+=parseWidgets(wdg.widgets); } s+="

"; break; case "Switch": break; case "Slider": var value=0; if (wdg.item.state !== null){value = wdg.item.state;} s+=createElement(wdg.label, wdg.item.name,''); break; case "Selection": s+="Selection
"; break; case "Text": s+=createElement(wdg.label,'',''); break; default: s+="Other
"; break; } }); return s; } function createElement(label, id, inner){ return '
'+label+''+inner+'
'; } function loadgui() { var client = new XMLHttpRequest(); client.onreadystatechange = function() { if (this.readyState === 4 && this.status === 200) { var myArr = JSON.parse(this.responseText); parseSitemap(myArr); } }; client.open('GET', 'http://habctrl:8080/rest/sitemaps/default', true); client.send(); }