Simplify nopaque.js

This commit is contained in:
Patrick Jentsch
2020-02-18 14:39:05 +01:00
parent e409727ef1
commit 292c24b38f
4 changed files with 30 additions and 39 deletions

View File

@ -19,25 +19,20 @@ nopaque.foreignJobsSubscribers = [];
// nopaque functions
nopaque.forms = {};
nopaque.forms.init = function() {
var abortRequestElement, parentElement, progressElement, progressModal,
progressModalElement, request, submitElement;
nopaque.Workarounds = {};
nopaque.Workarounds.apply = function() {
// Disable all option elements with no value
for (let optionElement of document.querySelectorAll('option[value=""]')) {
optionElement.disabled = true;
}
}
nopaque.Forms = {};
nopaque.Forms.init = function() {
var abortRequestElement, progressElement, progressModal,
progressModalElement, request;
for (let form of document.querySelectorAll(".nopaque-job-form")) {
submitElement = form.querySelector('button[type="submit"]');
submitElement.addEventListener("click", function() {
for (let selectElement of form.querySelectorAll('select')) {
if (selectElement.value === "") {
parentElement = selectElement.closest(".input-field");
for (let helperTextElement of parentElement.querySelectorAll(".helper-text")) {
helperTextElement.remove();
}
parentElement.insertAdjacentHTML("beforeend", `<span class="helper-text red-text">Please select an option.</span>`);
}
}
})
request = new XMLHttpRequest();
if (form.dataset.hasOwnProperty("progressModal")) {
progressModalElement = document.getElementById(form.dataset.progressModal);
@ -91,24 +86,14 @@ nopaque.forms.init = function() {
}
}
nopaque.navigation = {};
nopaque.navigation.init = function() {
var slideOutElement, tocElement;
slideOutElement = document.getElementById("slide-out");
for (let entry of slideOutElement.querySelectorAll("a:not(.subheader)")) {
nopaque.Navigation = {};
nopaque.Navigation.init = function() {
/* ### Initialize sidenav-main ### */
for (let entry of document.querySelectorAll("#sidenav-main a")) {
if (entry.href === window.location.href) {
entry.parentNode.classList.add("active");
}
}
tocElement = document.getElementById("roadmap");
if (tocElement) {
for (let entry of tocElement.querySelectorAll("a")) {
if (entry.href === window.location.href) {
entry.classList.add("active");
}
}
}
}
@ -223,11 +208,12 @@ nopaque.socket.on("match_context", function(message) {
});
document.addEventListener("DOMContentLoaded", function() {
nopaque.Workarounds.apply();
M.AutoInit();
M.CharacterCounter.init(document.querySelectorAll('input[data-length][type="text"]'));
M.Dropdown.init(document.querySelectorAll("#nav-notifications, #nav-account"),
{alignment: "right", constrainWidth: false, coverTrigger: false});
nopaque.forms.init();
nopaque.navigation.init();
nopaque.Forms.init();
nopaque.Navigation.init();
nopaque.socket.emit("user_ressources_init");
});