From 292c24b38fd02dfcceaa8f1acd249edb1daf9296 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Tue, 18 Feb 2020 14:39:05 +0100 Subject: [PATCH 1/3] Simplify nopaque.js --- app/static/js/nopaque.js | 52 +++++++++++------------------- app/templates/jobs/job.html.j2 | 2 +- app/templates/nopaque.html.j2 | 7 +++- app/templates/services/ocr.html.j2 | 8 ++--- 4 files changed, 30 insertions(+), 39 deletions(-) diff --git a/app/static/js/nopaque.js b/app/static/js/nopaque.js index 629a4434..01406fac 100644 --- a/app/static/js/nopaque.js +++ b/app/static/js/nopaque.js @@ -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", `Please select an option.`); - } - } - }) - 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"); }); diff --git a/app/templates/jobs/job.html.j2 b/app/templates/jobs/job.html.j2 index b0e10fe1..faef08ee 100644 --- a/app/templates/jobs/job.html.j2 +++ b/app/templates/jobs/job.html.j2 @@ -138,7 +138,7 @@ diff --git a/app/templates/nopaque.html.j2 b/app/templates/nopaque.html.j2 index 9b11b5df..7e4554d3 100644 --- a/app/templates/nopaque.html.j2 +++ b/app/templates/nopaque.html.j2 @@ -56,7 +56,7 @@ {% endif %} -