experiment with fixing ajax topics link
This commit is contained in:
parent
6746c9c91b
commit
ef7af76e91
|
@ -24,11 +24,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,er) {
|
||||
function ajaxError(xhr,status,e) {
|
||||
console.log("The AJAX request failed");
|
||||
console.log("xhr",xhr);
|
||||
console.log("status",status);
|
||||
console.log("er",er);
|
||||
console.log("e",e);
|
||||
if(status=="parsererror") console.log("The server didn't respond with a valid JSON response");
|
||||
console.trace();
|
||||
}
|
||||
|
@ -518,10 +518,11 @@ function mainInit(){
|
|||
}
|
||||
|
||||
function rebindPaginator() {
|
||||
$(".pageitem a").unbind("click");
|
||||
$(".pageitem a").click(function() {
|
||||
event.preventDefault();
|
||||
// TODO: Take mostviewed into account
|
||||
// TODO: Get this to work with topics too
|
||||
$(".pageitem a").unbind("click");
|
||||
$(".pageitem a").click(function(ev) {
|
||||
ev.preventDefault();
|
||||
let url = "//"+window.location.host+window.location.pathname;
|
||||
let urlParams = new URLSearchParams(window.location.search);
|
||||
urlParams.set("page",new URLSearchParams(this.getAttribute("href")).get("page"));
|
||||
|
@ -549,8 +550,7 @@ function mainInit(){
|
|||
rebuildPaginator(dat.LastPage);
|
||||
rebindPaginator();
|
||||
}).catch(e => {
|
||||
console.log("Unable to get script '"+url+q+"&js=1"+"'");
|
||||
console.log("e",e);
|
||||
console.log("Unable to get script '"+url+q+"&js=1"+"'",e);
|
||||
console.trace();
|
||||
});
|
||||
});
|
||||
|
@ -607,6 +607,7 @@ function mainInit(){
|
|||
// TODO: Show a search button when JS is disabled?
|
||||
$(".widget_search_input").keypress(function(e) {
|
||||
if(e.keyCode!='13') return;
|
||||
// TODO: Only fire on /topics/
|
||||
event.preventDefault();
|
||||
// TODO: Take mostviewed into account
|
||||
let url = "//"+window.location.host+window.location.pathname;
|
||||
|
@ -762,15 +763,6 @@ function mainInit(){
|
|||
|
||||
$("input,textarea,select,option").keyup(ev => ev.stopPropagation())
|
||||
|
||||
$(".create_topic_link").click(ev => {
|
||||
ev.preventDefault();
|
||||
$(".topic_create_form").removeClass("auto_hide");
|
||||
});
|
||||
$(".topic_create_form .close_form").click(ev => {
|
||||
ev.preventDefault();
|
||||
$(".topic_create_form").addClass("auto_hide");
|
||||
});
|
||||
|
||||
$("#themeSelectorSelect").change(function(){
|
||||
console.log("Changing the theme to "+this.options[this.selectedIndex].getAttribute("value"));
|
||||
$.ajax({
|
||||
|
@ -872,7 +864,7 @@ function mainInit(){
|
|||
return name.split('?')[0];
|
||||
}
|
||||
|
||||
function loadArb(base,href) {
|
||||
function loadArb(base,href,h = null) {
|
||||
fetch(href,{credentials:"same-origin"})
|
||||
.then(resp => {
|
||||
if(!resp.ok) throw(href+" failed to load");
|
||||
|
@ -892,8 +884,7 @@ function mainInit(){
|
|||
return resp.text();
|
||||
}).then(dat => {
|
||||
document.querySelector("#back").outerHTML = dat;
|
||||
unbindTopic();
|
||||
bindTopic();
|
||||
if(h!==null) h(dat);
|
||||
$(".elapsed").remove();
|
||||
let obj = {Title:document.title,Url:base};
|
||||
history.pushState(obj,obj.Title,obj.Url);
|
||||
|
@ -905,14 +896,20 @@ function mainInit(){
|
|||
|
||||
$(".rowtopic a,a.rowtopic,a.forum_poster").click(function(ev) {
|
||||
let base = this.getAttribute("href");
|
||||
loadArb(base,base+"?i=1");
|
||||
loadArb(base,base+"?i=1", () => {
|
||||
unbindTopic();
|
||||
bindTopic();
|
||||
});
|
||||
ev.stopPropagation();
|
||||
ev.preventDefault();
|
||||
})
|
||||
$("a").click(function(ev) {
|
||||
let base = this.getAttribute("href");
|
||||
if(base!="/topics/") return;
|
||||
loadArb(base,base+"?i=1");
|
||||
loadArb(base,base+"?i=1", () => {
|
||||
unbindPage();
|
||||
bindPage();
|
||||
});
|
||||
ev.stopPropagation();
|
||||
ev.preventDefault();
|
||||
})
|
||||
|
@ -922,10 +919,21 @@ function mainInit(){
|
|||
}
|
||||
|
||||
function bindPage() {
|
||||
$(".create_topic_link").click(ev => {
|
||||
ev.preventDefault();
|
||||
$(".topic_create_form").removeClass("auto_hide");
|
||||
});
|
||||
$(".topic_create_form .close_form").click(ev => {
|
||||
ev.preventDefault();
|
||||
$(".topic_create_form").addClass("auto_hide");
|
||||
});
|
||||
|
||||
bindTopic();
|
||||
}
|
||||
|
||||
function unbindPage() {
|
||||
$(".create_topic_link").unbind("click");
|
||||
$(".topic_create_form .close_form").unbind("click");
|
||||
unbindTopic();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue