avoid loading alerts in the panel in nox
This commit is contained in:
parent
2b904b8b76
commit
670b6186b5
|
@ -10,6 +10,7 @@ var attachItemCallback = function(){}
|
||||||
var quoteItemCallback = function(){}
|
var quoteItemCallback = function(){}
|
||||||
var baseTitle = document.title;
|
var baseTitle = document.title;
|
||||||
var wsBackoff = 0;
|
var wsBackoff = 0;
|
||||||
|
var noAlerts = false;
|
||||||
|
|
||||||
// Topic move
|
// Topic move
|
||||||
var forumToMoveTo = 0;
|
var forumToMoveTo = 0;
|
||||||
|
@ -32,18 +33,18 @@ function ajaxError(xhr,status,errstr) {
|
||||||
console.trace();
|
console.trace();
|
||||||
}
|
}
|
||||||
|
|
||||||
function postLink(event) {
|
function postLink(ev) {
|
||||||
event.preventDefault();
|
ev.preventDefault();
|
||||||
let formAction = $(event.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() {
|
||||||
console.log("bindToAlerts");
|
console.log("bindToAlerts");
|
||||||
$(".alertItem.withAvatar a").unbind("click");
|
$(".alertItem.withAvatar a").unbind("click");
|
||||||
$(".alertItem.withAvatar a").click(function(event) {
|
$(".alertItem.withAvatar a").click(function(ev) {
|
||||||
event.stopPropagation();
|
ev.stopPropagation();
|
||||||
event.preventDefault();
|
ev.preventDefault();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/api/?action=set&module=dismiss-alert",
|
url: "/api/?action=set&module=dismiss-alert",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
|
@ -149,14 +150,14 @@ 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.count);
|
||||||
for(var i in data.msgs) addAlert(data.msgs[i]);
|
for(var i in data.msgs) addAlert(data.msgs[i]);
|
||||||
console.log("data.count:",data.count);
|
|
||||||
alertCount = data.count;
|
alertCount = data.count;
|
||||||
updateAlertList(menuAlerts);
|
updateAlertList(menuAlerts);
|
||||||
//}
|
//}
|
||||||
lastTc = data.tc;
|
lastTc = data.tc;
|
||||||
},
|
},
|
||||||
error: (magic,theStatus,error) => {
|
error: (magic,theStatus,err) => {
|
||||||
let errtxt = "Unable to get the alerts";
|
let errtxt = "Unable to get the alerts";
|
||||||
try {
|
try {
|
||||||
var data = JSON.parse(magic.responseText);
|
var data = JSON.parse(magic.responseText);
|
||||||
|
@ -165,7 +166,7 @@ function loadAlerts(menuAlerts, eTc = false) {
|
||||||
console.log(magic.responseText);
|
console.log(magic.responseText);
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
console.log("error", error);
|
console.log("err", err);
|
||||||
setAlertError(menuAlerts,errtxt);
|
setAlertError(menuAlerts,errtxt);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -175,18 +176,18 @@ function SplitN(data,ch,n) {
|
||||||
var out = [];
|
var out = [];
|
||||||
if(data.length === 0) return out;
|
if(data.length === 0) return out;
|
||||||
|
|
||||||
var lastIndex = 0;
|
var lastI = 0;
|
||||||
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) {
|
||||||
out[j++] = data.substring(lastIndex,i);
|
out[j++] = data.substring(lastI,i);
|
||||||
lastIndex = i;
|
lastI = i;
|
||||||
if(lastN === n) break;
|
if(lastN === n) break;
|
||||||
lastN++;
|
lastN++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(data.length > lastIndex) out[out.length - 1] += data.substring(lastIndex);
|
if(data.length > lastI) out[out.length - 1] += data.substring(lastI);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,8 +235,10 @@ function runWebSockets(resume = false) {
|
||||||
wsBackoff++;
|
wsBackoff++;
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
var alertMenuList = document.getElementsByClassName("menu_alerts");
|
if(!noAlerts) {
|
||||||
for(var i = 0; i < alertMenuList.length; i++) loadAlerts(alertMenuList[i]);
|
var alertMenuList = document.getElementsByClassName("menu_alerts");
|
||||||
|
for(var i=0; i < alertMenuList.length; i++) loadAlerts(alertMenuList[i]);
|
||||||
|
}
|
||||||
runWebSockets(true);
|
runWebSockets(true);
|
||||||
}, backoff * 60 * 1000);
|
}, backoff * 60 * 1000);
|
||||||
|
|
||||||
|
@ -247,7 +250,7 @@ function runWebSockets(resume = false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.onmessage = (event) => {
|
conn.onmessage = (event) => {
|
||||||
if(event.data[0] == "{") {
|
if(!noAlerts && event.data[0] == "{") {
|
||||||
console.log("json message");
|
console.log("json message");
|
||||||
let data = "";
|
let data = "";
|
||||||
try {
|
try {
|
||||||
|
@ -264,7 +267,7 @@ function runWebSockets(resume = false) {
|
||||||
if(key!=data.id) return;
|
if(key!=data.id) return;
|
||||||
alertCount--;
|
alertCount--;
|
||||||
let index = -1;
|
let index = -1;
|
||||||
for(var i = 0; i < alertList.length; i++) {
|
for(var i=0; i < alertList.length; i++) {
|
||||||
if(alertList[i]==key) {
|
if(alertList[i]==key) {
|
||||||
alertList[i] = 0;
|
alertList[i] = 0;
|
||||||
index = i;
|
index = i;
|
||||||
|
@ -286,7 +289,7 @@ function runWebSockets(resume = false) {
|
||||||
}
|
}
|
||||||
} else if("Topics" in data) {
|
} else if("Topics" in data) {
|
||||||
console.log("topic in data");
|
console.log("topic in data");
|
||||||
console.log("data:", data);
|
console.log("data", data);
|
||||||
let topic = data.Topics[0];
|
let topic = data.Topics[0];
|
||||||
if(topic === undefined){
|
if(topic === undefined){
|
||||||
console.log("empty topic list");
|
console.log("empty topic list");
|
||||||
|
@ -303,7 +306,7 @@ function runWebSockets(resume = false) {
|
||||||
moreTopicCount++;
|
moreTopicCount++;
|
||||||
|
|
||||||
let moreTopicBlocks = document.getElementsByClassName("more_topic_block_initial");
|
let moreTopicBlocks = document.getElementsByClassName("more_topic_block_initial");
|
||||||
for(let i = 0; i < moreTopicBlocks.length; i++) {
|
for(let i=0; i < moreTopicBlocks.length; i++) {
|
||||||
let moreTopicBlock = moreTopicBlocks[i];
|
let moreTopicBlock = moreTopicBlocks[i];
|
||||||
moreTopicBlock.classList.remove("more_topic_block_initial");
|
moreTopicBlock.classList.remove("more_topic_block_initial");
|
||||||
moreTopicBlock.classList.add("more_topic_block_active");
|
moreTopicBlock.classList.add("more_topic_block_active");
|
||||||
|
@ -319,7 +322,7 @@ function runWebSockets(resume = false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var messages = event.data.split('\r');
|
var 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);
|
//console.log("Message: ",message);
|
||||||
let msgblocks = SplitN(message," ",3);
|
let msgblocks = SplitN(message," ",3);
|
||||||
|
@ -342,6 +345,7 @@ function runWebSockets(resume = false) {
|
||||||
addInitHook("pre_init", () => {
|
addInitHook("pre_init", () => {
|
||||||
console.log("before notify on alert")
|
console.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) {
|
||||||
notifyOnScriptW("template_alert", (e) => {
|
notifyOnScriptW("template_alert", (e) => {
|
||||||
if(e!=undefined) console.log("failed alert? why?", e)
|
if(e!=undefined) console.log("failed alert? why?", e)
|
||||||
}, () => {
|
}, () => {
|
||||||
|
@ -356,6 +360,13 @@ function runWebSockets(resume = false) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
addInitHook("after_phrases", () => {
|
||||||
|
$(document).ready(() => {
|
||||||
|
if(window["WebSocket"]) runWebSockets();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$(document).ready(mainInit);
|
$(document).ready(mainInit);
|
||||||
});
|
});
|
||||||
|
@ -397,8 +408,8 @@ function Paginate(currentPage, lastPage, maxPages) {
|
||||||
function mainInit(){
|
function mainInit(){
|
||||||
runInitHook("start_init");
|
runInitHook("start_init");
|
||||||
|
|
||||||
$(".more_topics").click((event) => {
|
$(".more_topics").click((ev) => {
|
||||||
event.preventDefault();
|
ev.preventDefault();
|
||||||
let moreTopicBlocks = document.getElementsByClassName("more_topic_block_active");
|
let moreTopicBlocks = document.getElementsByClassName("more_topic_block_active");
|
||||||
for(let i = 0; i < moreTopicBlocks.length; i++) {
|
for(let i = 0; i < moreTopicBlocks.length; i++) {
|
||||||
let block = moreTopicBlocks[i];
|
let block = moreTopicBlocks[i];
|
||||||
|
@ -416,7 +427,7 @@ function mainInit(){
|
||||||
event.preventDefault();
|
event.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);
|
console.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");
|
||||||
|
@ -833,23 +844,23 @@ function mainInit(){
|
||||||
$("#back").removeClass("alertActive");
|
$("#back").removeClass("alertActive");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$(".menu_alerts").click(function(event) {
|
$(".menu_alerts").click(function(ev) {
|
||||||
event.stopPropagation();
|
ev.stopPropagation();
|
||||||
if($(this).hasClass("selectedAlert")) return;
|
if($(this).hasClass("selectedAlert")) return;
|
||||||
if(!conn) loadAlerts(this);
|
if(!conn) loadAlerts(this);
|
||||||
this.className += " selectedAlert";
|
this.className += " selectedAlert";
|
||||||
document.getElementById("back").className += " alertActive"
|
document.getElementById("back").className += " alertActive"
|
||||||
});
|
});
|
||||||
$(".link_select").click(event => event.stopPropagation());
|
$(".link_select").click(ev => ev.stopPropagation());
|
||||||
|
|
||||||
$("input,textarea,select,option").keyup(event => event.stopPropagation())
|
$("input,textarea,select,option").keyup(ev => ev.stopPropagation())
|
||||||
|
|
||||||
$(".create_topic_link").click((event) => {
|
$(".create_topic_link").click(ev => {
|
||||||
event.preventDefault();
|
ev.preventDefault();
|
||||||
$(".topic_create_form").removeClass("auto_hide");
|
$(".topic_create_form").removeClass("auto_hide");
|
||||||
});
|
});
|
||||||
$(".topic_create_form .close_form").click((event) => {
|
$(".topic_create_form .close_form").click(ev => {
|
||||||
event.preventDefault();
|
ev.preventDefault();
|
||||||
$(".topic_create_form").addClass("auto_hide");
|
$(".topic_create_form").addClass("auto_hide");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -861,7 +872,7 @@ function mainInit(){
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
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 (data, status, xhr) {
|
success: function (data,status,xhr) {
|
||||||
console.log("Theme successfully switched");
|
console.log("Theme successfully switched");
|
||||||
console.log("data", data);
|
console.log("data", data);
|
||||||
console.log("status", status);
|
console.log("status", status);
|
||||||
|
@ -909,16 +920,16 @@ function mainInit(){
|
||||||
});
|
});
|
||||||
|
|
||||||
$("spoiler").addClass("hide_spoil");
|
$("spoiler").addClass("hide_spoil");
|
||||||
$(".hide_spoil").click(function(event) {
|
$(".hide_spoil").click(function(ev) {
|
||||||
event.stopPropagation();
|
ev.stopPropagation();
|
||||||
event.preventDefault();
|
ev.preventDefault();
|
||||||
$(this).removeClass("hide_spoil");
|
$(this).removeClass("hide_spoil");
|
||||||
$(this).unbind("click");
|
$(this).unbind("click");
|
||||||
});
|
});
|
||||||
|
|
||||||
this.onkeyup = function(event) {
|
this.onkeyup = function(ev) {
|
||||||
if(event.which == 37) this.querySelectorAll("#prevFloat a")[0].click();
|
if(ev.which == 37) this.querySelectorAll("#prevFloat a")[0].click();
|
||||||
if(event.which == 39) this.querySelectorAll("#nextFloat a")[0].click();
|
if(ev.which == 39) this.querySelectorAll("#nextFloat a")[0].click();
|
||||||
};
|
};
|
||||||
|
|
||||||
//id="poll_results_{{.Poll.ID}}" class="poll_results auto_hide"
|
//id="poll_results_{{.Poll.ID}}" class="poll_results auto_hide"
|
||||||
|
@ -935,15 +946,15 @@ function mainInit(){
|
||||||
if(data[i] != "0") allZero = false;
|
if(data[i] != "0") allZero = false;
|
||||||
}
|
}
|
||||||
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")
|
console.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);
|
console.log("rawData: ", rawData);
|
||||||
console.log("series: ", data);
|
console.log("series: ", data);
|
||||||
Chartist.Pie('#poll_results_chart_' + pollID, {
|
Chartist.Pie('#poll_results_chart_'+pollID, {
|
||||||
series: data,
|
series: data,
|
||||||
}, {
|
}, {
|
||||||
height: '120px',
|
height: '120px',
|
||||||
|
|
|
@ -176,7 +176,7 @@ function RelativeTime(date) {
|
||||||
|
|
||||||
function initPhrases(loggedIn, panel = false) {
|
function initPhrases(loggedIn, panel = false) {
|
||||||
console.log("in initPhrases")
|
console.log("in initPhrases")
|
||||||
console.log("tmlInits:",tmplInits)
|
console.log("tmlInits",tmplInits)
|
||||||
let e = "";
|
let e = "";
|
||||||
if(loggedIn && !panel) e = ",status,topic_list,topic";
|
if(loggedIn && !panel) e = ",status,topic_list,topic";
|
||||||
else if(panel) e = ",analytics,panel"; // TODO: Request phrases for just one section of the control panel?
|
else if(panel) e = ",analytics,panel"; // TODO: Request phrases for just one section of the control panel?
|
||||||
|
|
|
@ -29,8 +29,7 @@ func StaticFile(w http.ResponseWriter, r *http.Request) {
|
||||||
h := w.Header()
|
h := w.Header()
|
||||||
|
|
||||||
if file.Length > 300 {
|
if file.Length > 300 {
|
||||||
rangeHead := h.Get("Range")
|
if h.Get("Range") != "" {
|
||||||
if rangeHead != "" {
|
|
||||||
if file.GzipLength > 300 && strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
|
if file.GzipLength > 300 && strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
|
||||||
if len(file.Sha256) != 0 {
|
if len(file.Sha256) != 0 {
|
||||||
h.Set("Cache-Control", cacheControlMaxAgeWeek)
|
h.Set("Cache-Control", cacheControlMaxAgeWeek)
|
||||||
|
|
|
@ -30,6 +30,10 @@ function noxMenuBind() {
|
||||||
}
|
}
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
|
if(window.location.pathname.startsWith("/panel/")) {
|
||||||
|
addInitHook("pre_init", () => noAlerts = true);
|
||||||
|
}
|
||||||
|
|
||||||
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 colSel = $(".colstack_right .colstack_head:first");
|
||||||
|
@ -43,7 +47,7 @@ function noxMenuBind() {
|
||||||
|
|
||||||
addInitHook("after_update_alert_list", (alertCount) => {
|
addInitHook("after_update_alert_list", (alertCount) => {
|
||||||
console.log("misc.js");
|
console.log("misc.js");
|
||||||
console.log("alertCount:",alertCount);
|
console.log("alertCount",alertCount);
|
||||||
if(alertCount==0) {
|
if(alertCount==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");
|
||||||
|
@ -53,12 +57,13 @@ function noxMenuBind() {
|
||||||
$(".user_box").addClass("has_alerts");
|
$(".user_box").addClass("has_alerts");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
addHook("open_edit", () => $('.topic_block').addClass("edithead"));
|
let tb=$('.topic_block');
|
||||||
addHook("close_edit", () => $('.topic_block').removeClass("edithead"));
|
addHook("open_edit", () => tb.addClass("edithead"));
|
||||||
|
addHook("close_edit", () => tb.removeClass("edithead"));
|
||||||
|
|
||||||
addInitHook("end_init", () => {
|
addInitHook("end_init", () => {
|
||||||
$(".alerts").click((event) => {
|
$(".alerts").click(ev => {
|
||||||
event.stopPropagation();
|
ev.stopPropagation();
|
||||||
var alerts = $(".menu_alerts")[0];
|
var alerts = $(".menu_alerts")[0];
|
||||||
if($(alerts).hasClass("selectedAlert")) return;
|
if($(alerts).hasClass("selectedAlert")) return;
|
||||||
if(!conn) loadAlerts(alerts);
|
if(!conn) loadAlerts(alerts);
|
||||||
|
|
Loading…
Reference in New Issue