reduce page switch overhead

This commit is contained in:
Azareal 2020-04-04 12:51:31 +10:00
parent 943ab18761
commit 3114c5afdc
2 changed files with 26 additions and 12 deletions

View File

@ -156,6 +156,13 @@ function loadAlerts(menuAlerts,eTc=false) {
for(var i in data.msgs) addAlert(data.msgs[i]); for(var i in data.msgs) addAlert(data.msgs[i]);
alertCount = data.count; alertCount = data.count;
updateAlertList(menuAlerts); 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; lastTc = data.tc;
}, },
@ -353,13 +360,21 @@ function getExt(name) {
notifyOnScriptW("tmpl_alert", e => { notifyOnScriptW("tmpl_alert", e => {
if(e!=undefined) console.log("failed alert? why?",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", () => { addInitHook("after_phrases", () => {
// TODO: The load part of loadAlerts could be done asynchronously while the update of the DOM could be deferred // TODO: The load part of loadAlerts could be done asynchronously while the update of the DOM could be deferred
$(document).ready(() => { $(document).ready(() => {
alertsInitted = true; alertsInitted = true;
let alertMenuList = document.getElementsByClassName("menu_alerts"); let al = document.getElementsByClassName("menu_alerts");
for(var i=0; i<alertMenuList.length; i++) loadAlerts(alertMenuList[i]); let sAlertList = localStorage.getItem("alertList");
let sAlertMapping = localStorage.getItem("alertMapping");
let sAlertCount = localStorage.getItem("alertCount");
if(sAlertList!=""&&sAlertMapping!=""&&sAlertCount!="") {
alertList = JSON.parse(sAlertList)
alertMapping = JSON.parse(sAlertMapping)
alertCount = parseInt(sAlertCount)
for(var i=0; i<al.length; i++) loadAlerts(al[i],true);
} else for(var i=0; i<al.length; i++) loadAlerts(al[i]);
if(window["WebSocket"]) runWebSockets(); if(window["WebSocket"]) runWebSockets();
}); });
}); });

View File

@ -1,5 +1,4 @@
"use strict"; "use strict";
$(document).ready(() => { $(document).ready(() => {
let clickHandle = function(ev){ let clickHandle = function(ev){
console.log("in clickHandle") console.log("in clickHandle")
@ -41,9 +40,9 @@ $(document).ready(() => {
let widgetList = this.closest(".panel_widgets"); let widgetList = this.closest(".panel_widgets");
let widgetNew = this.closest(".widget_new"); let widgetNew = this.closest(".widget_new");
let widgetTmpl = document.getElementById("widgetTmpl").querySelector(".widget_item"); let widgetTmpl = document.getElementById("widgetTmpl").querySelector(".widget_item");
let node = widgetTmpl.cloneNode(true); let n = widgetTmpl.cloneNode(true);
node.querySelector(".wside").value = this.getAttribute("data-dock"); n.querySelector(".wside").value = this.getAttribute("data-dock");
widgetList.insertBefore(node,widgetNew); widgetList.insertBefore(n,widgetNew);
$(".widget_item a").unbind("click"); $(".widget_item a").unbind("click");
$(".widget_item a").click(clickHandle); $(".widget_item a").click(clickHandle);
$(".wtype_sel").unbind("change"); $(".wtype_sel").unbind("change");
@ -55,11 +54,11 @@ $(document).ready(() => {
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
let pform = this.closest("form"); let pform = this.closest("form");
let data = new URLSearchParams(); let dat = new URLSearchParams();
for (const pair of new FormData(pform)) data.append(pair[0], pair[1]); for (const pair of new FormData(pform)) dat.append(pair[0], pair[1]);
data.append("s",me.User.S); dat.append("s",me.User.S);
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.open("POST", pform.getAttribute("action")); req.open("POST",pform.getAttribute("action"));
req.send(data); req.send(dat);
}); });
}); });