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(); $("#dash_username button").show();
}); });
}); });
})(); })()

View File

@ -1,23 +1,9 @@
'use strict'; 'use strict';
var me={}; var me={};
var phraseBox={}; var phraseBox={};
if(tmplInits===undefined) var tmplInits={}; if(tmplInits===undefined) var tmplInits={};
var tmplPhrases=[]; // [key] array of phrases indexed by order of use var tmplPhrases=[]; // [key] array of phrases indexed by order of use
var hooks={ // Shorten this list by binding the hooks just in time? var hooks={};
"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 ranInitHooks={} var ranInitHooks={}
function runHook(name,...args) { function runHook(name,...args) {
@ -88,16 +74,16 @@ function notifyOnScript(src) {
let ss = src.replace("/s/",""); let ss = src.replace("/s/","");
try { try {
let ssp = ss.charAt(0).toUpperCase() + ss.slice(1) let ssp = ss.charAt(0).toUpperCase() + ss.slice(1)
console.log("ssp:",ssp) console.log("ssp",ssp)
if(window[ssp]) { if(window[ssp]) {
resolve(); resolve();
return; return;
} }
} catch(e) {} } catch(e) {}
console.log("src:",src) console.log("src",src)
let script = document.querySelectorAll('[src^="'+src+'"]')[0]; let script = document.querySelectorAll('[src^="'+src+'"]')[0];
console.log("script:",script); console.log("script",script);
if(script===undefined) { if(script===undefined) {
reject("no script found"); reject("no script found");
return; return;
@ -108,7 +94,6 @@ function notifyOnScript(src) {
script.onreadystatechange = null; script.onreadystatechange = null;
resolve(); resolve();
} }
script.onerror = (e) => { script.onerror = (e) => {
reject(e); reject(e);
}; };
@ -123,9 +108,9 @@ function notifyOnScriptW(name,complete,success) {
console.log("Loaded " +name+".js"); console.log("Loaded " +name+".js");
complete(); complete();
if(success!==undefined) success(); if(success!==undefined) success();
}).catch((e) => { }).catch(e => {
console.log("Unable to get script name '"+name+"'"); console.log("Unable to get script name '"+name+"'");
console.log("e: ", e); console.log("e", e);
console.trace(); console.trace();
complete(e); complete(e);
}); });
@ -147,29 +132,26 @@ function loadScript(name,callback,fail) {
if(fname!=name) { if(fname!=name) {
asyncGetScript(iurl) asyncGetScript(iurl)
.then(callback) .then(callback)
.catch((e) => { .catch(e => {
console.log("Unable to get script '"+iurl+"'"); console.log("Unable to get script '"+iurl+"'");
console.log("e:", e); console.log("e", e);
console.trace(); console.trace();
}); });
} }
console.log("e:", e); console.log("e", e);
console.trace(); console.trace();
fail(e); fail(e);
}); });
} }
/* /*function loadTmpl(name,callback) {
function loadTmpl(name,callback) {
let url = "/s/"+name let url = "/s/"+name
let worker = new Worker(url); let worker = new Worker(url);
} }*/
*/
function DoNothingButPassBack(it) { function DoNothingButPassBack(it) {
return it; return it;
} }
function RelativeTime(date) { function RelativeTime(date) {
return date; return date;
} }
@ -186,27 +168,27 @@ function initPhrases(loggedIn, panel = false) {
function fetchPhrases(plist) { function fetchPhrases(plist) {
fetch("/api/phrases/?q="+plist, {cache: "no-cache"}) fetch("/api/phrases/?q="+plist, {cache: "no-cache"})
.then((resp) => resp.json()) .then(resp => resp.json())
.then((data) => { .then(data => {
console.log("loaded phrase endpoint data"); console.log("loaded phrase endpoint data");
console.log("data:",data); console.log("data",data);
Object.keys(tmplInits).forEach((key) => { Object.keys(tmplInits).forEach(key => {
let phrases = []; let phrases = [];
let tmplInit = tmplInits[key]; let tmplInit = tmplInits[key];
for(let phraseName of tmplInit) phrases.push(data[phraseName]); for(let phraseName of tmplInit) phrases.push(data[phraseName]);
console.log("Adding phrases"); console.log("Adding phrases");
console.log("key:",key); console.log("key",key);
console.log("phrases:",phrases); console.log("phrases",phrases);
tmplPhrases[key] = phrases; tmplPhrases[key] = phrases;
}); });
let prefixes = {}; let prefixes = {};
Object.keys(data).forEach((key) => { Object.keys(data).forEach(key => {
let prefix = key.split(".")[0]; let prefix = key.split(".")[0];
if(prefixes[prefix]===undefined) prefixes[prefix] = {}; if(prefixes[prefix]===undefined) prefixes[prefix] = {};
prefixes[prefix][key] = data[key]; prefixes[prefix][key] = data[key];
}); });
Object.keys(prefixes).forEach((prefix) => { Object.keys(prefixes).forEach(prefix => {
console.log("adding phrase prefix '"+prefix+"' to box"); console.log("adding phrase prefix '"+prefix+"' to box");
phraseBox[prefix] = prefixes[prefix]; phraseBox[prefix] = prefixes[prefix];
}); });
@ -246,7 +228,7 @@ function fetchPhrases(plist) {
.then(resp => resp.json()) .then(resp => resp.json())
.then(data => { .then(data => {
console.log("loaded me endpoint data"); console.log("loaded me endpoint data");
console.log("data:",data); console.log("data",data);
me = data; me = data;
runInitHook("pre_init"); 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(); let req = new XMLHttpRequest();
req.addEventListener("load", () => { req.addEventListener("load", () => {
let data = JSON.parse(req.responseText); let data = JSON.parse(req.responseText);
//console.log("rdata:",data); //console.log("rdata",data);
let fileItem = document.createElement("div"); let fileItem = document.createElement("div");
let ext = getExt(filename); let ext = getExt(filename);
// TODO: Push ImageFileExts to the client from the server in some sort of gen.js? // 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(); bindAttachManager();
}); });
$(".moderate_link").click((event) => { $(".moderate_link").click(ev => {
event.preventDefault(); ev.preventDefault();
$(".pre_opt").removeClass("auto_hide"); $(".pre_opt").removeClass("auto_hide");
$(".moderate_link").addClass("moderate_open"); $(".moderate_link").addClass("moderate_open");
$(".topic_row").each(function(){ $(".topic_row").each(function(){

View File

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