From 833b7186093516ac4ed8cd7a90ff22c6b9f16ce2 Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tvdijen@gmail.com> Date: Thu, 17 Mar 2022 21:20:28 +0100 Subject: [PATCH] Convert language selector to native JS --- src/js/bundle.js | 57 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/src/js/bundle.js b/src/js/bundle.js index 608ce4d26..274ec3f9d 100644 --- a/src/js/bundle.js +++ b/src/js/bundle.js @@ -8,33 +8,58 @@ import json from "highlight.js/lib/languages/json"; window.readyHandlers = []; window.ready = function ready(handler) { - window.readyHandlers.push(handler); - handleState(); + window.readyHandlers.push(handler); + handleState(); }; window.handleState = function handleState () { - if (document.readyState === 'interactive' || document.readyState === "complete") { - while(window.readyHandlers.length > 0) { - (window.readyHandlers.shift())(); + if (document.readyState === 'interactive' || document.readyState === "complete") { + while(window.readyHandlers.length > 0) { + (window.readyHandlers.shift())(); + } } - } }; document.onreadystatechange = window.handleState; -$(document).ready(function () { - $('#language-selector').on('change', function () { - $("#language-form").submit(); - }); +ready(function () { + // Language selector + var languageSelector = document.getElementById("language-selector"); + languageSelector.onchange = function() { + var languageForm = document.getElementById("language-form"); + languageForm.submit(); + return true; + }; - // side menu - $('#menuLink').click(function (e) { + // Side menu + var menuLink = document.getElementById("menuLink"); + menuLink.onclick = function(e) { e.preventDefault(); - $('#layout').toggleClass('active'); - $('#foot').toggleClass('active'); - $(this).toggleClass('active'); - }); + var layout = document.getElementById("layout"); + if (layout.className.match(/(?:^|\s)active(?!\S)/)) { + layout.className = layout.className.replace(/(?:^|\s)active(?!\S)/g , ''); + } else { + layout.className += " active"; + } + + var foot = document.getElementById("foot"); + if (foot.className.match(/(?:^|\s)active(?!\S)/)) { + foot.className = foot.className.replace(/(?:^|\s)active(?!\S)/g , ''); + } else { + foot.className += " active"; + } + + if (menuLink.className.match(/(?:^|\s)active(?!\S)/)) { + menuLink.className = menuLink.className.replace(/(?:^|\s)active(?!\S)/g , ''); + } else { + menuLink.className += " active"; + } + }; +}); + + +$(document).ready(function () { // expander boxes $('.expandable > .expander').on('click', function (e) { e.preventDefault(); -- GitLab