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]);
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<alertMenuList.length; i++) loadAlerts(alertMenuList[i]);
let al = document.getElementsByClassName("menu_alerts");
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();
});
});

View File

@ -1,5 +1,4 @@
"use strict";
$(document).ready(() => {
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);
});
});