save bytes

This commit is contained in:
Azareal 2020-03-10 07:41:17 +10:00
parent d586220df2
commit bba83ef727
7 changed files with 53 additions and 71 deletions

View File

@ -6,4 +6,4 @@ addInitHook("end_init", () => {
$("#dash_username button").show();
});
});
})();
})()

View File

@ -1,23 +1,9 @@
'use strict';
var me={};
var phraseBox={};
if(tmplInits===undefined) var tmplInits={};
var tmplPhrases=[]; // [key] array of phrases indexed by order of use
var hooks={ // Shorten this list by binding the hooks just in time?
"pre_iffe":[],
"pre_init":[],
"start_init":[],
"almost_end_init":[],
"end_init":[],
"after_phrases":[],
"after_add_alert":[],
"after_update_alert_list":[],
"open_edit":[],
"close_edit":[],
"edit_item_pre_bind":[],
"analytics_loaded":[],
};
var hooks={};
var ranInitHooks={}
function runHook(name,...args) {
@ -88,16 +74,16 @@ function notifyOnScript(src) {
let ss = src.replace("/s/","");
try {
let ssp = ss.charAt(0).toUpperCase() + ss.slice(1)
console.log("ssp:",ssp)
console.log("ssp",ssp)
if(window[ssp]) {
resolve();
return;
}
} catch(e) {}
console.log("src:",src)
console.log("src",src)
let script = document.querySelectorAll('[src^="'+src+'"]')[0];
console.log("script:",script);
console.log("script",script);
if(script===undefined) {
reject("no script found");
return;
@ -108,7 +94,6 @@ function notifyOnScript(src) {
script.onreadystatechange = null;
resolve();
}
script.onerror = (e) => {
reject(e);
};
@ -123,9 +108,9 @@ function notifyOnScriptW(name,complete,success) {
console.log("Loaded " +name+".js");
complete();
if(success!==undefined) success();
}).catch((e) => {
}).catch(e => {
console.log("Unable to get script name '"+name+"'");
console.log("e: ", e);
console.log("e", e);
console.trace();
complete(e);
});
@ -147,29 +132,26 @@ function loadScript(name,callback,fail) {
if(fname!=name) {
asyncGetScript(iurl)
.then(callback)
.catch((e) => {
.catch(e => {
console.log("Unable to get script '"+iurl+"'");
console.log("e:", e);
console.log("e", e);
console.trace();
});
}
console.log("e:", e);
console.log("e", e);
console.trace();
fail(e);
});
}
/*
function loadTmpl(name,callback) {
/*function loadTmpl(name,callback) {
let url = "/s/"+name
let worker = new Worker(url);
}
*/
}*/
function DoNothingButPassBack(it) {
return it;
}
function RelativeTime(date) {
return date;
}
@ -186,27 +168,27 @@ function initPhrases(loggedIn, panel = false) {
function fetchPhrases(plist) {
fetch("/api/phrases/?q="+plist, {cache: "no-cache"})
.then((resp) => resp.json())
.then((data) => {
.then(resp => resp.json())
.then(data => {
console.log("loaded phrase endpoint data");
console.log("data:",data);
Object.keys(tmplInits).forEach((key) => {
console.log("data",data);
Object.keys(tmplInits).forEach(key => {
let phrases = [];
let tmplInit = tmplInits[key];
for(let phraseName of tmplInit) phrases.push(data[phraseName]);
console.log("Adding phrases");
console.log("key:",key);
console.log("phrases:",phrases);
console.log("key",key);
console.log("phrases",phrases);
tmplPhrases[key] = phrases;
});
let prefixes = {};
Object.keys(data).forEach((key) => {
Object.keys(data).forEach(key => {
let prefix = key.split(".")[0];
if(prefixes[prefix]===undefined) prefixes[prefix] = {};
prefixes[prefix][key] = data[key];
});
Object.keys(prefixes).forEach((prefix) => {
Object.keys(prefixes).forEach(prefix => {
console.log("adding phrase prefix '"+prefix+"' to box");
phraseBox[prefix] = prefixes[prefix];
});
@ -246,7 +228,7 @@ function fetchPhrases(plist) {
.then(resp => resp.json())
.then(data => {
console.log("loaded me endpoint data");
console.log("data:",data);
console.log("data",data);
me = data;
runInitHook("pre_init");
});

View File

@ -78,7 +78,7 @@ var imageExts = ["png", "jpg", "jpe","jpeg","jif","jfi","jfif", "svg", "bmp", "g
let req = new XMLHttpRequest();
req.addEventListener("load", () => {
let data = JSON.parse(req.responseText);
//console.log("rdata:",data);
//console.log("rdata",data);
let fileItem = document.createElement("div");
let ext = getExt(filename);
// TODO: Push ImageFileExts to the client from the server in some sort of gen.js?
@ -217,8 +217,8 @@ var imageExts = ["png", "jpg", "jpe","jpeg","jif","jfi","jfif", "svg", "bmp", "g
bindAttachManager();
});
$(".moderate_link").click((event) => {
event.preventDefault();
$(".moderate_link").click(ev => {
ev.preventDefault();
$(".pre_opt").removeClass("auto_hide");
$(".moderate_link").addClass("moderate_open");
$(".topic_row").each(function(){

View File

@ -1,6 +1,12 @@
"use strict";
(() => {
function newElement(etype, eclass) {
let element = document.createElement(etype);
element.className = eclass;
return element;
}
function moveAlerts() {
// Move the alerts under the first header
let colSel = $(".colstack_right .colstack_head:first");
@ -29,7 +35,7 @@
$('#input_content').trumbowyg('html', currentContent);
}
$(".topic_name_row").click(function(){
$(".topic_name_row").click(() => {
$(".topic_create_form").addClass("selectedInput");
});
@ -99,11 +105,11 @@
// Fill in the placeholder grid nodes
let rowCount = 4;
console.log("rowCount: ",rowCount);
console.log("gridElementCount: ",gridElementCount);
console.log("rowCount",rowCount);
console.log("gridElementCount",gridElementCount);
if(gridElementCount%rowCount != 0) {
let fillerNodes = (rowCount - (gridElementCount%rowCount));
console.log("fillerNodes: ",fillerNodes);
console.log("fillerNodes",fillerNodes);
for(let i = 0; i < fillerNodes;i++ ) {
console.log("added a gridFiller");
buttonGrid.appendChild(newElement("div","gridFiller"));
@ -118,10 +124,4 @@
});
addInitHook("after_notice", moveAlerts);
})();
function newElement(etype, eclass) {
let element = document.createElement(etype);
element.className = eclass;
return element;
}
})()

View File

@ -12,4 +12,4 @@ addInitHook("end_init", () => {
});
});
});
})();
})()

View File

@ -12,4 +12,4 @@ addInitHook("end_init", () => {
});
});
});
})();
})()