fix alerts erroring when you don't have any

reset mod floater status on page bind
alias console.log with log
reduce boilerplate
This commit is contained in:
Azareal 2020-07-23 14:02:16 +10:00
parent afc9f54e5e
commit e814e85daa
15 changed files with 203 additions and 202 deletions

View File

@ -8,7 +8,7 @@ function memStuff(window, document, Chartist) {
if(!chart instanceof Chartist.Line) return; if(!chart instanceof Chartist.Line) return;
chart.on('created', function() { chart.on('created', function() {
console.log("running created") log("running created")
const vbits = document.getElementsByClassName("ct-vertical"); const vbits = document.getElementsByClassName("ct-vertical");
if(vbits==null) return; if(vbits==null) return;
@ -16,7 +16,7 @@ function memStuff(window, document, Chartist) {
for(let i = 0; i < vbits.length; i++) { for(let i = 0; i < vbits.length; i++) {
tbits[i] = vbits[i].innerHTML; tbits[i] = vbits[i].innerHTML;
} }
console.log("tbits",tbits); log("tbits",tbits);
const calc = (places) => { const calc = (places) => {
if(places==3) return; if(places==3) return;
@ -47,7 +47,7 @@ function perfStuff(window, document, Chartist) {
if(!chart instanceof Chartist.Line) return; if(!chart instanceof Chartist.Line) return;
chart.on('created', function() { chart.on('created', function() {
console.log("running created") log("running created")
const vbits = document.getElementsByClassName("ct-vertical"); const vbits = document.getElementsByClassName("ct-vertical");
if(vbits==null) return; if(vbits==null) return;
@ -55,7 +55,7 @@ function perfStuff(window, document, Chartist) {
for(let i = 0; i < vbits.length; i++) { for(let i = 0; i < vbits.length; i++) {
tbits[i] = vbits[i].innerHTML; tbits[i] = vbits[i].innerHTML;
} }
console.log("tbits:",tbits); log("tbits:",tbits);
const calc = (places) => { const calc = (places) => {
if(places==3) return; if(places==3) return;
@ -122,8 +122,8 @@ function convertPerfUnit(quan, places = 0) {
// TODO: Fully localise this // TODO: Fully localise this
// TODO: Load rawLabels and seriesData dynamically rather than potentially fiddling with nonces for the CSP? // TODO: Load rawLabels and seriesData dynamically rather than potentially fiddling with nonces for the CSP?
function buildStatsChart(rawLabels, seriesData, timeRange, legendNames, typ=0) { function buildStatsChart(rawLabels, seriesData, timeRange, legendNames, typ=0) {
console.log("buildStatsChart"); log("buildStatsChart");
console.log("seriesData",seriesData); log("seriesData",seriesData);
let labels = []; let labels = [];
let aphrases = phraseBox["analytics"]; let aphrases = phraseBox["analytics"];
if(timeRange=="one-year") { if(timeRange=="one-year") {
@ -156,19 +156,19 @@ function buildStatsChart(rawLabels, seriesData, timeRange, legendNames, typ=0) {
continue; continue;
} }
let date = new Date(rawLabels[i]*1000); let date = new Date(rawLabels[i]*1000);
console.log("date", date); log("date",date);
let minutes = "0" + date.getMinutes(); let minutes = "0" + date.getMinutes();
let label = date.getHours() + ":" + minutes.substr(-2); let label = date.getHours() + ":" + minutes.substr(-2);
console.log("label", label); log("label",label);
labels.push(label); labels.push(label);
} }
} else { } else {
for(const i in rawLabels) { for(const i in rawLabels) {
let date = new Date(rawLabels[i]*1000); let date = new Date(rawLabels[i]*1000);
console.log("date", date); log("date",date);
let minutes = "0" + date.getMinutes(); let minutes = "0" + date.getMinutes();
let label = date.getHours() + ":" + minutes.substr(-2); let label = date.getHours() + ":" + minutes.substr(-2);
console.log("label", label); log("label",label);
labels.push(label); labels.push(label);
} }
} }

View File

@ -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 // 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) { function ajaxError(xhr,status,e) {
console.log("The AJAX request failed"); log("The AJAX request failed");
console.log("xhr",xhr); log("xhr",xhr);
console.log("status",status); log("status",status);
console.log("e",e); log("e",e);
if(status=="parsererror") console.log("The server didn't respond with a valid JSON response"); if(status=="parsererror") log("The server didn't respond with a valid JSON response");
console.trace(); console.trace();
} }
@ -40,7 +40,7 @@ function postLink(ev) {
} }
function bindToAlerts() { function bindToAlerts() {
console.log("bindToAlerts"); log("bindToAlerts");
$(".alertItem.withAvatar a").unbind("click"); $(".alertItem.withAvatar a").unbind("click");
$(".alertItem.withAvatar a").click(function(ev) { $(".alertItem.withAvatar a").click(function(ev) {
ev.stopPropagation(); ev.stopPropagation();
@ -93,6 +93,10 @@ function addAlert(msg,notice=false) {
} }
function updateAlertList(menuAlerts) { function updateAlertList(menuAlerts) {
log("enter updateAlertList");
log("alertList:",alertList);
log("alertMapping:",alertMapping);
log("alertCount:",alertCount);
let alertListNode = menuAlerts.getElementsByClassName("alertList")[0]; let alertListNode = menuAlerts.getElementsByClassName("alertList")[0];
let alertCounterNode = menuAlerts.getElementsByClassName("alert_counter")[0]; let alertCounterNode = menuAlerts.getElementsByClassName("alert_counter")[0];
alertCounterNode.textContent = "0"; alertCounterNode.textContent = "0";
@ -119,7 +123,7 @@ function updateAlertList(menuAlerts) {
} }
bindToAlerts(); bindToAlerts();
console.log("alertCount",alertCount) log("alertCount",alertCount)
runInitHook("after_update_alert_list",alertCount); runInitHook("after_update_alert_list",alertCount);
} }
@ -152,7 +156,7 @@ function loadAlerts(menuAlerts,eTc=false) {
if(eTc && lastTc!=0) { if(eTc && lastTc!=0) {
for(var i in data.msgs) wsAlertEvent(data.msgs[i]); for(var i in data.msgs) wsAlertEvent(data.msgs[i]);
} else {*/ } else {*/
console.log("data",data); log("data",data);
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);
@ -172,10 +176,10 @@ function loadAlerts(menuAlerts,eTc=false) {
let dat = JSON.parse(magic.responseText); let dat = JSON.parse(magic.responseText);
if("errmsg" in dat) errtxt = dat.errmsg; if("errmsg" in dat) errtxt = dat.errmsg;
} catch(e) { } catch(e) {
console.log(magic.responseText); log(magic.responseText);
console.log(e); log(e);
} }
console.log("er",er); log("er",er);
setAlertError(menuAlerts,errtxt); setAlertError(menuAlerts,errtxt);
} }
}); });
@ -201,7 +205,7 @@ function SplitN(data,ch,n) {
} }
function wsAlertEvent(dat) { function wsAlertEvent(dat) {
console.log("wsAlertEvent",dat) log("wsAlertEvent",dat)
addAlert(dat,true); addAlert(dat,true);
alertCount++; alertCount++;
@ -222,12 +226,12 @@ function runWebSockets(resume=false) {
conn = new WebSocket("ws"+s+"://" + document.location.host + "/ws/"); conn = new WebSocket("ws"+s+"://" + document.location.host + "/ws/");
conn.onerror = e => { conn.onerror = e => {
console.log(e); log(e);
} }
// TODO: Sync alerts, topic list, etc. // TODO: Sync alerts, topic list, etc.
conn.onopen = () => { 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'); if(resume) conn.send("resume " + document.location.pathname + " " + Math.round((new Date()).getTime() / 1000) + '\r');
else conn.send("page " + document.location.pathname + '\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 // 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.onclose = () => {
conn = false; conn = false;
console.log("The WebSockets connection was closed"); log("The WebSockets connection was closed");
let backoff = 0.8; let backoff = 0.8;
if(wsBackoff < 0) wsBackoff = 0; if(wsBackoff < 0) wsBackoff = 0;
else if(wsBackoff > 12) backoff = 11; else if(wsBackoff > 12) backoff = 11;
@ -260,12 +264,12 @@ function runWebSockets(resume=false) {
conn.onmessage = (event) => { conn.onmessage = (event) => {
if(!noAlerts && event.data[0] == "{") { if(!noAlerts && event.data[0] == "{") {
console.log("json message"); log("json message");
let data = ""; let data = "";
try { try {
data = JSON.parse(event.data); data = JSON.parse(event.data);
} catch(e) { } catch(e) {
console.log(e); log(e);
return; return;
} }
@ -295,13 +299,13 @@ function runWebSockets(resume=false) {
}); });
} }
} else if("Topics" in data) { } else if("Topics" in data) {
console.log("topic in data"); log("topic in data");
console.log("data",data); log("data",data);
// TODO: Handle desyncs more gracefully? // TODO: Handle desyncs more gracefully?
// TODO: Send less unneccessary data? // TODO: Send less unneccessary data?
let topic = data.Topics[0]; let topic = data.Topics[0];
if(topic===undefined){ if(topic===undefined){
console.log("empty topic list"); log("empty topic list");
return; return;
} }
if("mod" in data) { if("mod" in data) {
@ -323,7 +327,7 @@ function runWebSockets(resume=false) {
let node = $(renTopic); let node = $(renTopic);
node.addClass("new_item hide_ajax_topic"); node.addClass("new_item hide_ajax_topic");
console.log("Prepending to topic list"); log("Prepending to topic list");
$(".topic_list").prepend(node); $(".topic_list").prepend(node);
moreTopicCount++; moreTopicCount++;
@ -333,17 +337,17 @@ function runWebSockets(resume=false) {
block.classList.remove("more_topic_block_initial"); block.classList.remove("more_topic_block_initial");
block.classList.add("more_topic_block_active"); block.classList.add("more_topic_block_active");
console.log("phraseBox",phraseBox); log("phraseBox",phraseBox);
let msgBox = block.getElementsByClassName("more_topics")[0]; let msgBox = block.getElementsByClassName("more_topics")[0];
msgBox.innerText = phraseBox["topic_list"]["topic_list.changed_topics"].replace("%d",moreTopicCount); 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'); let messages = event.data.split('\r');
for(var i=0; i<messages.length; i++) { for(var i=0; i<messages.length; i++) {
let message = messages[i]; let message = messages[i];
//console.log("message",message); //log("message",message);
let msgblocks = SplitN(message," ",3); let msgblocks = SplitN(message," ",3);
if(msgblocks.length < 3) continue; if(msgblocks.length < 3) continue;
if(message.startsWith("set ")) { if(message.startsWith("set ")) {
@ -369,11 +373,11 @@ function getExt(name) {
(() => { (() => {
addInitHook("pre_init", () => { addInitHook("pre_init", () => {
runInitHook("pre_global"); 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 :( // 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) { if(!noAlerts) {
notifyOnScriptW("tmpl_alert", e => { 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"); if(!Tmpl_alert) throw("tmpl func not found");
addInitHook("after_phrases", () => { addInitHook("after_phrases", () => {
@ -385,17 +389,17 @@ function getExt(name) {
let sAlertMapping = localStorage.getItem("alertMapping"); let sAlertMapping = localStorage.getItem("alertMapping");
let sAlertCount = localStorage.getItem("alertCount"); let sAlertCount = localStorage.getItem("alertCount");
if(sAlertList!=null && sAlertList!="" && if(sAlertList!=null && sAlertList!="" &&
sAlertMapping!=null && sAlertMapping!="" &&sAlertCount!=null && sAlertCount!="" sAlertMapping!=null && sAlertMapping!="" &&sAlertCount!=null && sAlertCount!="" && sAlertCount!="0"
) { ) {
console.log("sAlertList",sAlertList) log("sAlertList",sAlertList)
console.log("sAlertMapping",sAlertMapping) log("sAlertMapping",sAlertMapping)
console.log("sAlertCount",sAlertCount) log("sAlertCount",sAlertCount)
alertList = JSON.parse(sAlertList) alertList = JSON.parse(sAlertList)
alertMapping = JSON.parse(sAlertMapping) alertMapping = JSON.parse(sAlertMapping)
alertCount = parseInt(sAlertCount) alertCount = parseInt(sAlertCount)
console.log("alertList",alertList) log("alertList",alertList)
console.log("alertMapping",alertMapping) log("alertMapping",alertMapping)
console.log("alertCount",alertCount) log("alertCount",alertCount)
for(var i=0; i<al.length; i++) loadAlerts(al[i],true); for(var i=0; i<al.length; i++) loadAlerts(al[i],true);
} else for(var i=0; i<al.length; i++) loadAlerts(al[i]); } else for(var i=0; i<al.length; i++) loadAlerts(al[i]);
if(window["WebSocket"]) runWebSockets(); if(window["WebSocket"]) runWebSockets();
@ -469,12 +473,12 @@ function mainInit(){
ev.preventDefault(); ev.preventDefault();
//$(this).unbind("click"); //$(this).unbind("click");
let target = this.closest("a").getAttribute("href"); let target = this.closest("a").getAttribute("href");
console.log("target",target); log("target",target);
let controls = this.closest(".controls"); let controls = this.closest(".controls");
let hadLikes = controls.classList.contains("has_likes"); let hadLikes = controls.classList.contains("has_likes");
let likeCountNode = controls.getElementsByClassName("like_count")[0]; let likeCountNode = controls.getElementsByClassName("like_count")[0];
console.log("likeCountNode",likeCountNode); log("likeCountNode",likeCountNode);
if(this.classList.contains("add_like")) { if(this.classList.contains("add_like")) {
this.classList.remove("add_like"); this.classList.remove("add_like");
this.classList.add("remove_like"); this.classList.add("remove_like");
@ -501,9 +505,9 @@ function mainInit(){
if("success" in dat && dat["success"] == "1") return; if("success" in dat && dat["success"] == "1") return;
// addNotice("Failed to add a like: {err}") // addNotice("Failed to add a like: {err}")
//likeCountNode.innerHTML = parseInt(likeCountNode.innerHTML)-1; //likeCountNode.innerHTML = parseInt(likeCountNode.innerHTML)-1;
console.log("data",dat); log("data",dat);
console.log("status",status); log("status",status);
console.log("xhr",xhr); log("xhr",xhr);
} }
}); });
}); });
@ -553,7 +557,7 @@ function mainInit(){
}).then(dat => { }).then(dat => {
if(!"Topics" in dat) throw("no Topics in data"); if(!"Topics" in dat) throw("no Topics in data");
let topics = dat["Topics"]; 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 // TODO: Fix the data race where the function hasn't been loaded yet
let out = ""; let out = "";
@ -565,7 +569,7 @@ function mainInit(){
rebuildPaginator(dat.LastPage); rebuildPaginator(dat.LastPage);
rebindPaginator(); rebindPaginator();
}).catch(e => { }).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(); console.trace();
}); });
}); });
@ -585,10 +589,10 @@ function mainInit(){
if(!resp.ok) throw(url+"&js=1 failed to load"); if(!resp.ok) throw(url+"&js=1 failed to load");
return resp.json(); return resp.json();
}).then(dat => { }).then(dat => {
console.log("data",dat); log("data",dat);
if(!"Topics" in dat) throw("no Topics in data"); if(!"Topics" in dat) throw("no Topics in data");
let topics = dat["Topics"]; 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 // TODO: Fix the data race where the function hasn't been loaded yet
let out = ""; let out = "";
@ -610,7 +614,7 @@ function mainInit(){
that.classList.add("filter_selected"); that.classList.add("filter_selected");
$(".topic_list_title h1").text(that.innerText); $(".topic_list_title h1").text(that.innerText);
}).catch(e => { }).catch(e => {
console.log("Unable to get script '"+url+"&js=1"+"'",e); log("Unable to get script '"+url+"&js=1"+"'",e);
console.trace(); console.trace();
}); });
}); });
@ -639,7 +643,7 @@ function mainInit(){
}).then(data => { }).then(data => {
if(!"Topics" in data) throw("no Topics in data"); if(!"Topics" in data) throw("no Topics in data");
let topics = data["Topics"]; 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 // TODO: Fix the data race where the function hasn't been loaded yet
let out = ""; let out = "";
@ -655,7 +659,7 @@ function mainInit(){
rebuildPaginator(data.LastPage); rebuildPaginator(data.LastPage);
rebindPaginator(); rebindPaginator();
}).catch(e => { }).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(); console.trace();
}); });
}); });
@ -690,7 +694,7 @@ function mainInit(){
$(".edit_fields").click(function(ev) { $(".edit_fields").click(function(ev) {
ev.preventDefault(); ev.preventDefault();
if($(this).find("input").length!==0) return; if($(this).find("input").length!==0) return;
//console.log("clicked .edit_fields"); //log("clicked .edit_fields");
var bp = $(this).closest('.editable_parent'); var bp = $(this).closest('.editable_parent');
bp.find('.hide_on_edit').addClass("edit_opened"); bp.find('.hide_on_edit').addClass("edit_opened");
bp.find('.show_on_edit').addClass("edit_opened"); bp.find('.show_on_edit').addClass("edit_opened");
@ -744,8 +748,8 @@ function mainInit(){
}); });
let href = $(this).closest('a').attr("href"); let href = $(this).closest('a').attr("href");
//console.log("href",href); //log("href",href);
//console.log(outData); //log(outData);
$.ajax({ url: href+"?s="+me.User.S, type:"POST", dataType:"json", data: outData, error: ajaxError }); $.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('.hide_on_edit').removeClass("edit_opened");
bp.find('.show_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()) $("input,textarea,select,option").keyup(ev => ev.stopPropagation())
$("#themeSelectorSelect").change(function(){ $("#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({ $.ajax({
url: this.form.getAttribute("action")+"?s="+me.User.S, url: this.form.getAttribute("action")+"?s="+me.User.S,
type:"POST", type:"POST",
@ -786,10 +790,10 @@ function mainInit(){
data: { "theme": this.options[this.selectedIndex].getAttribute("value"), js: 1 }, data: { "theme": this.options[this.selectedIndex].getAttribute("value"), js: 1 },
error: ajaxError, error: ajaxError,
success: function (dat,status,xhr) { success: function (dat,status,xhr) {
console.log("Theme successfully switched"); log("Theme successfully switched");
console.log("dat",dat); log("dat",dat);
console.log("status",status); log("status",status);
console.log("xhr",xhr); log("xhr",xhr);
window.location.reload(); window.location.reload();
} }
}); });
@ -814,10 +818,10 @@ function mainInit(){
$(".unix_to_24_hour_time").each(function(){ $(".unix_to_24_hour_time").each(function(){
let unixTime = this.innerText; let unixTime = this.innerText;
let date = new Date(unixTime*1000); let date = new Date(unixTime*1000);
console.log("date",date); log("date",date);
let mins = "0"+date.getMinutes(); let mins = "0"+date.getMinutes();
let formattedTime = date.getHours()+":"+mins.substr(-2); let formattedTime = date.getHours()+":"+mins.substr(-2);
console.log("formattedTime",formattedTime); log("formattedTime",formattedTime);
this.innerText = formattedTime; this.innerText = formattedTime;
}); });
@ -825,10 +829,10 @@ function mainInit(){
// TODO: Localise this // TODO: Localise this
let monthList = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; let monthList = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
let date = new Date(this.innerText * 1000); let date = new Date(this.innerText * 1000);
console.log("date",date); log("date",date);
let day = "0"+date.getDate(); let day = "0"+date.getDate();
let formattedTime = monthList[date.getMonth()]+" "+day.substr(-2)+" "+date.getFullYear(); let formattedTime = monthList[date.getMonth()]+" "+day.substr(-2)+" "+date.getFullYear();
console.log("formattedTime",formattedTime); log("formattedTime",formattedTime);
this.innerText = formattedTime; this.innerText = formattedTime;
}); });
@ -888,9 +892,9 @@ function mainInit(){
let pro; let pro;
if(stripQ(getExt(res))=="css") pro = asyncGetSheet("/s/"+res) if(stripQ(getExt(res))=="css") pro = asyncGetSheet("/s/"+res)
else pro = asyncGetScript("/s/"+res) else pro = asyncGetScript("/s/"+res)
pro.then(() => console.log("Loaded "+res)) pro.then(() => log("Loaded "+res))
.catch(e => { .catch(e => {
console.log("Unable to get '"+res+"'",e); log("Unable to get '"+res+"'",e);
console.trace(); console.trace();
}); });
} }
@ -903,7 +907,7 @@ function mainInit(){
let obj = {Title:document.title,Url:base}; let obj = {Title:document.title,Url:base};
history.pushState(obj,obj.Title,obj.Url); history.pushState(obj,obj.Title,obj.Url);
}).catch(e => { }).catch(e => {
console.log("Unable to get script '"+href+""+"'",e); log("Unable to get script '"+href+""+"'",e);
console.trace(); console.trace();
}); });
} }
@ -1066,13 +1070,13 @@ function bindTopic() {
ev.stopPropagation(); ev.stopPropagation();
let src = this.closest(".post_item").getElementsByClassName("edit_source")[0]; let src = this.closest(".post_item").getElementsByClassName("edit_source")[0];
let con = document.getElementById("input_content") let con = document.getElementById("input_content")
console.log("con.value",con.value); log("con.value",con.value);
let item; let item;
if(con.value=="") item = "<blockquote>"+src.innerHTML+"</blockquote>" if(con.value=="") item = "<blockquote>"+src.innerHTML+"</blockquote>"
else item = "\r\n<blockquote>"+src.innerHTML+"</blockquote>"; else item = "\r\n<blockquote>"+src.innerHTML+"</blockquote>";
con.value = con.value+item; con.value = con.value+item;
console.log("con.value",con.value); log("con.value",con.value);
// For custom / third party text editors // For custom / third party text editors
quoteItemCallback(src.innerHTML,item); quoteItemCallback(src.innerHTML,item);
@ -1093,13 +1097,13 @@ function bindTopic() {
} }
if(allZero) { if(allZero) {
$("#poll_results_"+pollID+" .poll_no_results").removeClass("auto_hide"); $("#poll_results_"+pollID+" .poll_no_results").removeClass("auto_hide");
console.log("all zero") log("all zero")
return; return;
} }
$("#poll_results_"+pollID+" .user_content").html("<div id='poll_results_chart_"+pollID+"'></div>"); $("#poll_results_"+pollID+" .user_content").html("<div id='poll_results_chart_"+pollID+"'></div>");
console.log("rawData",rawData); log("rawData",rawData);
console.log("series",data); log("series",data);
Chartist.Pie('#poll_results_chart_'+pollID, { Chartist.Pie('#poll_results_chart_'+pollID, {
series: data, series: data,
}, { }, {

View File

@ -5,39 +5,38 @@ 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={}; var hooks={};
var ranInitHooks={} var ranInitHooks={}
var log = console.log;
function runHook(name,...args) { function runHook(name,...args) {
if(!(name in hooks)) { if(!(name in hooks)) {
console.log("Couldn't find hook '"+name+"'"); log("Couldn't find hook "+name);
return; return;
} }
console.log("Running hook '"+name+"'"); log("Running hook "+name);
let hook = hooks[name]; let hook = hooks[name];
let ret; let o;
for (const index in hook) ret = hook[index](...args); for (const index in hook) o = hook[index](...args);
return ret; return o;
} }
function addHook(name,h) { function addHook(name,h) {
log("Add hook "+name);
if(hooks[name]===undefined) hooks[name]=[]; if(hooks[name]===undefined) hooks[name]=[];
hooks[name].push(h); 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 // 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) { function runInitHook(name,...args) {
let ret = runHook(name,...args);
ranInitHooks[name]=true; ranInitHooks[name]=true;
return ret; return runHook(name,...args);
} }
function addInitHook(name,h) { function addInitHook(name,h) {
addHook(name,h); addHook(name,h);
if(name in ranInitHooks) h(); if(name in ranInitHooks) h();
} }
// Temporary hack for templates // Temporary hack for templates
function len(it) {return it.length;} function len(d) {return d.length}
function asyncGetScript(src) { function asyncGetScript(src) {
return new Promise((resolve,reject) => { return new Promise((resolve,reject) => {
@ -54,7 +53,7 @@ function asyncGetScript(src) {
} }
} }
script.onerror = (e) => { script.onerror = e => {
reject(e); reject(e);
}; };
script.onload = onloadHandler; script.onload = onloadHandler;
@ -72,27 +71,27 @@ 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) log("ssp",ssp)
if(window[ssp]) { if(window[ssp]) {
resolve(); resolve();
return; return;
} }
} catch(e) {} } catch(e) {}
console.log("src",src) log("src",src)
let script = document.querySelectorAll('[src^="'+src+'"]')[0]; let script = document.querySelectorAll(`[src^="${src}"]`)[0];
console.log("script",script); log("script",script);
if(script===undefined) { if(script===undefined) {
reject("no script found"); reject("no script found");
return; return;
} }
const onloadHandler = (e) => { const onloadHandler = e => {
script.onload=null; script.onload=null;
script.onreadystatechange=null; script.onreadystatechange=null;
resolve(); resolve();
} }
script.onerror = (e) => { script.onerror = e => {
reject(e); reject(e);
}; };
script.onload = onloadHandler; script.onload = onloadHandler;
@ -103,38 +102,35 @@ function notifyOnScript(src) {
function notifyOnScriptW(name,complete,success) { function notifyOnScriptW(name,complete,success) {
notifyOnScript(name) notifyOnScript(name)
.then(() => { .then(() => {
console.log("Loaded "+name+".js"); log(`Loaded ${name}.js`);
complete(); complete();
if(success!==undefined) success(); if(success!==undefined) success();
}).catch(e => { }).catch(e => {
console.log("Unable to get '"+name+"'",e); log("Unable to get "+name,e);
console.trace(); console.trace();
complete(e); complete(e);
}); });
} }
// TODO: Send data at load time so we don't have to rely on a fallback template here // 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 fname = name;
let value = "; "+document.cookie; let value = "; "+document.cookie;
let parts = value.split("; current_theme="); let parts = value.split("; current_theme=");
if(parts.length==2) fname += "_"+parts.pop().split(";").shift(); if(parts.length==2) fname += "_"+parts.pop().split(";").shift();
let url = "/s/"+fname+".js" let url = `/s/${fname}.js`
let iurl = "/s/"+name+".js" let iurl = `/s/${name}.js`
asyncGetScript(url) asyncGetScript(url)
.then(callback) .then(h).catch(e => {
.catch(e => { log("Unable to get "+url,e);
console.log("Unable to get '"+url+"'");
if(fname!=name) { if(fname!=name) {
asyncGetScript(iurl) asyncGetScript(iurl)
.then(callback) .then(h).catch(e => {
.catch(e => { log("Unable to get "+iurl,e);
console.log("Unable to get '"+iurl+"'",e);
console.trace(); console.trace();
}); });
} }
console.log("e",e);
console.trace(); console.trace();
fail(e); fail(e);
}); });
@ -143,8 +139,8 @@ function loadScript(name,callback,fail) {
function RelativeTime(date) {return date} function RelativeTime(date) {return date}
function initPhrases(member,acp=false) { function initPhrases(member,acp=false) {
console.log("initPhrases") log("initPhrases")
console.log("tmlInits",tmplInits) log("tmlInits",tmplInits)
let e = ""; let e = "";
if(member && !acp) e=",status,topic_list,topic"; if(member && !acp) e=",status,topic_list,topic";
else if(acp) e=",analytics,panel"; // TODO: Request phrases for just one section of the acp? 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) { function fetchPhrases(plist) {
fetch("/api/phrases/?q="+plist,{cache:"no-cache"}) fetch("/api/phrases/?q="+plist,{cache:"no-cache"})
.then(resp => resp.json()) .then(r => r.json())
.then(data => { .then(d => {
console.log("loaded phrase endpoint data"); log("loaded phrase endpoint data",d);
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(d[phraseName]);
console.log("Adding phrases"); log("Adding phrases for "+key,phrases);
console.log("key",key);
console.log("phrases",phrases);
tmplPhrases[key] = phrases; tmplPhrases[key] = phrases;
}); });
let prefixes={}; let prefixes={};
Object.keys(data).forEach(key => { Object.keys(d).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] = d[key];
}); });
Object.keys(prefixes).forEach(prefix => { Object.keys(prefixes).forEach(prefix => {
console.log("adding phrase prefix '"+prefix+"' to box"); log(`adding phrase prefix ${prefix} to box`);
phraseBox[prefix] = prefixes[prefix]; phraseBox[prefix] = prefixes[prefix];
}); });
@ -190,31 +183,32 @@ function fetchPhrases(plist) {
let toLoad = 1; let toLoad = 1;
// TODO: Shunt this into member if there aren't any search and filter widgets? // TODO: Shunt this into member if there aren't any search and filter widgets?
let q = (f) => { let q = f => {
toLoad--; toLoad--;
if(toLoad===0) initPhrases(member,acp); if(toLoad===0) initPhrases(member,acp);
if(f) throw("tmpl func not found"); if(f) throw("tmpl func not found");
}; };
let l = (n,h) => notifyOnScriptW("tmpl_"+n,h);
if(!acp) { if(!acp) {
toLoad += 2; toLoad += 2;
if(member) { if(member) {
toLoad += 3; toLoad += 3;
notifyOnScriptW("tmpl_topic_c_edit_post", () => q(!Tmpl_topic_c_edit_post)); l("topic_c_edit_post", () => q(!Tmpl_topic_c_edit_post));
notifyOnScriptW("tmpl_topic_c_attach_item", () => q(!Tmpl_topic_c_attach_item)); l("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_poll_input", () => q(!Tmpl_topic_c_poll_input));
} }
notifyOnScriptW("tmpl_topics_topic", () => q(!Tmpl_topics_topic)); l("topics_topic", () => q(!Tmpl_topics_topic));
notifyOnScriptW("tmpl_paginator", () => q(!Tmpl_paginator)); l("paginator", () => q(!Tmpl_paginator));
} }
notifyOnScriptW("tmpl_notice", () => q(!Tmpl_notice)); l("notice", () => q(!Tmpl_notice));
if(member) { if(member) {
fetch("/api/me/") fetch("/api/me/")
.then(resp => resp.json()) .then(r => r.json())
.then(data => { .then(d => {
console.log("me data",data); log("me",d);
me=data; me=d;
runInitHook("pre_init"); runInitHook("pre_init");
}); });
} else { } else {

View File

@ -20,7 +20,7 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif","
let totalSize = 0; let totalSize = 0;
for(let i=0; i<files.length; i++) { for(let i=0; i<files.length; i++) {
console.log("file "+i,files[i]); log("file "+i,files[i]);
totalSize += files[i]["size"]; totalSize += files[i]["size"];
} }
if(totalSize > me.Site.MaxRequestSize) throw("You can't upload this much at once, max: "+me.Site.MaxRequestSize); if(totalSize > 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 { try {
uploadFileHandler(this.files, 5, () => {}, uploadFileHandler(this.files, 5, () => {},
(e,hash,fname) => { (e,hash,fname) => {
console.log("hash",hash); log("hash",hash);
let formData = new FormData(); let formData = new FormData();
formData.append("s",me.User.S); formData.append("s",me.User.S);
for(let i=0; i<this.files.length; i++) formData.append("upload_files",this.files[i]); for(let i=0; i<this.files.length; i++) formData.append("upload_files",this.files[i]);
@ -68,7 +68,7 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif","
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); //log("rdata",data);
let fileItem = document.createElement("div"); let fileItem = document.createElement("div");
let ext = getExt(fname); let ext = getExt(fname);
// 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?
@ -92,7 +92,7 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif","
}); });
} catch(e) { } catch(e) {
// TODO: Use a notice instead // TODO: Use a notice instead
console.log("e",e); log("e",e);
alert(e); alert(e);
} }
} }
@ -104,7 +104,7 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif","
// TODO: Use client templates here // TODO: Use client templates here
let fileDock = document.getElementById("upload_file_dock"); let fileDock = document.getElementById("upload_file_dock");
let fileItem = document.createElement("label"); let fileItem = document.createElement("label");
console.log("fileItem",fileItem); log("fileItem",fileItem);
let ext = getExt(fname); let ext = getExt(fname);
// 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?
@ -116,23 +116,23 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif","
fileDock.appendChild(fileItem); fileDock.appendChild(fileItem);
},(e,hash,fname) => { },(e,hash,fname) => {
console.log("hash",hash); log("hash",hash);
let ext = getExt(fname) let ext = getExt(fname)
let con = document.getElementById("input_content") let con = document.getElementById("input_content")
console.log("con.value",con.value); log("con.value",con.value);
let attachItem; let attachItem;
if(con.value=="") attachItem = "//"+window.location.host+"/attachs/"+hash+"."+ext; if(con.value=="") attachItem = "//"+window.location.host+"/attachs/"+hash+"."+ext;
else attachItem = "\r\n//"+window.location.host+"/attachs/"+hash+"."+ext; else attachItem = "\r\n//"+window.location.host+"/attachs/"+hash+"."+ext;
con.value = con.value + attachItem; con.value = con.value + attachItem;
console.log("con.value",con.value); log("con.value",con.value);
// For custom / third party text editors // For custom / third party text editors
attachItemCallback(attachItem); attachItemCallback(attachItem);
}); });
} catch(e) { } catch(e) {
// TODO: Use a notice instead // TODO: Use a notice instead
console.log("e",e); log("e",e);
alert(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++) { for(let i = 0; i < elems.length; i++) {
let pathNode = elems[i].querySelector(".attach_item_path"); let pathNode = elems[i].querySelector(".attach_item_path");
console.log("pathNode",pathNode); log("pathNode",pathNode);
aidList += pathNode.getAttribute("aid")+","; aidList += pathNode.getAttribute("aid")+",";
elems[i].remove(); elems[i].remove();
} }
if(aidList.length > 0) aidList = aidList.slice(0, -1); if(aidList.length > 0) aidList = aidList.slice(0, -1);
console.log("aidList",aidList) log("aidList",aidList)
formData.append("aids",aidList); formData.append("aids",aidList);
let ec = 0; let ec = 0;
@ -214,9 +214,9 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif","
}); });
function addPollInput() { function addPollInput() {
console.log("clicked on pollinputinput"); log("clicked on pollinputinput");
let dataPollInput = $(this).parent().attr("data-pollinput"); let dataPollInput = $(this).parent().attr("data-pollinput");
console.log("dataPollInput",dataPollInput); log("dataPollInput",dataPollInput);
if(dataPollInput==undefined) return; if(dataPollInput==undefined) return;
if(dataPollInput!=(pollInputIndex-1)) return; if(dataPollInput!=(pollInputIndex-1)) return;
$(".poll_content_row .formitem").append(Tmpl_topic_c_poll_input({ $(".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), Place: phraseBox["topic"]["topic.reply_add_poll_option"].replace("%d",pollInputIndex),
})); }));
pollInputIndex++; pollInputIndex++;
console.log("new pollInputIndex",pollInputIndex); log("new pollInputIndex",pollInputIndex);
$(".pollinputinput").off("click"); $(".pollinputinput").off("click");
$(".pollinputinput").click(addPollInput); $(".pollinputinput").click(addPollInput);
} }
@ -241,8 +241,11 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif","
}); });
//addInitHook("after_init_bind_page", () => { //addInitHook("after_init_bind_page", () => {
addHook("end_bind_page", () => { addHook("end_bind_page", () => {
if(!$(".mod_floater").hasClass("auto_hide")) $(".mod_floater").addClass("auto_hide")
$(".moderate_link").unbind("click"); $(".moderate_link").unbind("click");
$(".mod_floater_submit").unbind("click"); $(".mod_floater_submit").unbind("click");
selectedTopics=[];
$("topic_selected").removeClass("topic_selected");
$(".moderate_link").click(ev => { $(".moderate_link").click(ev => {
ev.preventDefault(); ev.preventDefault();
$(".pre_opt").removeClass("auto_hide"); $(".pre_opt").removeClass("auto_hide");
@ -298,7 +301,7 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif","
// Handle these specially // Handle these specially
switch(action) { switch(action) {
case "move": case "move":
console.log("move action"); log("move action");
let modTopicMover = $("#mod_topic_mover"); let modTopicMover = $("#mod_topic_mover");
$("#mod_topic_mover").removeClass("auto_hide"); $("#mod_topic_mover").removeClass("auto_hide");
$("#mod_topic_mover .pane_row").click(function(){ $("#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"); let fid = this.getAttribute("data-fid");
if(fid==null) return; if(fid==null) return;
this.classList.add("pane_selected"); this.classList.add("pane_selected");
console.log("fid",fid); log("fid",fid);
forumToMoveTo = fid; forumToMoveTo = fid;
$("#mover_submit").unbind("click"); $("#mover_submit").unbind("click");

View File

@ -8,26 +8,26 @@ formVars = {
var forums = {}; var forums = {};
let items = document.getElementsByClassName("panel_forum_item"); let items = document.getElementsByClassName("panel_forum_item");
for(let i=0; item=items[i]; i++) forums[i] = item.getAttribute("data-fid"); 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"), { Sortable.create(document.getElementById("panel_forums"), {
sort: true, sort: true,
onEnd: (evt) => { onEnd: (evt) => {
console.log("pre forums",forums) log("pre forums",forums)
console.log("evt",evt) log("evt",evt)
let oldFid = forums[evt.newIndex]; let oldFid = forums[evt.newIndex];
forums[evt.oldIndex] = oldFid; forums[evt.oldIndex] = oldFid;
let newFid = evt.item.getAttribute("data-fid"); let newFid = evt.item.getAttribute("data-fid");
console.log("newFid",newFid); log("newFid",newFid);
forums[evt.newIndex] = newFid; forums[evt.newIndex] = newFid;
console.log("post forums",forums); log("post forums",forums);
} }
}); });
document.getElementById("panel_forums_order_button").addEventListener("click", () => { document.getElementById("panel_forums_order_button").addEventListener("click", () => {
let req = new XMLHttpRequest(); let req = new XMLHttpRequest();
if(!req) { if(!req) {
console.log("Failed to create request"); log("Failed to create request");
return false; return false;
} }
req.onreadystatechange = () => { req.onreadystatechange = () => {
@ -37,7 +37,7 @@ document.getElementById("panel_forums_order_button").addEventListener("click", (
if(req.status!==200) return; if(req.status!==200) return;
let resp = JSON.parse(req.responseText); let resp = JSON.parse(req.responseText);
console.log("resp",resp); log("resp",resp);
// TODO: Should we move other notices into TmplPhrases like this one? // TODO: Should we move other notices into TmplPhrases like this one?
pushNotice(phraseBox["panel"]["panel.forums_order_updated"]); pushNotice(phraseBox["panel"]["panel.forums_order_updated"]);
if(resp.success==1) return; if(resp.success==1) return;

View File

@ -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"), { Sortable.create(document.getElementById("panel_menu_item_holder"), {
sort: true, sort: true,
onEnd: evt => { onEnd: evt => {
console.log("pre menuItems",menuItems) log("pre menuItems",menuItems)
console.log("evt",evt) log("evt",evt)
let oldMiid = menuItems[evt.newIndex]; let oldMiid = menuItems[evt.newIndex];
menuItems[evt.oldIndex] = oldMiid; menuItems[evt.oldIndex] = oldMiid;
let newMiid = evt.item.getAttribute("data-miid"); let newMiid = evt.item.getAttribute("data-miid");
console.log("newMiid",newMiid); log("newMiid",newMiid);
menuItems[evt.newIndex] = newMiid; menuItems[evt.newIndex] = newMiid;
console.log("post menuItems",menuItems); log("post menuItems",menuItems);
} }
}); });
document.getElementById("panel_menu_items_order_button").addEventListener("click", () => { document.getElementById("panel_menu_items_order_button").addEventListener("click", () => {
let req = new XMLHttpRequest(); let req = new XMLHttpRequest();
if(!req) { if(!req) {
console.log("Failed to create request"); log("Failed to create request");
return false; return false;
} }
req.onreadystatechange = () => { req.onreadystatechange = () => {
@ -32,7 +32,7 @@ document.getElementById("panel_menu_items_order_button").addEventListener("click
// TODO: Signal the error with a notice // TODO: Signal the error with a notice
if(req.status===200) { if(req.status===200) {
let resp = JSON.parse(req.responseText); let resp = JSON.parse(req.responseText);
console.log("resp",resp); log("resp",resp);
// TODO: Should we move other notices into TmplPhrases like this one? // TODO: Should we move other notices into TmplPhrases like this one?
pushNotice(phraseBox["panel"]["panel.themes_menus_items_order_updated"]); pushNotice(phraseBox["panel"]["panel.themes_menus_items_order_updated"]);
if(resp.success==1) return; if(resp.success==1) return;

View File

@ -8,7 +8,7 @@ function handle_profile_hashbit() {
hash_class = "delete_posts_hash"; hash_class = "delete_posts_hash";
break; break;
default: default:
console.log("Unknown hashbit"); log("Unknown hashbit");
return; return;
} }
$(".hash_hide").hide(); $(".hash_hide").hide();

View File

@ -3,12 +3,12 @@
fetch("/api/watches/") fetch("/api/watches/")
.then(resp => { .then(resp => {
if(resp.status!==200) { if(resp.status!==200) {
console.log("err"); log("err");
console.log("resp",resp); log("resp",resp);
return; return;
} }
resp.text().then(d => eval(d)); resp.text().then(d => eval(d));
}) })
.catch(e => console.log("e",e)); .catch(e => log("e",e));
}); });
})() })()

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
$(document).ready(() => { $(document).ready(() => {
let clickHandle = function(ev){ let clickHandle = function(ev){
console.log("in clickHandle") log("in clickHandle")
ev.preventDefault(); ev.preventDefault();
let ep = $(this).closest(".editable_parent"); let ep = $(this).closest(".editable_parent");
ep.find(".hide_on_block_edit").addClass("edit_opened"); ep.find(".hide_on_block_edit").addClass("edit_opened");
@ -36,7 +36,7 @@ $(document).ready(() => {
$(".wtype_sel").change(changeHandle); $(".wtype_sel").change(changeHandle);
$(".widget_new a").click(function(ev){ $(".widget_new a").click(function(ev){
console.log("clicked widget_new a") log("clicked widget_new a")
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");
@ -50,7 +50,7 @@ $(document).ready(() => {
}); });
$(".widget_save").click(function(ev){ $(".widget_save").click(function(ev){
console.log("in .widget_save") log("in .widget_save")
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
let pform = this.closest("form"); let pform = this.closest("form");

View File

@ -7,7 +7,7 @@
{{range .Header.PreScriptsAsync}} {{range .Header.PreScriptsAsync}}
<script async src="/s/{{.}}"></script>{{end}} <script async src="/s/{{.}}"></script>{{end}}
{{if .CurrentUser.Loggedin}}<meta property="x-mem"content="1">{{end}} {{if .CurrentUser.Loggedin}}<meta property="x-mem"content="1">{{end}}
<script src="/s/init.js?i=11"></script> <script src="/s/init.js?i=12"></script>
{{range .Header.ScriptsAsync}} {{range .Header.ScriptsAsync}}
<script async src="/s/{{.}}"></script>{{end}} <script async src="/s/{{.}}"></script>{{end}}
<script src="/s/jquery-3.1.1.min.js"></script> <script src="/s/jquery-3.1.1.min.js"></script>

View File

@ -66,7 +66,7 @@
// TODO: Refactor this to use `each` less // TODO: Refactor this to use `each` less
$('.button_menu').click(function(){ $('.button_menu').click(function(){
console.log(".button_menu"); log(".button_menu");
// The outer container // The outer container
let buttonPane = newElement("div","button_menu_pane"); let buttonPane = newElement("div","button_menu_pane");
let postItem = $(this).parents('.post_item'); let postItem = $(this).parents('.post_item');
@ -103,13 +103,13 @@
// Fill in the placeholder grid nodes // Fill in the placeholder grid nodes
let rowCount = 4; let rowCount = 4;
console.log("rowCount",rowCount); log("rowCount",rowCount);
console.log("gridElementCount",gridElementCount); 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); log("fillerNodes",fillerNodes);
for(let i = 0; i < fillerNodes;i++ ) { for(let i = 0; i < fillerNodes;i++ ) {
console.log("added a gridFiller"); log("added a gridFiller");
buttonGrid.appendChild(newElement("div","gridFiller")); buttonGrid.appendChild(newElement("div","gridFiller"));
} }
} }

View File

@ -36,24 +36,24 @@ function noxMenuBind() {
function moveAlerts() { function moveAlerts() {
// Move the alerts above the first header // Move the alerts above the first header
let colSel = $(".colstack_right .colstack_head:first"); let cSel = $(".colstack_right .colstack_head:first");
let colSelAlt = $(".colstack_right .colstack_item:first"); let cSelAlt = $(".colstack_right .colstack_item:first");
let colSelAltAlt = $(".colstack_right .coldyn_block:first"); let cSelAltAlt = $(".colstack_right .coldyn_block:first");
if(colSel.length > 0) $('.alert').insertBefore(colSel); if(cSel.length > 0) $('.alert').insertBefore(cSel);
else if (colSelAlt.length > 0) $('.alert').insertBefore(colSelAlt); else if (cSelAlt.length > 0) $('.alert').insertBefore(cSelAlt);
else if (colSelAltAlt.length > 0) $('.alert').insertBefore(colSelAltAlt); else if (cSelAltAlt.length > 0) $('.alert').insertBefore(cSelAltAlt);
else $('.alert').insertAfter(".rowhead:first"); else $('.alert').insertAfter(".rowhead:first");
} }
addInitHook("after_update_alert_list", alertCount => { addInitHook("after_update_alert_list", count => {
console.log("misc.js"); log("misc.js");
console.log("alertCount",alertCount); log("count",count);
if(alertCount==0) { if(count==0) {
$(".alerts").html(phraseBox["alerts"]["alerts.no_alerts_short"]); $(".alerts").html(phraseBox["alerts"]["alerts.no_alerts_short"]);
$(".user_box").removeClass("has_alerts"); $(".user_box").removeClass("has_alerts");
} else { } else {
// TODO: Localise this // TODO: Localise this
$(".alerts").html(alertCount + " new alerts"); $(".alerts").html(count+" new alerts");
$(".user_box").addClass("has_alerts"); $(".user_box").addClass("has_alerts");
} }
}); });
@ -63,7 +63,7 @@ function noxMenuBind() {
addInitHook("end_init", () => { addInitHook("end_init", () => {
$(".alerts").click(ev => { $(".alerts").click(ev => {
ev.stopPropagation(); ev.stopPropagation();
var alerts = $(".menu_alerts")[0]; let alerts = $(".menu_alerts")[0];
if($(alerts).hasClass("selectedAlert")) return; if($(alerts).hasClass("selectedAlert")) return;
if(!conn) loadAlerts(alerts); if(!conn) loadAlerts(alerts);
alerts.className += " selectedAlert"; alerts.className += " selectedAlert";

View File

@ -3,9 +3,9 @@ addInitHook("end_init", () => {
// TODO: Run this when the image is loaded rather than when the document is ready? // TODO: Run this when the image is loaded rather than when the document is ready?
$(".topic_list img").each(function(){ $(".topic_list img").each(function(){
let aspectRatio = this.naturalHeight / this.naturalWidth; let aspectRatio = this.naturalHeight / this.naturalWidth;
console.log("aspectRatio",aspectRatio); log("aspectRatio",aspectRatio);
console.log("height",this.naturalHeight); log("height",this.naturalHeight);
console.log("width",this.naturalWidth); log("width",this.naturalWidth);
$(this).css({ height: aspectRatio * this.width }); $(this).css({ height: aspectRatio * this.width });
}); });

View File

@ -3,9 +3,9 @@ addInitHook("end_init", () => {
// TODO: Run this when the image is loaded rather than when the document is ready? // TODO: Run this when the image is loaded rather than when the document is ready?
$(".topic_list img").each(function(){ $(".topic_list img").each(function(){
let aspectRatio = this.naturalHeight / this.naturalWidth; let aspectRatio = this.naturalHeight / this.naturalWidth;
console.log("aspectRatio",aspectRatio); log("aspectRatio",aspectRatio);
console.log("height",this.naturalHeight); log("height",this.naturalHeight);
console.log("width",this.naturalWidth); log("width",this.naturalWidth);
$(this).css({ height: aspectRatio * this.width }); $(this).css({ height: aspectRatio * this.width });
}); });