accelerate other view topic entrypoints

This commit is contained in:
Azareal 2020-04-11 07:48:30 +10:00
parent 5a9e0c72d3
commit 3d87ad8895
2 changed files with 46 additions and 44 deletions

View File

@ -6,8 +6,8 @@ var alertCount=0;
var moreTopicCount=0; var moreTopicCount=0;
var conn=false; var conn=false;
var selectedTopics=[]; var selectedTopics=[];
var attachItemCallback=function(){} var attachItemCallback=()=>{}
var quoteItemCallback=function(){} var quoteItemCallback=()=>{}
var baseTitle=document.title; var baseTitle=document.title;
var wsBackoff=0; var wsBackoff=0;
var noAlerts=false; var noAlerts=false;
@ -36,7 +36,7 @@ function ajaxError(xhr,status,er) {
function postLink(ev) { function postLink(ev) {
ev.preventDefault(); ev.preventDefault();
let formAction = $(ev.target).closest('a').attr("href"); let formAction = $(ev.target).closest('a').attr("href");
$.ajax({ url: formAction, type: "POST", dataType: "json", error: ajaxError, data: {js: 1} }); $.ajax({ url:formAction, type:"POST", dataType:"json", error: ajaxError, data: {js: 1} });
} }
function bindToAlerts() { function bindToAlerts() {
@ -62,7 +62,7 @@ function addAlert(msg,notice=false) {
var mmsg = msg.msg; var mmsg = msg.msg;
if(mmsg[0]==".") mmsg = phraseBox["alerts"]["alerts"+mmsg]; if(mmsg[0]==".") mmsg = phraseBox["alerts"]["alerts"+mmsg];
if("sub" in msg) { if("sub" in msg) {
for(var i=0; i<msg.sub.length; i++) mmsg = mmsg.replace("\{"+i+"\}", msg.sub[i]); for(var i=0; i<msg.sub.length; i++) mmsg = mmsg.replace("\{"+i+"\}",msg.sub[i]);
} }
let aItem = Tmpl_alert({ let aItem = Tmpl_alert({
@ -189,14 +189,14 @@ function SplitN(data,ch,n) {
var j = 0; var j = 0;
var lastN = 1; var lastN = 1;
for(let i=0; i<data.length; i++) { for(let i=0; i<data.length; i++) {
if(data[i] === ch) { if(data[i]===ch) {
o[j++] = data.substring(lastI,i); o[j++] = data.substring(lastI,i);
lastI = i; lastI = i;
if(lastN === n) break; if(lastN===n) break;
lastN++; lastN++;
} }
} }
if(data.length > lastI) o[o.length - 1] += data.substring(lastI); if(data.length > lastI) o[o.length-1] += data.substring(lastI);
return o; return o;
} }
@ -544,7 +544,7 @@ function mainInit(){
for(let i=0; i<topics.length;i++) out += Tmpl_topics_topic(topics[i]); for(let i=0; i<topics.length;i++) out += Tmpl_topics_topic(topics[i]);
$(".topic_list").html(out); $(".topic_list").html(out);
let obj = {Title:document.title, Url:url+q}; let obj = {Title:document.title,Url:url+q};
history.pushState(obj,obj.Title,obj.Url); history.pushState(obj,obj.Title,obj.Url);
rebuildPaginator(dat.LastPage); rebuildPaginator(dat.LastPage);
rebindPaginator(); rebindPaginator();
@ -584,8 +584,8 @@ function mainInit(){
baseTitle = that.innerText; baseTitle = that.innerText;
if(alertCount > 0) document.title = "("+alertCount+") "+baseTitle; if(alertCount > 0) document.title = "("+alertCount+") "+baseTitle;
else document.title = baseTitle; else document.title = baseTitle;
let obj = {Title: document.title, Url: url}; let obj = {Title:document.title,Url:url};
history.pushState(obj, obj.Title, obj.Url); history.pushState(obj,obj.Title,obj.Url);
rebuildPaginator(dat.LastPage) rebuildPaginator(dat.LastPage)
rebindPaginator(); rebindPaginator();
@ -628,7 +628,7 @@ function mainInit(){
// 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 = "";
for(let i=0; i < topics.length;i++) out += Tmpl_topics_topic(topics[i]); for(let i=0;i<topics.length;i++) out += Tmpl_topics_topic(topics[i]);
$(".topic_list").html(out); $(".topic_list").html(out);
baseTitle = phraseBox["topic_list"]["topic_list.search_head"]; baseTitle = phraseBox["topic_list"]["topic_list.search_head"];
@ -636,7 +636,7 @@ function mainInit(){
if(alertCount > 0) document.title = "("+alertCount+") "+baseTitle; if(alertCount > 0) document.title = "("+alertCount+") "+baseTitle;
else document.title = baseTitle; else document.title = baseTitle;
let obj = {Title: document.title, Url: url+q}; let obj = {Title: document.title, Url: url+q};
history.pushState(obj, obj.Title, obj.Url); history.pushState(obj,obj.Title,obj.Url);
rebuildPaginator(data.LastPage); rebuildPaginator(data.LastPage);
rebindPaginator(); rebindPaginator();
}).catch(e => { }).catch(e => {
@ -652,7 +652,7 @@ function mainInit(){
ev.preventDefault(); ev.preventDefault();
let bp = $(this).closest('.editable_parent'); let bp = $(this).closest('.editable_parent');
let block = bp.find('.editable_block').eq(0); let block = bp.find('.editable_block').eq(0);
block.html("<input name='edit_field'value='" + block.text() + "' type='text'><a href='" + $(this).closest('a').attr("href") + "'><button class='submit_edit'type='submit'>Update</button></a>"); block.html("<input name='edit_field'value='"+block.text()+"' type='text'><a href='"+$(this).closest('a').attr("href")+"'><button class='submit_edit'type='submit'>Update</button></a>");
$(".submit_edit").click(function(ev) { $(".submit_edit").click(function(ev) {
ev.preventDefault(); ev.preventDefault();
@ -774,7 +774,7 @@ function mainInit(){
$("#themeSelectorSelect").change(function(){ $("#themeSelectorSelect").change(function(){
console.log("Changing the theme to "+this.options[this.selectedIndex].getAttribute("value")); console.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",
dataType:"json", dataType:"json",
data: { "theme": this.options[this.selectedIndex].getAttribute("value"), js: 1 }, data: { "theme": this.options[this.selectedIndex].getAttribute("value"), js: 1 },
@ -793,14 +793,14 @@ function mainInit(){
$(".autoSubmitRedirect").change(function(){ $(".autoSubmitRedirect").change(function(){
let elems = this.form.elements; let elems = this.form.elements;
let s = ""; let s = "";
for(let i = 0; i < elems.length; i++) { for(let i=0; i<elems.length; i++) {
let elem = elems[i]; let elem = elems[i];
if(elem.nodeName=="SELECT") { if(elem.nodeName=="SELECT") {
s += elem.name + "=" + elem.options[elem.selectedIndex].getAttribute("value") + "&"; s += elem.name+"="+elem.options[elem.selectedIndex].getAttribute("value")+"&";
} }
// TODO: Implement other element types... // TODO: Implement other element types...
} }
if(s.length > 0) s = "?" + s.substr(0, s.length-1); if(s.length > 0) s = "?"+s.substr(0, s.length-1);
window.location = this.form.getAttribute("action") + s; // Do a redirect as a form submission refuses to work properly window.location = this.form.getAttribute("action") + s; // Do a redirect as a form submission refuses to work properly
}); });
@ -809,8 +809,8 @@ function mainInit(){
let unixTime = this.innerText; let unixTime = this.innerText;
let date = new Date(unixTime*1000); let date = new Date(unixTime*1000);
console.log("date",date); console.log("date",date);
let minutes = "0" + date.getMinutes(); let minutes = "0"+date.getMinutes();
let formattedTime = date.getHours() + ":" + minutes.substr(-2); let formattedTime = date.getHours()+":"+minutes.substr(-2);
console.log("formattedTime",formattedTime); console.log("formattedTime",formattedTime);
this.innerText = formattedTime; this.innerText = formattedTime;
}); });
@ -820,8 +820,8 @@ function mainInit(){
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); console.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); console.log("formattedTime",formattedTime);
this.innerText = formattedTime; this.innerText = formattedTime;
}); });
@ -872,15 +872,13 @@ function mainInit(){
return name.split('?')[0]; return name.split('?')[0];
} }
$(".rowtopic a,a.rowtopic").click(function(ev) { function loadArb(base,href) {
let base = this.getAttribute("href"); fetch(href,{credentials:"same-origin"})
let href = base + "?i=1";
fetch(href, {credentials:"same-origin"})
.then(resp => { .then(resp => {
if(!resp.ok) throw(href+" failed to load"); if(!resp.ok) throw(href+" failed to load");
let xRes = resp.headers.get("x-res") let xr = resp.headers.get("x-res")
if(xRes!=null) { if(xr!=null) {
for(let res of xRes.split(",")) { for(let res of xr.split(",")) {
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)
@ -893,19 +891,23 @@ function mainInit(){
} }
} }
return resp.text(); return resp.text();
}).then(data => { }).then(dat => {
document.querySelector("#back").outerHTML = data; document.querySelector("#back").outerHTML = dat;
unbindTopic(); unbindTopic();
bindTopic(); bindTopic();
$(".elapsed").remove(); $(".elapsed").remove();
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+""+"'"); console.log("Unable to get script '"+href+""+"'");
console.log("e",e); console.log("e",e);
console.trace(); console.trace();
}); });
}
$(".rowtopic a,a.rowtopic,a.forum_poster").click(function(ev) {
let base = this.getAttribute("href");
loadArb(base,base+"?i=1");
ev.stopPropagation(); ev.stopPropagation();
ev.preventDefault(); ev.preventDefault();
}) })
@ -1012,9 +1014,9 @@ function bindTopic() {
$(bp).find('.hide_on_block_edit').removeClass("edit_opened"); $(bp).find('.hide_on_block_edit').removeClass("edit_opened");
$(bp).find('.show_on_block_edit').removeClass("edit_opened"); $(bp).find('.show_on_block_edit').removeClass("edit_opened");
block.classList.remove("in_edit"); block.classList.remove("in_edit");
let content = block.querySelector('textarea').value; let con = block.querySelector('textarea').value;
block.innerHTML = quickParse(content); block.innerHTML = quickParse(con);
if(srcNode!=null) srcNode.innerText = content; if(srcNode!=null) srcNode.innerText = con;
let formAction = this.closest('a').getAttribute("href"); let formAction = this.closest('a').getAttribute("href");
// TODO: Bounce the parsed post back and set innerHTML to it? // TODO: Bounce the parsed post back and set innerHTML to it?
@ -1022,7 +1024,7 @@ function bindTopic() {
url: formAction, url: formAction,
type:"POST", type:"POST",
dataType:"json", dataType:"json",
data: { js: 1, edit_item: content }, data: { js: 1, edit_item: con },
error: ajaxError, error: ajaxError,
success: (dat,status,xhr) => { success: (dat,status,xhr) => {
if("Content" in dat) block.innerHTML = dat["Content"]; if("Content" in dat) block.innerHTML = dat["Content"];
@ -1035,14 +1037,14 @@ function bindTopic() {
ev.preventDefault(); ev.preventDefault();
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 content = document.getElementById("input_content") let con = document.getElementById("input_content")
console.log("content.value",content.value); console.log("con.value",con.value);
let item; let item;
if(content.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>";
content.value = content.value + item; con.value = con.value+item;
console.log("content.value",content.value); console.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);
@ -1054,7 +1056,7 @@ function bindTopic() {
$("#poll_results_"+pollID).removeClass("auto_hide"); $("#poll_results_"+pollID).removeClass("auto_hide");
fetch("/poll/results/"+pollID, { fetch("/poll/results/"+pollID, {
credentials: 'same-origin' credentials: 'same-origin'
}).then(resp => resp.text()).catch(er => console.error("er",er)).then(rawData => { }).then(resp => resp.text()).catch(e => console.error("e",e)).then(rawData => {
// TODO: Make sure the received data is actually a list of integers // TODO: Make sure the received data is actually a list of integers
let data = JSON.parse(rawData); let data = JSON.parse(rawData);
let allZero = true; let allZero = true;

View File

@ -18,7 +18,7 @@
<span class="forum_right shift_right"> <span class="forum_right shift_right">
{{if .LastReplyer.MicroAvatar}}<img class="extra_little_row_avatar"src="{{.LastReplyer.MicroAvatar}}"height=64 width=64 alt="Avatar"title="{{.LastReplyer.Name}}'s Avatar"aria-hidden="true">{{end}} {{if .LastReplyer.MicroAvatar}}<img class="extra_little_row_avatar"src="{{.LastReplyer.MicroAvatar}}"height=64 width=64 alt="Avatar"title="{{.LastReplyer.Name}}'s Avatar"aria-hidden="true">{{end}}
<span> <span>
<a {{if .LastTopic.Link}}href="{{.LastTopic.Link}}"{{else}}class="forum_no_poster"{{end}}>{{if .LastTopic.Title}}{{.LastTopic.Title}}{{else}}{{lang "forums_none"}}{{end}}</a> <a {{if .LastTopic.Link}}class="forum_poster"href="{{.LastTopic.Link}}"{{else}}class="forum_no_poster"{{end}}>{{if .LastTopic.Title}}{{.LastTopic.Title}}{{else}}{{lang "forums_none"}}{{end}}</a>
{{if .LastTopicTime}}<br><span class="rowsmall"title="{{abstime .LastTopic.LastReplyAt}}">{{.LastTopicTime}}</span>{{end}} {{if .LastTopicTime}}<br><span class="rowsmall"title="{{abstime .LastTopic.LastReplyAt}}">{{.LastTopicTime}}</span>{{end}}
</span> </span>
</span><div style="clear:both;"></div> </span><div style="clear:both;"></div>