mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 09:15:33 +00:00
JavaScript Refactor p1
This commit is contained in:
@@ -9,9 +9,9 @@ using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
List<string> configpaths = new List<string>();
|
||||
|
||||
// Add additional configuration
|
||||
List<string> configpaths = new List<string>();
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
|
||||
var p = builder.Configuration.GetValue<string>("WorkingTreePathWindows") + "settings.json";
|
||||
configpaths.Add(p);
|
||||
@@ -38,6 +38,8 @@ builder.Services.AddSingleton<IXMLFileProvider, XMLFileProvider>(_ => XMLFP);
|
||||
builder.Services.AddSingleton<WebSocketMiddleware>();
|
||||
builder.Services.AddTransient<IReaderService, ReaderService>();
|
||||
builder.Services.AddFeatureManagement();
|
||||
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Reload config on change
|
||||
@@ -48,12 +50,13 @@ ChangeToken.OnChange(
|
||||
app.Environment
|
||||
);
|
||||
|
||||
// Websockets for realtime notification of changes
|
||||
app.UseWebSockets( new WebSocketOptions {
|
||||
KeepAliveInterval = TimeSpan.FromMinutes(180),
|
||||
});
|
||||
app.UseMiddleware<WebSocketMiddleware>();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
// Production Options
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Gives active classes to links with active URLs
|
||||
// Marks links as active which target URL starts with the current URL
|
||||
const markactive_startswith = function (element) {
|
||||
const startup_active = function () {
|
||||
// Gives active classes to links with active URLs
|
||||
// Marks links as active which target URL starts with the current URL
|
||||
const markactive_startswith = function (element) {
|
||||
var all_links = element.getElementsByTagName("a"),
|
||||
i = 0,
|
||||
len = all_links.length,
|
||||
@@ -11,10 +12,10 @@ const markactive_startswith = function (element) {
|
||||
all_links[i].className += " active";
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Marks links active which target URL is exact the same as the current URL
|
||||
const markactive_exact = function (element) {
|
||||
// Marks links active which target URL is exact the same as the current URL
|
||||
const markactive_exact = function (element) {
|
||||
var all_links = element.getElementsByTagName("a"),
|
||||
i = 0,
|
||||
len = all_links.length,
|
||||
@@ -25,10 +26,10 @@ const markactive_exact = function (element) {
|
||||
all_links[i].className += " active";
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Marks links as active, single links mutch match exactly, dropdown only the beginning
|
||||
const markactive_menu = function (element) {
|
||||
// Marks links as active, single links mutch match exactly, dropdown only the beginning
|
||||
const markactive_menu = function (element) {
|
||||
var all_links = element.getElementsByTagName("a"),
|
||||
i = 0,
|
||||
len = all_links.length,
|
||||
@@ -58,11 +59,15 @@ const markactive_menu = function (element) {
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (document.getElementById("ha-topnav") !== null)
|
||||
markactive_menu(document.getElementById("ha-topnav"));
|
||||
if (document.getElementById("ha-register-nav") !== null)
|
||||
markactive_exact(document.getElementById("ha-register-nav"));
|
||||
if (this.document.getElementById("ha-adminuploadfields") !== null)
|
||||
markactive_exact(document.getElementById("ha-adminuploadfields"));
|
||||
};
|
||||
|
||||
if (document.getElementById("ha-topnav") !== null)
|
||||
markactive_menu(document.getElementById("ha-topnav"));
|
||||
if (document.getElementById("ha-register-nav") !== null)
|
||||
markactive_exact(document.getElementById("ha-register-nav"));
|
||||
if (this.document.getElementById("ha-adminuploadfields") !== null)
|
||||
markactive_exact(document.getElementById("ha-adminuploadfields"));
|
||||
|
||||
startup_active();
|
||||
@@ -1,5 +1,5 @@
|
||||
// Marks anchors, if anchors are present in the URL
|
||||
const markanchor = function () {
|
||||
const startup_markanchor = function () {
|
||||
var currentUrl = document.URL,
|
||||
urlParts = currentUrl.split('#');
|
||||
var anchor = (urlParts.length > 1) ? urlParts[1] : null;
|
||||
@@ -19,4 +19,4 @@ const markanchor = function () {
|
||||
}
|
||||
}
|
||||
|
||||
markanchor();
|
||||
startup_markanchor();
|
||||
@@ -1,11 +1,13 @@
|
||||
// // Code specifically for the letter view
|
||||
let activetab = null;
|
||||
let activetabbtn = null;
|
||||
let activetabbtn2 = null;
|
||||
let tabbtnlist = document.querySelectorAll(".ha-tabbtn");
|
||||
let tablist = document.querySelectorAll(".ha-tab");
|
||||
|
||||
for (let i = 0; i < tabbtnlist.length; i++) {
|
||||
const startup_briefe = function () {
|
||||
let activetab = null;
|
||||
let activetabbtn = null;
|
||||
let activetabbtn2 = null;
|
||||
let tabbtnlist = document.querySelectorAll(".ha-tabbtn");
|
||||
let tablist = document.querySelectorAll(".ha-tab");
|
||||
|
||||
for (let i = 0; i < tabbtnlist.length; i++) {
|
||||
tablist[i % tablist.length].classList.add("hidden");
|
||||
tabbtnlist[i].addEventListener("click", () => {
|
||||
if (activetab != null)
|
||||
@@ -27,7 +29,10 @@ for (let i = 0; i < tabbtnlist.length; i++) {
|
||||
// requestAnimationFrame(() => { resetall(); });
|
||||
// }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (tabbtnlist.length > 0)
|
||||
if (tabbtnlist.length > 0)
|
||||
tabbtnlist[0].click();
|
||||
};
|
||||
|
||||
startup_briefe();
|
||||
@@ -1,7 +1,13 @@
|
||||
document.addEventListener('copy', function(e){
|
||||
|
||||
const startup_clipboard = function () {
|
||||
document.addEventListener('copy', function (e) {
|
||||
var e = navigator.clipboard.read();
|
||||
|
||||
var text = window.getSelection().toString();
|
||||
e.clipboardData.setData('text/plain', text);
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
startup_clipboard();
|
||||
@@ -1,10 +1,11 @@
|
||||
function getCookie(name) {
|
||||
const startup_filelistform = function () {
|
||||
function getCookie(name) {
|
||||
var value = "; " + document.cookie;
|
||||
var parts = value.split("; " + name + "=");
|
||||
if (parts.length == 2) return parts.pop().split(";").shift();
|
||||
}
|
||||
}
|
||||
|
||||
const USESubmit = async function (oFormElement, file = null) {
|
||||
const USESubmit = async function (oFormElement, file = null) {
|
||||
let fd = new FormData(oFormElement);
|
||||
document.getElementById("ha-filelistbutton").style.pointerEvents = "none";
|
||||
document.getElementById("ha-filelistbutton").classList.add("loading");
|
||||
@@ -26,14 +27,14 @@ const USESubmit = async function (oFormElement, file = null) {
|
||||
location.reload();
|
||||
}
|
||||
})
|
||||
.catch ((e) => {
|
||||
.catch((e) => {
|
||||
document.getElementById("ha-filelistbutton").classList.remove("loading");
|
||||
document.getElementById("ha-filelistbutton").style.pointerEvents = "auto";
|
||||
document.getElementById("ha-filelistoutput").textContent = e;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const GETSyntaxCheck = async function (oFormElement, file = null) {
|
||||
const GETSyntaxCheck = async function (oFormElement, file = null) {
|
||||
document.getElementById("ha-scbutton").style.pointerEvents = "none";
|
||||
document.getElementById("ha-scbutton").classList.toggle("loading");
|
||||
await fetch(oFormElement.action)
|
||||
@@ -82,32 +83,23 @@ const GETSyntaxCheck = async function (oFormElement, file = null) {
|
||||
}
|
||||
console.log(e, h, i, a);
|
||||
});
|
||||
// let coll = document.getElementsByClassName("ha-managedfile");
|
||||
// for (i = 0; i < coll.length; i++) {
|
||||
// let e = coll[i];
|
||||
// if (j[e.id] !== null) {
|
||||
// if(j[e.id].errors === null) {
|
||||
// console.log(e.id + " hat keine errors");
|
||||
// } else {
|
||||
// console.log(e.id + " hat errors");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
document.getElementById("ha-scbutton").classList.toggle("hidden");
|
||||
|
||||
})
|
||||
.catch ((e) => {
|
||||
.catch((e) => {
|
||||
console.log(e);
|
||||
document.getElementById("ha-scbutton").classList.toggle("loading");
|
||||
document.getElementById("ha-scbutton").style.pointerEvents = "auto";
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var coll = document.getElementsByClassName("expandable");
|
||||
|
||||
for (i = 0; i < coll.length; i++) {
|
||||
var coll = document.getElementsByClassName("expandable");
|
||||
for (i = 0; i < coll.length; i++) {
|
||||
let element = coll[i]
|
||||
coll[i].addEventListener("click", () => {
|
||||
element.classList.toggle("expanded");
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
startup_filelistform();
|
||||
@@ -1,6 +1,8 @@
|
||||
function encode(e){return e.replace(/[^]/g,function(e){return"&#"+e.charCodeAt(0)+";"})}
|
||||
const startup_index = function () {
|
||||
|
||||
const ACTIVATEGOTOFILTER = function(filter, button) {
|
||||
function encode(e) { return e.replace(/[^]/g, function (e) { return "&#" + e.charCodeAt(0) + ";" }) }
|
||||
|
||||
const ACTIVATEGOTOFILTER = function (filter, button) {
|
||||
let f = filter.value;
|
||||
let gotoinfo = document.getElementById("ha-gotoinfo");
|
||||
|
||||
@@ -21,9 +23,9 @@ const ACTIVATEGOTOFILTER = function(filter, button) {
|
||||
|
||||
if (gotoinfo != null && !gotoinfo.classList.contains("opacity-0")) gotoinfo.classList.add("opacity-0");
|
||||
button.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
const ACTIVATEZHSEARCH = function(volume, page, button) {
|
||||
const ACTIVATEZHSEARCH = function (volume, page, button) {
|
||||
let vol = volume.options[volume.selectedIndex].value;
|
||||
let pg = page.value;
|
||||
let gotoinfo = document.getElementById("ha-zhsearchinfo");
|
||||
@@ -45,47 +47,50 @@ const ACTIVATEZHSEARCH = function(volume, page, button) {
|
||||
|
||||
if (gotoinfo != null && !gotoinfo.classList.contains("opacity-0")) gotoinfo.classList.add("opacity-0");
|
||||
button.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
const SUBMITZHSEARCH = function(volume, page) {
|
||||
const SUBMITZHSEARCH = function (volume, page) {
|
||||
let vol = volume.options[volume.selectedIndex].value;
|
||||
let pg = page.value;
|
||||
window.location.href = "/HKB/" + vol + "/" + pg;
|
||||
}
|
||||
}
|
||||
|
||||
const ACTIVATESEARCHFILTER = function(filter, button) {
|
||||
const ACTIVATESEARCHFILTER = function (filter, button) {
|
||||
let f = filter.value;
|
||||
if (f === "") {
|
||||
button.disabled = true;
|
||||
return;
|
||||
}
|
||||
button.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Go to letter HKB number
|
||||
let gotofilter = document.getElementById("ha-gotoletternumber");
|
||||
let gotosubmitbtn = document.getElementById("ha-gotoformsubmit");
|
||||
let gotoform = document.getElementById("ha-gotoform");
|
||||
ACTIVATEGOTOFILTER(gotofilter, gotosubmitbtn);
|
||||
gotofilter.addEventListener("input", () => ACTIVATEGOTOFILTER(gotofilter, gotosubmitbtn));
|
||||
// Go to letter HKB number
|
||||
let gotofilter = document.getElementById("ha-gotoletternumber");
|
||||
let gotosubmitbtn = document.getElementById("ha-gotoformsubmit");
|
||||
let gotoform = document.getElementById("ha-gotoform");
|
||||
ACTIVATEGOTOFILTER(gotofilter, gotosubmitbtn);
|
||||
gotofilter.addEventListener("input", () => ACTIVATEGOTOFILTER(gotofilter, gotosubmitbtn));
|
||||
|
||||
// ZH Volume / Page Lookup
|
||||
let vol = document.getElementById("ha-zhformvolume");
|
||||
let pg = document.getElementById("ha-zhformpage");
|
||||
let zhsubmitbtn = document.getElementById("ha-zhformsubmit");
|
||||
let zhsearchform = document.getElementById("ha-zhform");
|
||||
ACTIVATEZHSEARCH(vol, pg, zhsubmitbtn);
|
||||
vol.addEventListener("change", () => ACTIVATEZHSEARCH(vol, pg, zhsubmitbtn));
|
||||
pg.addEventListener("input", () => ACTIVATEZHSEARCH(vol, pg, zhsubmitbtn));
|
||||
// Need to implement send bc razor tag helpers do not work here
|
||||
zhsearchform.addEventListener("submit", (ev) => {
|
||||
// ZH Volume / Page Lookup
|
||||
let vol = document.getElementById("ha-zhformvolume");
|
||||
let pg = document.getElementById("ha-zhformpage");
|
||||
let zhsubmitbtn = document.getElementById("ha-zhformsubmit");
|
||||
let zhsearchform = document.getElementById("ha-zhform");
|
||||
ACTIVATEZHSEARCH(vol, pg, zhsubmitbtn);
|
||||
vol.addEventListener("change", () => ACTIVATEZHSEARCH(vol, pg, zhsubmitbtn));
|
||||
pg.addEventListener("input", () => ACTIVATEZHSEARCH(vol, pg, zhsubmitbtn));
|
||||
// Need to implement send bc razor tag helpers do not work here
|
||||
zhsearchform.addEventListener("submit", (ev) => {
|
||||
ev.preventDefault();
|
||||
SUBMITZHSEARCH(vol, pg);
|
||||
});
|
||||
});
|
||||
|
||||
// Full-text search
|
||||
let searchfilter = document.getElementById("ha-searchformtext");
|
||||
let searchsubmitbtn = document.getElementById("ha-searchformsubmit");
|
||||
let searchform = document.getElementById("ha-searchform");
|
||||
ACTIVATESEARCHFILTER(searchfilter, searchsubmitbtn);
|
||||
searchfilter.addEventListener("input", () => ACTIVATESEARCHFILTER(searchfilter, searchsubmitbtn));
|
||||
// Full-text search
|
||||
let searchfilter = document.getElementById("ha-searchformtext");
|
||||
let searchsubmitbtn = document.getElementById("ha-searchformsubmit");
|
||||
let searchform = document.getElementById("ha-searchform");
|
||||
ACTIVATESEARCHFILTER(searchfilter, searchsubmitbtn);
|
||||
searchfilter.addEventListener("input", () => ACTIVATESEARCHFILTER(searchfilter, searchsubmitbtn));
|
||||
};
|
||||
|
||||
startup_index();
|
||||
@@ -1,5 +1,6 @@
|
||||
// Script for auto collapsing marginal boxes
|
||||
const getLineHeight = function (element) {
|
||||
const startup_marginals = function () {
|
||||
const getLineHeight = function (element) {
|
||||
var temp = document.createElement(element.nodeName),
|
||||
ret;
|
||||
temp.setAttribute("class", element.className);
|
||||
@@ -8,20 +9,20 @@ const getLineHeight = function (element) {
|
||||
ret = temp.getBoundingClientRect().height;
|
||||
temp.parentNode.removeChild(temp);
|
||||
return ret;
|
||||
};
|
||||
};
|
||||
|
||||
const collapsebox = function (element, height, lineheight) {
|
||||
const collapsebox = function (element, height, lineheight) {
|
||||
element.style.maxHeight = height + "px";
|
||||
element.classList.add("ha-collapsed-box");
|
||||
element.classList.remove("ha-expanded-box");
|
||||
};
|
||||
};
|
||||
|
||||
const uncollapsebox = function (element) {
|
||||
const uncollapsebox = function (element) {
|
||||
element.classList.remove("ha-collapsed-box");
|
||||
element.classList.add("ha-expanded-box");
|
||||
};
|
||||
};
|
||||
|
||||
const addbuttoncaollapsebox = function (element, height, hoverfunction) {
|
||||
const addbuttoncaollapsebox = function (element, height, hoverfunction) {
|
||||
let btn = document.createElement("div");
|
||||
btn.classList.add("ha-btn-collapsed-box");
|
||||
|
||||
@@ -72,9 +73,9 @@ const addbuttoncaollapsebox = function (element, height, hoverfunction) {
|
||||
});
|
||||
}
|
||||
element.parentNode.insertBefore(btn, element);
|
||||
};
|
||||
};
|
||||
|
||||
const overlappingcollapsebox = function (selector, hoverfunction) {
|
||||
const overlappingcollapsebox = function (selector, hoverfunction) {
|
||||
let boxes = document.querySelectorAll(selector);
|
||||
let lineheight = 1;
|
||||
|
||||
@@ -128,9 +129,9 @@ const overlappingcollapsebox = function (selector, hoverfunction) {
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const marginalboxwidthset = function () {
|
||||
const marginalboxwidthset = function () {
|
||||
let lt = document.getElementById("ha-letterbody");
|
||||
if (lt !== null) {
|
||||
let mg = lt.querySelectorAll(".ha-text .ha-marginalbox");
|
||||
@@ -144,20 +145,18 @@ const marginalboxwidthset = function () {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const collapseboxes = function () {
|
||||
const collapseboxes = function () {
|
||||
overlappingcollapsebox(".ha-neuzeit .ha-letlinks", true);
|
||||
overlappingcollapsebox(".ha-forschung .ha-letlinks", true);
|
||||
overlappingcollapsebox(".ha-commentlist .ha-letlinks", true);
|
||||
overlappingcollapsebox(".ha-text .ha-marginalbox", true);
|
||||
};
|
||||
};
|
||||
|
||||
var collapsedboxes = [];
|
||||
var collapsedboxes = [];
|
||||
|
||||
const clearcollapsedboxes = function () {
|
||||
const clearcollapsedboxes = function () {
|
||||
var elements = document.querySelectorAll(".ha-text .ha-marginalbox");
|
||||
elements.forEach(element => {
|
||||
element.removeAttribute("style");
|
||||
@@ -172,19 +171,23 @@ const clearcollapsedboxes = function () {
|
||||
elements.forEach(element => {
|
||||
element.remove();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const resetall = function() {
|
||||
const resetall = function () {
|
||||
clearcollapsedboxes();
|
||||
marginalboxwidthset();
|
||||
collapseboxes();
|
||||
}
|
||||
}
|
||||
|
||||
marginalboxwidthset();
|
||||
collapseboxes();
|
||||
|
||||
var doit;
|
||||
this.window.addEventListener("resize", function () {
|
||||
marginalboxwidthset();
|
||||
collapseboxes();
|
||||
|
||||
var doit;
|
||||
this.window.addEventListener("resize", function () {
|
||||
this.clearTimeout(doit);
|
||||
doit = this.setTimeout(resetall, 17);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
startup_marginals();
|
||||
|
||||
@@ -1,31 +1,35 @@
|
||||
// Code for showing and hiding the mobile menu
|
||||
const openmenu = function () {
|
||||
const startup_mobilemenu = function () {
|
||||
const openmenu = function () {
|
||||
var x = document.getElementById("ha-topnav");
|
||||
if (x !== null) x.className += " ha-topnav-collapsed";
|
||||
let oldbutton = document.getElementById("openmenubutton");
|
||||
if (oldbutton !== null) oldbutton.setAttribute("class", "hidden");
|
||||
let newbutton = document.getElementById("closemenubutton");
|
||||
if (newbutton !== null) newbutton.setAttribute("class", "");
|
||||
};
|
||||
};
|
||||
|
||||
const closemenu = function () {
|
||||
const closemenu = function () {
|
||||
var x = document.getElementById("ha-topnav");
|
||||
if (x !== null) x.className = "ha-topnav";
|
||||
let oldbutton = document.getElementById("closemenubutton");
|
||||
if (oldbutton !== null) oldbutton.setAttribute("class", "hidden");
|
||||
let newbutton = document.getElementById("openmenubutton");
|
||||
if (newbutton !== null) newbutton.setAttribute("class", "");
|
||||
};
|
||||
};
|
||||
|
||||
// Menu: Show / Hide Buttons for mobile View
|
||||
if (
|
||||
// Menu: Show / Hide Buttons for mobile View
|
||||
if (
|
||||
document.getElementById("openmenubutton") !== null &&
|
||||
document.getElementById("closemenubutton") !== null
|
||||
) {
|
||||
) {
|
||||
document
|
||||
.getElementById("openmenubutton")
|
||||
.addEventListener("click", openmenu);
|
||||
document
|
||||
.getElementById("closemenubutton")
|
||||
.addEventListener("click", closemenu);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
startup_mobilemenu();
|
||||
@@ -1,4 +1,6 @@
|
||||
const LOCALPUBLISHSubmit = async function (oFormElement) {
|
||||
const startup_publishform = function () {
|
||||
|
||||
const LOCALPUBLISHSubmit = async function (oFormElement) {
|
||||
var fd = new FormData();
|
||||
document.getElementById("ha-publishfilelabel").style.pointerEvents = "none";
|
||||
document.getElementById("ha-lds-ellipsis-publish").style.display = "inline-block";
|
||||
@@ -24,14 +26,16 @@ const LOCALPUBLISHSubmit = async function (oFormElement) {
|
||||
location.reload();
|
||||
}
|
||||
})
|
||||
.catch ((e) => {
|
||||
.catch((e) => {
|
||||
document.getElementById("ha-publishfilelabel").style.pointerEvents = "auto";
|
||||
document.getElementById("ha-lds-ellipsis-publish").style.display = "none";
|
||||
document.getElementById("publish-result").value = "Keine Antwort. Bitte Seite neu laden!";
|
||||
})
|
||||
}
|
||||
|
||||
var publishelement = document.getElementById("ha-publishform");
|
||||
var publishbutton = document.getElementById("ha-publishfilelabel");
|
||||
publishbutton.addEventListener("click", () => LOCALPUBLISHSubmit(publishelement));
|
||||
var publishelement = document.getElementById("ha-publishform");
|
||||
var publishbutton = document.getElementById("ha-publishfilelabel");
|
||||
publishbutton.addEventListener("click", () => LOCALPUBLISHSubmit(publishelement));
|
||||
};
|
||||
|
||||
startup_publishform();
|
||||
@@ -1,5 +1,7 @@
|
||||
// Script for showing and acting upon the "scroll to top button"
|
||||
const scrollFunction = function () {
|
||||
const startup_scrollbutton = function () {
|
||||
|
||||
// Script for showing and acting upon the "scroll to top button"
|
||||
const scrollFunction = function () {
|
||||
button = document.getElementById("ha-scrollbutton");
|
||||
if (button !== null) {
|
||||
if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 300) {
|
||||
@@ -12,10 +14,10 @@ const scrollFunction = function () {
|
||||
button.style.opacity = "0";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Scroll button
|
||||
if (document.getElementById("ha-scrollbutton") !== null) {
|
||||
// Scroll button
|
||||
if (document.getElementById("ha-scrollbutton") !== null) {
|
||||
scrollFunction();
|
||||
document.getElementById("ha-scrollbutton").addEventListener("click", () => {
|
||||
document.body.scrollTop = 0; // For Safari
|
||||
@@ -23,4 +25,7 @@ if (document.getElementById("ha-scrollbutton") !== null) {
|
||||
})
|
||||
// TODO: workaround, bc window does not recieve scroll events anymore
|
||||
setInterval(() => scrollFunction(), 1500);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
startup_scrollbutton();
|
||||
@@ -1,14 +1,19 @@
|
||||
const ACTIVATESEARCHFILTER = function(filter, button) {
|
||||
const startup_search = function () {
|
||||
|
||||
const ACTIVATESEARCHFILTER = function (filter, button) {
|
||||
let f = filter.value;
|
||||
if (f === "") {
|
||||
button.disabled = true;
|
||||
return;
|
||||
}
|
||||
button.disabled = false;
|
||||
}
|
||||
|
||||
let searchfilter = document.getElementById("ha-searchformtext");
|
||||
let searchsubmitbtn = document.getElementById("ha-searchformsubmit");
|
||||
let searchform = document.getElementById("ha-searchform");
|
||||
ACTIVATESEARCHFILTER(searchfilter, searchsubmitbtn);
|
||||
searchfilter.addEventListener("input", () => ACTIVATESEARCHFILTER(searchfilter, searchsubmitbtn));
|
||||
}
|
||||
|
||||
let searchfilter = document.getElementById("ha-searchformtext");
|
||||
let searchsubmitbtn = document.getElementById("ha-searchformsubmit");
|
||||
let searchform = document.getElementById("ha-searchform");
|
||||
ACTIVATESEARCHFILTER(searchfilter, searchsubmitbtn);
|
||||
searchfilter.addEventListener("input", () => ACTIVATESEARCHFILTER(searchfilter, searchsubmitbtn));
|
||||
startup_search();
|
||||
|
||||
@@ -1,30 +1,35 @@
|
||||
// Functions for switching theme
|
||||
const go_to_dark = function () {
|
||||
const startup_theme = function () {
|
||||
|
||||
const go_to_dark = function () {
|
||||
localStorage.setItem("theme", "ha-toggledark");
|
||||
document.documentElement.classList.add("dark");
|
||||
};
|
||||
};
|
||||
|
||||
const go_to_bright = function () {
|
||||
const go_to_bright = function () {
|
||||
document.documentElement.classList.remove("dark");
|
||||
localStorage.setItem("theme", "ha-togglebright");
|
||||
};
|
||||
};
|
||||
|
||||
// Functions for reading theme settings
|
||||
const get_theme_settings = function (standard) {
|
||||
// Functions for reading theme settings
|
||||
const get_theme_settings = function (standard) {
|
||||
var theme = localStorage.getItem("theme");
|
||||
if (theme === null) theme = standard;
|
||||
let toggleSwitch = document.getElementById(theme).click();
|
||||
};
|
||||
};
|
||||
|
||||
if (
|
||||
if (
|
||||
document.getElementById("ha-togglebright") !== null &&
|
||||
this.document.getElementById("ha-toggledark") !== null
|
||||
) {
|
||||
) {
|
||||
document
|
||||
.getElementById("ha-togglebright")
|
||||
.addEventListener("click", go_to_bright);
|
||||
document
|
||||
.getElementById("ha-toggledark")
|
||||
.addEventListener("click", go_to_dark);
|
||||
}
|
||||
get_theme_settings("ha-togglebright");
|
||||
}
|
||||
get_theme_settings("ha-togglebright");
|
||||
};
|
||||
|
||||
startup_theme();
|
||||
@@ -1,73 +0,0 @@
|
||||
const dropHandler = function (formelement, ev, dropzone) {
|
||||
ev.preventDefault();
|
||||
if (ev.dataTransfer.items) {
|
||||
if (ev.dataTransfer.items[0].kind === 'file') {
|
||||
var file = ev.dataTransfer.items[0].getAsFile();
|
||||
UPLOADSubmit(formelement, file);
|
||||
} else {
|
||||
var file = ev.dataTransfer.files[0];
|
||||
UPLOADSubmit(formelement, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const dragOverHandler = function (ev, dropzone) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
const dragLeaveHander = function (ev, dropzone) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
const dragEnterHandler = function (ev, dropzone) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
const UPLOADSubmit = async function (oFormElement, file = null) {
|
||||
var fd = new FormData();
|
||||
if (file !== null) fd.append("file", file);
|
||||
else fd = new FormData(oFormElement);
|
||||
document.getElementById("dropzone").style.pointerEvents = "none";
|
||||
document.getElementById("ha-lds-ellipsis-upload").style.display = "inline-block";
|
||||
document.getElementById("ha-uploadmessage").style.opacity = "0";
|
||||
await fetch(oFormElement.action, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'RequestVerificationToken': getCookie('RequestVerificationToken')
|
||||
},
|
||||
body: fd
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
if ("Error" in json) {
|
||||
document.getElementById("dropzone").style.pointerEvents = "auto";
|
||||
document.getElementById("ha-lds-ellipsis-upload").style.display = "none";
|
||||
document.getElementById("ha-uploadmessage").style.opacity = "1";
|
||||
oFormElement.elements.namedItem("upload-result").value = json.Error;
|
||||
} else {
|
||||
document.getElementById("dropzone").style.pointerEvents = "auto";
|
||||
document.getElementById("ha-lds-ellipsis-upload").style.display = "none";
|
||||
oFormElement.elements.namedItem("upload-result").value = "Erfolg!";
|
||||
if ("Prefix" in json[0]) {
|
||||
document.getElementById("dropzone").style.pointerEvents = "auto";
|
||||
document.getElementById("ha-lds-ellipsis-upload").style.display = "none";
|
||||
window.location.replace("/Admin/Upload/" + json[0].Prefix);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch ((e) => {
|
||||
document.getElementById("dropzone").style.pointerEvents = "auto";
|
||||
document.getElementById("ha-lds-ellipsis-upload").style.display = "none";
|
||||
document.getElementById("ha-uploadmessage").style.opacity = "1";
|
||||
oFormElement.elements.namedItem("upload-result").value = "Keine Antwort. Bitte Seite neu laden!";
|
||||
})
|
||||
}
|
||||
|
||||
var submitelement = document.getElementById("file");
|
||||
var formelement = document.getElementById("uploadForm");
|
||||
var dropzone = document.getElementById("dropzone");
|
||||
submitelement.addEventListener("change", () => UPLOADSubmit(formelement));
|
||||
dropzone.addEventListener("drop", (ev) => dropHandler(formelement, ev, dropzone));
|
||||
dropzone.addEventListener("dragover", (ev) => dragOverHandler(ev, dropzone));
|
||||
dropzone.addEventListener("dragleave", (ev) => dragLeaveHander(ev, dropzone));
|
||||
dropzone.addEventListener("dragenter", (ev) => dragEnterHandler(ev, dropzone));
|
||||
@@ -1,42 +1,44 @@
|
||||
var stateSC = null;
|
||||
var stateValidation = null;
|
||||
var stateReload = null;
|
||||
var stateCommit = null;
|
||||
var statePing = false;
|
||||
var firstMessage = true;
|
||||
var commsLog = document.getElementById("commsLog");
|
||||
var commsNot = document.getElementById("comm-notifications");
|
||||
var socket;
|
||||
|
||||
var scheme = document.location.protocol === "https:" ? "wss" : "ws";
|
||||
var port = document.location.port ? (":" + document.location.port) : "";
|
||||
var wsPingInterval;
|
||||
var connectionUrl = scheme + "://" + document.location.hostname + port + "/WS" ;
|
||||
|
||||
function htmlEscape(str) {
|
||||
// Functions for change notifications and automatic reload via websockets
|
||||
const startup_websocket = function () {
|
||||
function htmlEscape(str) {
|
||||
return str.toString()
|
||||
.replace(/&/g, '&')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
socket = new WebSocket(connectionUrl);
|
||||
socket.onopen = function (event) {
|
||||
var stateSC = null;
|
||||
var stateValidation = null;
|
||||
var stateReload = null;
|
||||
var stateCommit = null;
|
||||
var statePing = false;
|
||||
var firstMessage = true;
|
||||
var commsLog = document.getElementById("commsLog");
|
||||
var commsNot = document.getElementById("comm-notifications");
|
||||
var socket;
|
||||
|
||||
var scheme = document.location.protocol === "https:" ? "wss" : "ws";
|
||||
var port = document.location.port ? (":" + document.location.port) : "";
|
||||
var wsPingInterval;
|
||||
var connectionUrl = scheme + "://" + document.location.hostname + port + "/WS";
|
||||
|
||||
socket = new WebSocket(connectionUrl);
|
||||
socket.onopen = function (event) {
|
||||
socket.send("Hello");
|
||||
wsPingInterval = setInterval(() => {
|
||||
socket.send("Ping");
|
||||
}, 30000);
|
||||
updateMessage();
|
||||
};
|
||||
socket.onclose = function (event) {
|
||||
};
|
||||
socket.onclose = function (event) {
|
||||
clearInterval(wsPingInterval);
|
||||
updateMessage();
|
||||
};
|
||||
socket.onerror = updateMessage;
|
||||
socket.onmessage = function (event) {
|
||||
};
|
||||
socket.onerror = updateMessage;
|
||||
socket.onmessage = function (event) {
|
||||
var msg = JSON.parse(event.data);
|
||||
if (msg.ValidationState != null) {
|
||||
stateValidation = msg.ValidationState;
|
||||
@@ -87,9 +89,9 @@ socket.onmessage = function (event) {
|
||||
commsLog.innerHTML = htmlEscape(event.data);
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
function updateMessage() {
|
||||
function updateMessage() {
|
||||
function disable() {
|
||||
commsNot.classList.remove("red");
|
||||
commsNot.classList.remove("loading");
|
||||
@@ -118,7 +120,7 @@ function updateMessage() {
|
||||
case WebSocket.OPEN:
|
||||
commsLog.innerHTML = "";
|
||||
// TODO: decide on state what the message is
|
||||
if (stateValidation == 0 ) {
|
||||
if (stateValidation == 0) {
|
||||
commsLog.innerHTML = 'Der angezeigte Stand ist nicht aktuell. ' +
|
||||
'<a href="/Admin">Fehler beheben</a>';
|
||||
if (!firstMessage) commsNot.classList.add("imp");
|
||||
@@ -126,7 +128,7 @@ function updateMessage() {
|
||||
commsLog.innerHTML = "Der Server arbeitet...";
|
||||
} else {
|
||||
if (stateCommit != null) {
|
||||
commsLog.innerHTML = "<a href='https://github.com/Theodor-Springmann-Stiftung/hamann-xml/commit/" + stateCommit.Commit.substring(0,7) + "'>commit " +
|
||||
commsLog.innerHTML = "<a href='https://github.com/Theodor-Springmann-Stiftung/hamann-xml/commit/" + stateCommit.Commit.substring(0, 7) + "'>commit " +
|
||||
stateCommit.Commit.substring(0, 7) +
|
||||
" geladen</a>"
|
||||
} else {
|
||||
@@ -142,24 +144,7 @@ function updateMessage() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// closeButton.onclick = function () {
|
||||
// if (!socket || socket.readyState !== WebSocket.OPEN) {
|
||||
// alert("socket not connected");
|
||||
// }
|
||||
// socket.close(1000, "Closing from client");
|
||||
// };
|
||||
|
||||
// sendButton.onclick = function () {
|
||||
// if (!socket || socket.readyState !== WebSocket.OPEN) {
|
||||
// alert("socket not connected");
|
||||
// }
|
||||
// var data = sendMessage.value;
|
||||
// socket.send(data);
|
||||
// commsLog.innerHTML += '<tr>' +
|
||||
// '<td class="commslog-client">Client</td>' +
|
||||
// '<td class="commslog-server">Server</td>' +
|
||||
// '<td class="commslog-data">' + htmlEscape(data) + '</td></tr>';
|
||||
// };
|
||||
}
|
||||
};
|
||||
|
||||
startup_websocket();
|
||||
Reference in New Issue
Block a user