From 3114c5afdc18b85cfb0c48cbc94e202fb83f9c24 Mon Sep 17 00:00:00 2001 From: Azareal Date: Sat, 4 Apr 2020 12:51:31 +1000 Subject: [PATCH] reduce page switch overhead --- public/global.js | 21 ++++++++++++++++++--- public/widgets.js | 17 ++++++++--------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/public/global.js b/public/global.js index 6d4c113d..c066f06d 100644 --- a/public/global.js +++ b/public/global.js @@ -156,6 +156,13 @@ function loadAlerts(menuAlerts,eTc=false) { for(var i in data.msgs) addAlert(data.msgs[i]); alertCount = data.count; updateAlertList(menuAlerts); + try { + localStorage.setItem("alertList",JSON.stringify(alertList)); + localStorage.setItem("alertMapping",JSON.stringify(alertMapping)); + localStorage.setItem("alertCount",alertCount); + } catch(e) { + localStorage.clear(); + } //} lastTc = data.tc; }, @@ -353,13 +360,21 @@ function getExt(name) { notifyOnScriptW("tmpl_alert", e => { if(e!=undefined) console.log("failed alert? why?",e) }, () => { - if(!Tmpl_alert) throw("template function not found"); + if(!Tmpl_alert) throw("tmpl func not found"); addInitHook("after_phrases", () => { // TODO: The load part of loadAlerts could be done asynchronously while the update of the DOM could be deferred $(document).ready(() => { alertsInitted = true; - let alertMenuList = document.getElementsByClassName("menu_alerts"); - for(var i=0; i { let clickHandle = function(ev){ console.log("in clickHandle") @@ -41,9 +40,9 @@ $(document).ready(() => { let widgetList = this.closest(".panel_widgets"); let widgetNew = this.closest(".widget_new"); let widgetTmpl = document.getElementById("widgetTmpl").querySelector(".widget_item"); - let node = widgetTmpl.cloneNode(true); - node.querySelector(".wside").value = this.getAttribute("data-dock"); - widgetList.insertBefore(node,widgetNew); + let n = widgetTmpl.cloneNode(true); + n.querySelector(".wside").value = this.getAttribute("data-dock"); + widgetList.insertBefore(n,widgetNew); $(".widget_item a").unbind("click"); $(".widget_item a").click(clickHandle); $(".wtype_sel").unbind("change"); @@ -55,11 +54,11 @@ $(document).ready(() => { ev.preventDefault(); ev.stopPropagation(); let pform = this.closest("form"); - let data = new URLSearchParams(); - for (const pair of new FormData(pform)) data.append(pair[0], pair[1]); - data.append("s",me.User.S); + let dat = new URLSearchParams(); + for (const pair of new FormData(pform)) dat.append(pair[0], pair[1]); + dat.append("s",me.User.S); var req = new XMLHttpRequest(); - req.open("POST", pform.getAttribute("action")); - req.send(data); + req.open("POST",pform.getAttribute("action")); + req.send(dat); }); }); \ No newline at end of file