From e814e85daac140bffa8595e47644b1f299024d5f Mon Sep 17 00:00:00 2001 From: Azareal Date: Thu, 23 Jul 2020 14:02:16 +1000 Subject: [PATCH] fix alerts erroring when you don't have any reset mod floater status on page bind alias console.log with log reduce boilerplate --- public/analytics.js | 20 ++-- public/global.js | 140 ++++++++++++++-------------- public/init.js | 120 +++++++++++------------- public/member.js | 35 +++---- public/panel_forums.js | 14 +-- public/panel_menu_items.js | 12 +-- public/profile_member.js | 2 +- public/register.js | 6 +- public/widgets.js | 6 +- templates/header.html | 2 +- templates/panel_forums.html | 2 +- themes/cosora/public/misc.js | 10 +- themes/nox/public/misc.js | 24 ++--- themes/shadow/public/misc.js | 6 +- themes/tempra_simple/public/misc.js | 6 +- 15 files changed, 203 insertions(+), 202 deletions(-) diff --git a/public/analytics.js b/public/analytics.js index 4c21eb03..a3c0e12c 100644 --- a/public/analytics.js +++ b/public/analytics.js @@ -8,7 +8,7 @@ function memStuff(window, document, Chartist) { if(!chart instanceof Chartist.Line) return; chart.on('created', function() { - console.log("running created") + log("running created") const vbits = document.getElementsByClassName("ct-vertical"); if(vbits==null) return; @@ -16,7 +16,7 @@ function memStuff(window, document, Chartist) { for(let i = 0; i < vbits.length; i++) { tbits[i] = vbits[i].innerHTML; } - console.log("tbits",tbits); + log("tbits",tbits); const calc = (places) => { if(places==3) return; @@ -47,7 +47,7 @@ function perfStuff(window, document, Chartist) { if(!chart instanceof Chartist.Line) return; chart.on('created', function() { - console.log("running created") + log("running created") const vbits = document.getElementsByClassName("ct-vertical"); if(vbits==null) return; @@ -55,7 +55,7 @@ function perfStuff(window, document, Chartist) { for(let i = 0; i < vbits.length; i++) { tbits[i] = vbits[i].innerHTML; } - console.log("tbits:",tbits); + log("tbits:",tbits); const calc = (places) => { if(places==3) return; @@ -122,8 +122,8 @@ function convertPerfUnit(quan, places = 0) { // TODO: Fully localise this // TODO: Load rawLabels and seriesData dynamically rather than potentially fiddling with nonces for the CSP? function buildStatsChart(rawLabels, seriesData, timeRange, legendNames, typ=0) { - console.log("buildStatsChart"); - console.log("seriesData",seriesData); + log("buildStatsChart"); + log("seriesData",seriesData); let labels = []; let aphrases = phraseBox["analytics"]; if(timeRange=="one-year") { @@ -156,19 +156,19 @@ function buildStatsChart(rawLabels, seriesData, timeRange, legendNames, typ=0) { continue; } let date = new Date(rawLabels[i]*1000); - console.log("date", date); + log("date",date); let minutes = "0" + date.getMinutes(); let label = date.getHours() + ":" + minutes.substr(-2); - console.log("label", label); + log("label",label); labels.push(label); } } else { for(const i in rawLabels) { let date = new Date(rawLabels[i]*1000); - console.log("date", date); + log("date",date); let minutes = "0" + date.getMinutes(); let label = date.getHours() + ":" + minutes.substr(-2); - console.log("label", label); + log("label",label); labels.push(label); } } diff --git a/public/global.js b/public/global.js index bab9ae4d..cab64a00 100644 --- a/public/global.js +++ b/public/global.js @@ -25,11 +25,11 @@ function pushNotice(msg) { // TODO: Write a friendlier error handler which uses a .notice or something, we could have a specialised one for alerts function ajaxError(xhr,status,e) { - console.log("The AJAX request failed"); - console.log("xhr",xhr); - console.log("status",status); - console.log("e",e); - if(status=="parsererror") console.log("The server didn't respond with a valid JSON response"); + log("The AJAX request failed"); + log("xhr",xhr); + log("status",status); + log("e",e); + if(status=="parsererror") log("The server didn't respond with a valid JSON response"); console.trace(); } @@ -40,7 +40,7 @@ function postLink(ev) { } function bindToAlerts() { - console.log("bindToAlerts"); + log("bindToAlerts"); $(".alertItem.withAvatar a").unbind("click"); $(".alertItem.withAvatar a").click(function(ev) { ev.stopPropagation(); @@ -93,6 +93,10 @@ function addAlert(msg,notice=false) { } function updateAlertList(menuAlerts) { + log("enter updateAlertList"); + log("alertList:",alertList); + log("alertMapping:",alertMapping); + log("alertCount:",alertCount); let alertListNode = menuAlerts.getElementsByClassName("alertList")[0]; let alertCounterNode = menuAlerts.getElementsByClassName("alert_counter")[0]; alertCounterNode.textContent = "0"; @@ -119,7 +123,7 @@ function updateAlertList(menuAlerts) { } bindToAlerts(); - console.log("alertCount",alertCount) + log("alertCount",alertCount) runInitHook("after_update_alert_list",alertCount); } @@ -152,7 +156,7 @@ function loadAlerts(menuAlerts,eTc=false) { if(eTc && lastTc!=0) { for(var i in data.msgs) wsAlertEvent(data.msgs[i]); } else {*/ - console.log("data",data); + log("data",data); for(var i in data.msgs) addAlert(data.msgs[i]); alertCount = data.count; updateAlertList(menuAlerts); @@ -172,10 +176,10 @@ function loadAlerts(menuAlerts,eTc=false) { let dat = JSON.parse(magic.responseText); if("errmsg" in dat) errtxt = dat.errmsg; } catch(e) { - console.log(magic.responseText); - console.log(e); + log(magic.responseText); + log(e); } - console.log("er",er); + log("er",er); setAlertError(menuAlerts,errtxt); } }); @@ -201,7 +205,7 @@ function SplitN(data,ch,n) { } function wsAlertEvent(dat) { - console.log("wsAlertEvent",dat) + log("wsAlertEvent",dat) addAlert(dat,true); alertCount++; @@ -222,12 +226,12 @@ function runWebSockets(resume=false) { conn = new WebSocket("ws"+s+"://" + document.location.host + "/ws/"); conn.onerror = e => { - console.log(e); + log(e); } // TODO: Sync alerts, topic list, etc. conn.onopen = () => { - console.log("The WebSockets connection was opened"); + log("The WebSockets connection was opened"); if(resume) conn.send("resume " + document.location.pathname + " " + Math.round((new Date()).getTime() / 1000) + '\r'); else conn.send("page " + document.location.pathname + '\r'); // TODO: Don't ask again, if it's denied. We could have a setting in the UCP which automatically requests this when someone flips desktop notifications on @@ -236,7 +240,7 @@ function runWebSockets(resume=false) { conn.onclose = () => { conn = false; - console.log("The WebSockets connection was closed"); + log("The WebSockets connection was closed"); let backoff = 0.8; if(wsBackoff < 0) wsBackoff = 0; else if(wsBackoff > 12) backoff = 11; @@ -260,12 +264,12 @@ function runWebSockets(resume=false) { conn.onmessage = (event) => { if(!noAlerts && event.data[0] == "{") { - console.log("json message"); + log("json message"); let data = ""; try { data = JSON.parse(event.data); } catch(e) { - console.log(e); + log(e); return; } @@ -295,13 +299,13 @@ function runWebSockets(resume=false) { }); } } else if("Topics" in data) { - console.log("topic in data"); - console.log("data",data); + log("topic in data"); + log("data",data); // TODO: Handle desyncs more gracefully? // TODO: Send less unneccessary data? let topic = data.Topics[0]; if(topic===undefined){ - console.log("empty topic list"); + log("empty topic list"); return; } if("mod" in data) { @@ -323,7 +327,7 @@ function runWebSockets(resume=false) { let node = $(renTopic); node.addClass("new_item hide_ajax_topic"); - console.log("Prepending to topic list"); + log("Prepending to topic list"); $(".topic_list").prepend(node); moreTopicCount++; @@ -333,17 +337,17 @@ function runWebSockets(resume=false) { block.classList.remove("more_topic_block_initial"); block.classList.add("more_topic_block_active"); - console.log("phraseBox",phraseBox); + log("phraseBox",phraseBox); let msgBox = block.getElementsByClassName("more_topics")[0]; msgBox.innerText = phraseBox["topic_list"]["topic_list.changed_topics"].replace("%d",moreTopicCount); } - } else console.log("unknown message",data); + } else log("unknown message",data); } let messages = event.data.split('\r'); for(var i=0; i { addInitHook("pre_init", () => { runInitHook("pre_global"); - console.log("before notify on alert") + log("before notify on alert") // We can only get away with this because template_alert has no phrases, otherwise it too would have to be part of the "dance", I miss Go concurrency :( if(!noAlerts) { notifyOnScriptW("tmpl_alert", e => { - if(e!=undefined) console.log("failed alert? why?",e) + if(e!=undefined) log("failed alert? why?",e) }, () => { if(!Tmpl_alert) throw("tmpl func not found"); addInitHook("after_phrases", () => { @@ -385,17 +389,17 @@ function getExt(name) { let sAlertMapping = localStorage.getItem("alertMapping"); let sAlertCount = localStorage.getItem("alertCount"); if(sAlertList!=null && sAlertList!="" && - sAlertMapping!=null && sAlertMapping!="" &&sAlertCount!=null && sAlertCount!="" + sAlertMapping!=null && sAlertMapping!="" &&sAlertCount!=null && sAlertCount!="" && sAlertCount!="0" ) { - console.log("sAlertList",sAlertList) - console.log("sAlertMapping",sAlertMapping) - console.log("sAlertCount",sAlertCount) + log("sAlertList",sAlertList) + log("sAlertMapping",sAlertMapping) + log("sAlertCount",sAlertCount) alertList = JSON.parse(sAlertList) alertMapping = JSON.parse(sAlertMapping) alertCount = parseInt(sAlertCount) - console.log("alertList",alertList) - console.log("alertMapping",alertMapping) - console.log("alertCount",alertCount) + log("alertList",alertList) + log("alertMapping",alertMapping) + log("alertCount",alertCount) for(var i=0; i { if(!"Topics" in dat) throw("no Topics in data"); let topics = dat["Topics"]; - console.log("ajax navigated to different page"); + log("ajax navigated to different page"); // TODO: Fix the data race where the function hasn't been loaded yet let out = ""; @@ -565,7 +569,7 @@ function mainInit(){ rebuildPaginator(dat.LastPage); rebindPaginator(); }).catch(e => { - console.log("Unable to get script '"+url+q+"&js=1"+"'",e); + log("Unable to get script '"+url+q+"&js=1"+"'",e); console.trace(); }); }); @@ -585,10 +589,10 @@ function mainInit(){ if(!resp.ok) throw(url+"&js=1 failed to load"); return resp.json(); }).then(dat => { - console.log("data",dat); + log("data",dat); if(!"Topics" in dat) throw("no Topics in data"); let topics = dat["Topics"]; - console.log("ajax navigated to "+that.innerText); + log("ajax navigated to "+that.innerText); // TODO: Fix the data race where the function hasn't been loaded yet let out = ""; @@ -610,7 +614,7 @@ function mainInit(){ that.classList.add("filter_selected"); $(".topic_list_title h1").text(that.innerText); }).catch(e => { - console.log("Unable to get script '"+url+"&js=1"+"'",e); + log("Unable to get script '"+url+"&js=1"+"'",e); console.trace(); }); }); @@ -639,7 +643,7 @@ function mainInit(){ }).then(data => { if(!"Topics" in data) throw("no Topics in data"); let topics = data["Topics"]; - console.log("ajax navigated to search page"); + log("ajax navigated to search page"); // TODO: Fix the data race where the function hasn't been loaded yet let out = ""; @@ -655,7 +659,7 @@ function mainInit(){ rebuildPaginator(data.LastPage); rebindPaginator(); }).catch(e => { - console.log("Unable to get script '"+url+q+"&js=1"+"'",e); + log("Unable to get script '"+url+q+"&js=1"+"'",e); console.trace(); }); }); @@ -667,7 +671,7 @@ function mainInit(){ ev.preventDefault(); let bp = $(this).closest('.editable_parent'); let block = bp.find('.editable_block').eq(0); - block.html(""); + block.html(""); $(".submit_edit").click(function(ev) { ev.preventDefault(); @@ -690,7 +694,7 @@ function mainInit(){ $(".edit_fields").click(function(ev) { ev.preventDefault(); if($(this).find("input").length!==0) return; - //console.log("clicked .edit_fields"); + //log("clicked .edit_fields"); var bp = $(this).closest('.editable_parent'); bp.find('.hide_on_edit').addClass("edit_opened"); bp.find('.show_on_edit').addClass("edit_opened"); @@ -713,10 +717,10 @@ function mainInit(){ } out += ""; } - this.innerHTML = ""; + this.innerHTML = ""; } else if(fieldType=="hidden") {} - else this.innerHTML = ""; + else this.innerHTML = ""; }); // Remove any handlers already attached to the submitter @@ -744,8 +748,8 @@ function mainInit(){ }); let href = $(this).closest('a').attr("href"); - //console.log("href",href); - //console.log(outData); + //log("href",href); + //log(outData); $.ajax({ url: href+"?s="+me.User.S, type:"POST", dataType:"json", data: outData, error: ajaxError }); bp.find('.hide_on_edit').removeClass("edit_opened"); bp.find('.show_on_edit').removeClass("edit_opened"); @@ -778,7 +782,7 @@ function mainInit(){ $("input,textarea,select,option").keyup(ev => ev.stopPropagation()) $("#themeSelectorSelect").change(function(){ - console.log("Changing the theme to "+this.options[this.selectedIndex].getAttribute("value")); + log("Changing the theme to "+this.options[this.selectedIndex].getAttribute("value")); $.ajax({ url: this.form.getAttribute("action")+"?s="+me.User.S, type:"POST", @@ -786,10 +790,10 @@ function mainInit(){ data: { "theme": this.options[this.selectedIndex].getAttribute("value"), js: 1 }, error: ajaxError, success: function (dat,status,xhr) { - console.log("Theme successfully switched"); - console.log("dat",dat); - console.log("status",status); - console.log("xhr",xhr); + log("Theme successfully switched"); + log("dat",dat); + log("status",status); + log("xhr",xhr); window.location.reload(); } }); @@ -814,10 +818,10 @@ function mainInit(){ $(".unix_to_24_hour_time").each(function(){ let unixTime = this.innerText; let date = new Date(unixTime*1000); - console.log("date",date); + log("date",date); let mins = "0"+date.getMinutes(); let formattedTime = date.getHours()+":"+mins.substr(-2); - console.log("formattedTime",formattedTime); + log("formattedTime",formattedTime); this.innerText = formattedTime; }); @@ -825,10 +829,10 @@ function mainInit(){ // TODO: Localise this let monthList = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; let date = new Date(this.innerText * 1000); - console.log("date",date); + log("date",date); let day = "0"+date.getDate(); let formattedTime = monthList[date.getMonth()]+" "+day.substr(-2)+" "+date.getFullYear(); - console.log("formattedTime",formattedTime); + log("formattedTime",formattedTime); this.innerText = formattedTime; }); @@ -888,9 +892,9 @@ function mainInit(){ let pro; if(stripQ(getExt(res))=="css") pro = asyncGetSheet("/s/"+res) else pro = asyncGetScript("/s/"+res) - pro.then(() => console.log("Loaded "+res)) + pro.then(() => log("Loaded "+res)) .catch(e => { - console.log("Unable to get '"+res+"'",e); + log("Unable to get '"+res+"'",e); console.trace(); }); } @@ -903,7 +907,7 @@ function mainInit(){ let obj = {Title:document.title,Url:base}; history.pushState(obj,obj.Title,obj.Url); }).catch(e => { - console.log("Unable to get script '"+href+""+"'",e); + log("Unable to get script '"+href+""+"'",e); console.trace(); }); } @@ -1066,13 +1070,13 @@ function bindTopic() { ev.stopPropagation(); let src = this.closest(".post_item").getElementsByClassName("edit_source")[0]; let con = document.getElementById("input_content") - console.log("con.value",con.value); + log("con.value",con.value); let item; if(con.value=="") item = "
"+src.innerHTML+"
" else item = "\r\n
"+src.innerHTML+"
"; con.value = con.value+item; - console.log("con.value",con.value); + log("con.value",con.value); // For custom / third party text editors quoteItemCallback(src.innerHTML,item); @@ -1093,13 +1097,13 @@ function bindTopic() { } if(allZero) { $("#poll_results_"+pollID+" .poll_no_results").removeClass("auto_hide"); - console.log("all zero") + log("all zero") return; } $("#poll_results_"+pollID+" .user_content").html("
"); - console.log("rawData",rawData); - console.log("series",data); + log("rawData",rawData); + log("series",data); Chartist.Pie('#poll_results_chart_'+pollID, { series: data, }, { diff --git a/public/init.js b/public/init.js index c7e6e44c..1316285f 100644 --- a/public/init.js +++ b/public/init.js @@ -5,39 +5,38 @@ if(tmplInits===undefined) var tmplInits={}; var tmplPhrases=[]; // [key] array of phrases indexed by order of use var hooks={}; var ranInitHooks={} +var log = console.log; function runHook(name,...args) { if(!(name in hooks)) { - console.log("Couldn't find hook '"+name+"'"); + log("Couldn't find hook "+name); return; } - console.log("Running hook '"+name+"'"); + log("Running hook "+name); let hook = hooks[name]; - let ret; - for (const index in hook) ret = hook[index](...args); - return ret; + let o; + for (const index in hook) o = hook[index](...args); + return o; } - function addHook(name,h) { + log("Add hook "+name); if(hooks[name]===undefined) hooks[name]=[]; hooks[name].push(h); } // InitHooks are slightly special, as if they are run, then any adds after the initial run will run immediately, this is to deal with the async nature of script loads function runInitHook(name,...args) { - let ret = runHook(name,...args); - ranInitHooks[name] = true; - return ret; + ranInitHooks[name]=true; + return runHook(name,...args); } - function addInitHook(name,h) { - addHook(name, h); + addHook(name,h); if(name in ranInitHooks) h(); } // Temporary hack for templates -function len(it) {return it.length;} +function len(d) {return d.length} function asyncGetScript(src) { return new Promise((resolve,reject) => { @@ -45,16 +44,16 @@ function asyncGetScript(src) { script.async = true; const onloadHandler = (e,isAbort) => { - if (isAbort || !script.readyState || /loaded|complete/.test(script.readyState)) { - script.onload = null; - script.onreadystatechange = null; - script = undefined; + if (isAbort||!script.readyState||/loaded|complete/.test(script.readyState)) { + script.onload=null; + script.onreadystatechange=null; + script=undefined; isAbort ? reject(e) : resolve(); } } - script.onerror = (e) => { + script.onerror = e => { reject(e); }; script.onload = onloadHandler; @@ -72,27 +71,27 @@ function notifyOnScript(src) { let ss = src.replace("/s/",""); try { let ssp = ss.charAt(0).toUpperCase() + ss.slice(1) - console.log("ssp",ssp) + log("ssp",ssp) if(window[ssp]) { resolve(); return; } } catch(e) {} - console.log("src",src) - let script = document.querySelectorAll('[src^="'+src+'"]')[0]; - console.log("script",script); + log("src",src) + let script = document.querySelectorAll(`[src^="${src}"]`)[0]; + log("script",script); if(script===undefined) { reject("no script found"); return; } - const onloadHandler = (e) => { - script.onload = null; - script.onreadystatechange = null; + const onloadHandler = e => { + script.onload=null; + script.onreadystatechange=null; resolve(); } - script.onerror = (e) => { + script.onerror = e => { reject(e); }; script.onload = onloadHandler; @@ -103,38 +102,35 @@ function notifyOnScript(src) { function notifyOnScriptW(name,complete,success) { notifyOnScript(name) .then(() => { - console.log("Loaded "+name+".js"); + log(`Loaded ${name}.js`); complete(); if(success!==undefined) success(); }).catch(e => { - console.log("Unable to get '"+name+"'",e); + log("Unable to get "+name,e); console.trace(); complete(e); }); } // TODO: Send data at load time so we don't have to rely on a fallback template here -function loadScript(name,callback,fail) { +function loadScript(name,h,fail) { let fname = name; let value = "; "+document.cookie; let parts = value.split("; current_theme="); if(parts.length==2) fname += "_"+parts.pop().split(";").shift(); - let url = "/s/"+fname+".js" - let iurl = "/s/"+name+".js" + let url = `/s/${fname}.js` + let iurl = `/s/${name}.js` asyncGetScript(url) - .then(callback) - .catch(e => { - console.log("Unable to get '"+url+"'"); + .then(h).catch(e => { + log("Unable to get "+url,e); if(fname!=name) { asyncGetScript(iurl) - .then(callback) - .catch(e => { - console.log("Unable to get '"+iurl+"'",e); + .then(h).catch(e => { + log("Unable to get "+iurl,e); console.trace(); }); } - console.log("e",e); console.trace(); fail(e); }); @@ -143,8 +139,8 @@ function loadScript(name,callback,fail) { function RelativeTime(date) {return date} function initPhrases(member,acp=false) { - console.log("initPhrases") - console.log("tmlInits",tmplInits) + log("initPhrases") + log("tmlInits",tmplInits) let e = ""; if(member && !acp) e=",status,topic_list,topic"; else if(acp) e=",analytics,panel"; // TODO: Request phrases for just one section of the acp? @@ -154,28 +150,25 @@ function initPhrases(member,acp=false) { function fetchPhrases(plist) { fetch("/api/phrases/?q="+plist,{cache:"no-cache"}) - .then(resp => resp.json()) - .then(data => { - console.log("loaded phrase endpoint data"); - console.log("data",data); + .then(r => r.json()) + .then(d => { + log("loaded phrase endpoint data",d); 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); + for(let phraseName of tmplInit) phrases.push(d[phraseName]); + log("Adding phrases for "+key,phrases); tmplPhrases[key] = phrases; }); - let prefixes = {}; - Object.keys(data).forEach(key => { + let prefixes={}; + Object.keys(d).forEach(key => { let prefix = key.split(".")[0]; - if(prefixes[prefix]===undefined) prefixes[prefix] = {}; - prefixes[prefix][key] = data[key]; + if(prefixes[prefix]===undefined) prefixes[prefix]={}; + prefixes[prefix][key] = d[key]; }); Object.keys(prefixes).forEach(prefix => { - console.log("adding phrase prefix '"+prefix+"' to box"); + log(`adding phrase prefix ${prefix} to box`); phraseBox[prefix] = prefixes[prefix]; }); @@ -190,31 +183,32 @@ function fetchPhrases(plist) { let toLoad = 1; // TODO: Shunt this into member if there aren't any search and filter widgets? - let q = (f) => { + let q = f => { toLoad--; if(toLoad===0) initPhrases(member,acp); if(f) throw("tmpl func not found"); }; + let l = (n,h) => notifyOnScriptW("tmpl_"+n,h); if(!acp) { toLoad += 2; if(member) { toLoad += 3; - notifyOnScriptW("tmpl_topic_c_edit_post", () => q(!Tmpl_topic_c_edit_post)); - notifyOnScriptW("tmpl_topic_c_attach_item", () => q(!Tmpl_topic_c_attach_item)); - notifyOnScriptW("tmpl_topic_c_poll_input", () => q(!Tmpl_topic_c_poll_input)); + l("topic_c_edit_post", () => q(!Tmpl_topic_c_edit_post)); + l("topic_c_attach_item", () => q(!Tmpl_topic_c_attach_item)); + l("topic_c_poll_input", () => q(!Tmpl_topic_c_poll_input)); } - notifyOnScriptW("tmpl_topics_topic", () => q(!Tmpl_topics_topic)); - notifyOnScriptW("tmpl_paginator", () => q(!Tmpl_paginator)); + l("topics_topic", () => q(!Tmpl_topics_topic)); + l("paginator", () => q(!Tmpl_paginator)); } - notifyOnScriptW("tmpl_notice", () => q(!Tmpl_notice)); + l("notice", () => q(!Tmpl_notice)); if(member) { fetch("/api/me/") - .then(resp => resp.json()) - .then(data => { - console.log("me data",data); - me=data; + .then(r => r.json()) + .then(d => { + log("me",d); + me=d; runInitHook("pre_init"); }); } else { diff --git a/public/member.js b/public/member.js index 5aca6108..cc58368a 100644 --- a/public/member.js +++ b/public/member.js @@ -20,7 +20,7 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif"," let totalSize = 0; for(let i=0; i me.Site.MaxRequestSize) throw("You can't upload this much at once, max: "+me.Site.MaxRequestSize); @@ -59,7 +59,7 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif"," try { uploadFileHandler(this.files, 5, () => {}, (e,hash,fname) => { - console.log("hash",hash); + log("hash",hash); let formData = new FormData(); formData.append("s",me.User.S); for(let i=0; i { let data = JSON.parse(req.responseText); - //console.log("rdata",data); + //log("rdata",data); let fileItem = document.createElement("div"); let ext = getExt(fname); // TODO: Push ImageFileExts to the client from the server in some sort of gen.js? @@ -92,7 +92,7 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif"," }); } catch(e) { // TODO: Use a notice instead - console.log("e",e); + log("e",e); alert(e); } } @@ -104,7 +104,7 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif"," // TODO: Use client templates here let fileDock = document.getElementById("upload_file_dock"); let fileItem = document.createElement("label"); - console.log("fileItem",fileItem); + log("fileItem",fileItem); let ext = getExt(fname); // TODO: Push ImageFileExts to the client from the server in some sort of gen.js? @@ -116,23 +116,23 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif"," fileDock.appendChild(fileItem); },(e,hash,fname) => { - console.log("hash",hash); + log("hash",hash); let ext = getExt(fname) let con = document.getElementById("input_content") - console.log("con.value",con.value); + log("con.value",con.value); let attachItem; if(con.value=="") attachItem = "//"+window.location.host+"/attachs/"+hash+"."+ext; else attachItem = "\r\n//"+window.location.host+"/attachs/"+hash+"."+ext; con.value = con.value + attachItem; - console.log("con.value",con.value); + log("con.value",con.value); // For custom / third party text editors attachItemCallback(attachItem); }); } catch(e) { // TODO: Use a notice instead - console.log("e",e); + log("e",e); alert(e); } } @@ -191,12 +191,12 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif"," for(let i = 0; i < elems.length; i++) { let pathNode = elems[i].querySelector(".attach_item_path"); - console.log("pathNode",pathNode); + log("pathNode",pathNode); aidList += pathNode.getAttribute("aid")+","; elems[i].remove(); } if(aidList.length > 0) aidList = aidList.slice(0, -1); - console.log("aidList",aidList) + log("aidList",aidList) formData.append("aids",aidList); let ec = 0; @@ -214,9 +214,9 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif"," }); function addPollInput() { - console.log("clicked on pollinputinput"); + log("clicked on pollinputinput"); let dataPollInput = $(this).parent().attr("data-pollinput"); - console.log("dataPollInput",dataPollInput); + log("dataPollInput",dataPollInput); if(dataPollInput==undefined) return; if(dataPollInput!=(pollInputIndex-1)) return; $(".poll_content_row .formitem").append(Tmpl_topic_c_poll_input({ @@ -224,7 +224,7 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif"," Place: phraseBox["topic"]["topic.reply_add_poll_option"].replace("%d",pollInputIndex), })); pollInputIndex++; - console.log("new pollInputIndex",pollInputIndex); + log("new pollInputIndex",pollInputIndex); $(".pollinputinput").off("click"); $(".pollinputinput").click(addPollInput); } @@ -241,8 +241,11 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif"," }); //addInitHook("after_init_bind_page", () => { addHook("end_bind_page", () => { + if(!$(".mod_floater").hasClass("auto_hide")) $(".mod_floater").addClass("auto_hide") $(".moderate_link").unbind("click"); $(".mod_floater_submit").unbind("click"); + selectedTopics=[]; + $("topic_selected").removeClass("topic_selected"); $(".moderate_link").click(ev => { ev.preventDefault(); $(".pre_opt").removeClass("auto_hide"); @@ -298,7 +301,7 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif"," // Handle these specially switch(action) { case "move": - console.log("move action"); + log("move action"); let modTopicMover = $("#mod_topic_mover"); $("#mod_topic_mover").removeClass("auto_hide"); $("#mod_topic_mover .pane_row").click(function(){ @@ -306,7 +309,7 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif"," let fid = this.getAttribute("data-fid"); if(fid==null) return; this.classList.add("pane_selected"); - console.log("fid",fid); + log("fid",fid); forumToMoveTo = fid; $("#mover_submit").unbind("click"); diff --git a/public/panel_forums.js b/public/panel_forums.js index 3e850c84..c4a679b5 100644 --- a/public/panel_forums.js +++ b/public/panel_forums.js @@ -8,26 +8,26 @@ formVars = { var forums = {}; let items = document.getElementsByClassName("panel_forum_item"); for(let i=0; item=items[i]; i++) forums[i] = item.getAttribute("data-fid"); -console.log("forums",forums); +log("forums",forums); Sortable.create(document.getElementById("panel_forums"), { sort: true, onEnd: (evt) => { - console.log("pre forums",forums) - console.log("evt",evt) + log("pre forums",forums) + log("evt",evt) let oldFid = forums[evt.newIndex]; forums[evt.oldIndex] = oldFid; let newFid = evt.item.getAttribute("data-fid"); - console.log("newFid",newFid); + log("newFid",newFid); forums[evt.newIndex] = newFid; - console.log("post forums",forums); + log("post forums",forums); } }); document.getElementById("panel_forums_order_button").addEventListener("click", () => { let req = new XMLHttpRequest(); if(!req) { - console.log("Failed to create request"); + log("Failed to create request"); return false; } req.onreadystatechange = () => { @@ -37,7 +37,7 @@ document.getElementById("panel_forums_order_button").addEventListener("click", ( if(req.status!==200) return; let resp = JSON.parse(req.responseText); - console.log("resp",resp); + log("resp",resp); // TODO: Should we move other notices into TmplPhrases like this one? pushNotice(phraseBox["panel"]["panel.forums_order_updated"]); if(resp.success==1) return; diff --git a/public/panel_menu_items.js b/public/panel_menu_items.js index abf1a849..06db9de6 100644 --- a/public/panel_menu_items.js +++ b/public/panel_menu_items.js @@ -9,21 +9,21 @@ for(let i=0; item=items[i]; i++) menuItems[i] = item.getAttribute("data-miid"); Sortable.create(document.getElementById("panel_menu_item_holder"), { sort: true, onEnd: evt => { - console.log("pre menuItems",menuItems) - console.log("evt",evt) + log("pre menuItems",menuItems) + log("evt",evt) let oldMiid = menuItems[evt.newIndex]; menuItems[evt.oldIndex] = oldMiid; let newMiid = evt.item.getAttribute("data-miid"); - console.log("newMiid",newMiid); + log("newMiid",newMiid); menuItems[evt.newIndex] = newMiid; - console.log("post menuItems",menuItems); + log("post menuItems",menuItems); } }); document.getElementById("panel_menu_items_order_button").addEventListener("click", () => { let req = new XMLHttpRequest(); if(!req) { - console.log("Failed to create request"); + log("Failed to create request"); return false; } req.onreadystatechange = () => { @@ -32,7 +32,7 @@ document.getElementById("panel_menu_items_order_button").addEventListener("click // TODO: Signal the error with a notice if(req.status===200) { let resp = JSON.parse(req.responseText); - console.log("resp",resp); + log("resp",resp); // TODO: Should we move other notices into TmplPhrases like this one? pushNotice(phraseBox["panel"]["panel.themes_menus_items_order_updated"]); if(resp.success==1) return; diff --git a/public/profile_member.js b/public/profile_member.js index 07ec2ca0..fb971738 100644 --- a/public/profile_member.js +++ b/public/profile_member.js @@ -8,7 +8,7 @@ function handle_profile_hashbit() { hash_class = "delete_posts_hash"; break; default: - console.log("Unknown hashbit"); + log("Unknown hashbit"); return; } $(".hash_hide").hide(); diff --git a/public/register.js b/public/register.js index 86855700..9021df7f 100644 --- a/public/register.js +++ b/public/register.js @@ -3,12 +3,12 @@ fetch("/api/watches/") .then(resp => { if(resp.status!==200) { - console.log("err"); - console.log("resp",resp); + log("err"); + log("resp",resp); return; } resp.text().then(d => eval(d)); }) - .catch(e => console.log("e",e)); + .catch(e => log("e",e)); }); })() \ No newline at end of file diff --git a/public/widgets.js b/public/widgets.js index 508e0c39..a24659d5 100644 --- a/public/widgets.js +++ b/public/widgets.js @@ -1,7 +1,7 @@ "use strict"; $(document).ready(() => { let clickHandle = function(ev){ - console.log("in clickHandle") + log("in clickHandle") ev.preventDefault(); let ep = $(this).closest(".editable_parent"); ep.find(".hide_on_block_edit").addClass("edit_opened"); @@ -36,7 +36,7 @@ $(document).ready(() => { $(".wtype_sel").change(changeHandle); $(".widget_new a").click(function(ev){ - console.log("clicked widget_new a") + log("clicked widget_new a") let widgetList = this.closest(".panel_widgets"); let widgetNew = this.closest(".widget_new"); let widgetTmpl = document.getElementById("widgetTmpl").querySelector(".widget_item"); @@ -50,7 +50,7 @@ $(document).ready(() => { }); $(".widget_save").click(function(ev){ - console.log("in .widget_save") + log("in .widget_save") ev.preventDefault(); ev.stopPropagation(); let pform = this.closest("form"); diff --git a/templates/header.html b/templates/header.html index e9c11dd7..e5be2f43 100644 --- a/templates/header.html +++ b/templates/header.html @@ -7,7 +7,7 @@ {{range .Header.PreScriptsAsync}} {{end}} {{if .CurrentUser.Loggedin}}{{end}} - + {{range .Header.ScriptsAsync}} {{end}} diff --git a/templates/panel_forums.html b/templates/panel_forums.html index e6fa14e2..a6b36359 100644 --- a/templates/panel_forums.html +++ b/templates/panel_forums.html @@ -18,7 +18,7 @@ - + {{if gt .ID 1}}{{end}} diff --git a/themes/cosora/public/misc.js b/themes/cosora/public/misc.js index 67fd26f4..386d207f 100644 --- a/themes/cosora/public/misc.js +++ b/themes/cosora/public/misc.js @@ -66,7 +66,7 @@ // TODO: Refactor this to use `each` less $('.button_menu').click(function(){ - console.log(".button_menu"); + log(".button_menu"); // The outer container let buttonPane = newElement("div","button_menu_pane"); let postItem = $(this).parents('.post_item'); @@ -103,13 +103,13 @@ // Fill in the placeholder grid nodes let rowCount = 4; - console.log("rowCount",rowCount); - console.log("gridElementCount",gridElementCount); + log("rowCount",rowCount); + log("gridElementCount",gridElementCount); if(gridElementCount%rowCount != 0) { let fillerNodes = (rowCount - (gridElementCount%rowCount)); - console.log("fillerNodes",fillerNodes); + log("fillerNodes",fillerNodes); for(let i = 0; i < fillerNodes;i++ ) { - console.log("added a gridFiller"); + log("added a gridFiller"); buttonGrid.appendChild(newElement("div","gridFiller")); } } diff --git a/themes/nox/public/misc.js b/themes/nox/public/misc.js index f33c0236..dd082651 100644 --- a/themes/nox/public/misc.js +++ b/themes/nox/public/misc.js @@ -36,24 +36,24 @@ function noxMenuBind() { function moveAlerts() { // Move the alerts above the first header - let colSel = $(".colstack_right .colstack_head:first"); - let colSelAlt = $(".colstack_right .colstack_item:first"); - let colSelAltAlt = $(".colstack_right .coldyn_block:first"); - if(colSel.length > 0) $('.alert').insertBefore(colSel); - else if (colSelAlt.length > 0) $('.alert').insertBefore(colSelAlt); - else if (colSelAltAlt.length > 0) $('.alert').insertBefore(colSelAltAlt); + let cSel = $(".colstack_right .colstack_head:first"); + let cSelAlt = $(".colstack_right .colstack_item:first"); + let cSelAltAlt = $(".colstack_right .coldyn_block:first"); + if(cSel.length > 0) $('.alert').insertBefore(cSel); + else if (cSelAlt.length > 0) $('.alert').insertBefore(cSelAlt); + else if (cSelAltAlt.length > 0) $('.alert').insertBefore(cSelAltAlt); else $('.alert').insertAfter(".rowhead:first"); } - addInitHook("after_update_alert_list", alertCount => { - console.log("misc.js"); - console.log("alertCount",alertCount); - if(alertCount==0) { + addInitHook("after_update_alert_list", count => { + log("misc.js"); + log("count",count); + if(count==0) { $(".alerts").html(phraseBox["alerts"]["alerts.no_alerts_short"]); $(".user_box").removeClass("has_alerts"); } else { // TODO: Localise this - $(".alerts").html(alertCount + " new alerts"); + $(".alerts").html(count+" new alerts"); $(".user_box").addClass("has_alerts"); } }); @@ -63,7 +63,7 @@ function noxMenuBind() { addInitHook("end_init", () => { $(".alerts").click(ev => { ev.stopPropagation(); - var alerts = $(".menu_alerts")[0]; + let alerts = $(".menu_alerts")[0]; if($(alerts).hasClass("selectedAlert")) return; if(!conn) loadAlerts(alerts); alerts.className += " selectedAlert"; diff --git a/themes/shadow/public/misc.js b/themes/shadow/public/misc.js index 0510ae2b..121ab2b9 100644 --- a/themes/shadow/public/misc.js +++ b/themes/shadow/public/misc.js @@ -3,9 +3,9 @@ addInitHook("end_init", () => { // TODO: Run this when the image is loaded rather than when the document is ready? $(".topic_list img").each(function(){ let aspectRatio = this.naturalHeight / this.naturalWidth; - console.log("aspectRatio",aspectRatio); - console.log("height",this.naturalHeight); - console.log("width",this.naturalWidth); + log("aspectRatio",aspectRatio); + log("height",this.naturalHeight); + log("width",this.naturalWidth); $(this).css({ height: aspectRatio * this.width }); }); diff --git a/themes/tempra_simple/public/misc.js b/themes/tempra_simple/public/misc.js index 0510ae2b..121ab2b9 100644 --- a/themes/tempra_simple/public/misc.js +++ b/themes/tempra_simple/public/misc.js @@ -3,9 +3,9 @@ addInitHook("end_init", () => { // TODO: Run this when the image is loaded rather than when the document is ready? $(".topic_list img").each(function(){ let aspectRatio = this.naturalHeight / this.naturalWidth; - console.log("aspectRatio",aspectRatio); - console.log("height",this.naturalHeight); - console.log("width",this.naturalWidth); + log("aspectRatio",aspectRatio); + log("height",this.naturalHeight); + log("width",this.naturalWidth); $(this).css({ height: aspectRatio * this.width }); });