From 96b345cdd68e0d5f434cd1bd25417e0b9eb62ba6 Mon Sep 17 00:00:00 2001 From: piernov Date: Sun, 24 Apr 2016 22:28:22 +0200 Subject: Add JS GUI helpers --- js/gui.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 js/gui.js diff --git a/js/gui.js b/js/gui.js new file mode 100644 index 0000000..bdf1710 --- /dev/null +++ b/js/gui.js @@ -0,0 +1,42 @@ +var MESSAGE_TIMEOUT = 4000; + +function changeTab() { + var hashtype = window.location.hash.substr(1,3); + if(hashtype != "tab") return; + var id = window.location.hash.substr(4); + var tabs = document.querySelectorAll("#tabs-panel > ul > li"); + for(var i=0; i < tabs.length; i++) { + if(i == id-1) + tabs[i].className = "active"; + else + tabs[i].className = ""; + } + +} + +function showMessage(type, msg) { + var msg_box = document.getElementById(type+"-box"); + msg_box.style.display = "initial"; + var msg_list = msg_box.firstElementChild.firstElementChild.firstElementChild; + msg_list.innerHTML = "
  • " + msg + "
  • \n" + msg_list.innerHTML; + + window.setTimeout(hideMessage.bind(null, type), MESSAGE_TIMEOUT); +} + +function hideMessage(type) { + var msg_box = document.getElementById(type+"-box"); + var msg_list = msg_box.firstElementChild.firstElementChild.firstElementChild; + var item = msg_list.lastElementChild; + msg_list.removeChild(item); + + if(msg_list.children.length <= 0) + msg_box.style.display = "none"; +} + +function showError(msg) { + showMessage("error", msg); +} + +function showInfo(msg) { + showMessage("info", msg); +} -- cgit v1.2.3-70-g09d2