From f4137a4cf6d8facfadfd91a126235966b5c04be8 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Sat, 21 Jan 2023 20:31:55 +0200 Subject: [PATCH] Moved qJuery install --- ' | 47 --------------- static/main/js/lightmode.js | 30 +++++----- static/main/js/lightsaber.js | 55 ++++++++++-------- static/main/js/navigation.js | 28 ++++----- static/main/js/text_swap.js | 32 +++++----- static/main/js/typewriter.js | 58 ++++++++++--------- static/main/js/validation.js | 6 +- static/projects/js/projects.js | 18 +++--- templates/layout.html | 3 - templates/main/validation.html | 1 + .../traffic_light_detector.html | 6 +- 11 files changed, 125 insertions(+), 159 deletions(-) delete mode 100644 ' diff --git a/' b/' deleted file mode 100644 index be7c77a..0000000 --- a/' +++ /dev/null @@ -1,47 +0,0 @@ -$(document).ready(function () { - let lightmode = localStorage.getItem("lightmode") - const HTML = $("html") - const AUDIO = $("#flashbang") - - const enable_light_mode = () => { - HTML.attr("data-color-mode", "light") - localStorage.setItem("lightmode", "enabled") - } - - const disable_light_mode = () => { - HTML.attr("data-color-mode", "dark") - localStorage.setItem("lightmode", null) - } - - if (lightmode === "enabled") { - enable_light_mode() - } - - window - .matchMedia("(prefers-color-scheme: dark)") - .addEventListener("change", (event) => { - if (event.matches) { - disable_light_mode() - } else { - enable_light_mode() - } - }) - - if (window.matchMedia) { - if (window.matchMedia("(prefers-color-scheme: light)").matches) { - enable_light_mode() - } else { - disable_light_mode() - } - } - - $("#color-mode-toggle").click(() => { - lightmode = localStorage.getItem("lightmode") - if (lightmode !== "enabled") { - enable_light_mode() - AUDIO[0].play() - } else { - disable_light_mode() - } - }) -}) diff --git a/static/main/js/lightmode.js b/static/main/js/lightmode.js index 5727901..8cd4da7 100644 --- a/static/main/js/lightmode.js +++ b/static/main/js/lightmode.js @@ -1,15 +1,15 @@ -$(document).ready(function () { +window.addEventListener("DOMContentLoaded", () => { + const HTML = document.documentElement + const AUDIO = document.getElementById("flashbang") let lightmode = localStorage.getItem("lightmode") - const HTML = $("html") - const AUDIO = $("#flashbang") const enable_light_mode = () => { - HTML.attr("data-color-mode", "light") + HTML.setAttribute("data-color-mode", "light") localStorage.setItem("lightmode", "enabled") } const disable_light_mode = () => { - HTML.attr("data-color-mode", "dark") + HTML.setAttribute("data-color-mode", "dark") localStorage.setItem("lightmode", null) } @@ -35,13 +35,15 @@ $(document).ready(function () { } } - $("#color-mode-toggle").click(() => { - lightmode = localStorage.getItem("lightmode") - if (lightmode !== "enabled") { - enable_light_mode() - AUDIO[0].play() - } else { - disable_light_mode() - } - }) + document + .querySelector("#color-mode-toggle") + .addEventListener("click", () => { + lightmode = localStorage.getItem("lightmode") + if (lightmode !== "enabled") { + enable_light_mode() + AUDIO.play() + } else { + disable_light_mode() + } + }) }) diff --git a/static/main/js/lightsaber.js b/static/main/js/lightsaber.js index cb12066..7ee9eee 100644 --- a/static/main/js/lightsaber.js +++ b/static/main/js/lightsaber.js @@ -1,28 +1,33 @@ -const COLORS = [ - "#2ff924", - "#2e67f8", - "#871efe", - "#eb212e", - "#ff8f18", - "#ffffff", -] -let random_color = COLORS[Math.floor(Math.random() * COLORS.length)] -document.documentElement.style.setProperty("--lightsaber-color", random_color) +window.addEventListener("DOMContentLoaded", () => { + const COLORS = [ + "#2ff924", + "#2e67f8", + "#871efe", + "#eb212e", + "#ff8f18", + "#ffffff", + ] + let random_color = COLORS[Math.floor(Math.random() * COLORS.length)] + document.documentElement.style.setProperty( + "--lightsaber-color", + random_color + ) -let body = document.body -body.addEventListener("click", () => { - body.hidden = true - requestAnimationFrame(() => { - body.hidden = false + let body = document.body + body.addEventListener("click", () => { + body.hidden = true + requestAnimationFrame(() => { + body.hidden = false + }) + }) + + let style = document.createElement("style") + style.innerHTML = + " *, *:before, *:after { animation-play-state: paused !important; }" + + document.addEventListener("keypress", () => { + style.parentNode + ? document.head.removeChild(style) + : document.head.appendChild(style) }) }) - -let style = document.createElement("style") -style.innerHTML = - " *, *:before, *:after { animation-play-state: paused !important; }" - -document.addEventListener("keypress", () => { - style.parentNode - ? document.head.removeChild(style) - : document.head.appendChild(style) -}) diff --git a/static/main/js/navigation.js b/static/main/js/navigation.js index a5a0363..cd055e2 100644 --- a/static/main/js/navigation.js +++ b/static/main/js/navigation.js @@ -1,15 +1,17 @@ -const PRIMARY_NAV = document.querySelector(".primary-navigation") -const MENU_BUTTON = document.querySelector(".mobile-nav-toggle") +window.addEventListener("DOMContentLoaded", () => { + const PRIMARY_NAV = document.querySelector(".primary-navigation") + const MENU_BUTTON = document.querySelector(".mobile-nav-toggle") -MENU_BUTTON.addEventListener("click", () => { - const VISIBILITY = PRIMARY_NAV.getAttribute("data-visible") === "false" - if (VISIBILITY) { - PRIMARY_NAV.setAttribute("data-visible", true) - MENU_BUTTON.setAttribute("aria-expanded", true) - MENU_BUTTON.classList.add("open") - } else { - PRIMARY_NAV.setAttribute("data-visible", false) - MENU_BUTTON.setAttribute("aria-expanded", false) - MENU_BUTTON.classList.remove("open") - } + MENU_BUTTON.addEventListener("click", () => { + const VISIBILITY = PRIMARY_NAV.getAttribute("data-visible") === "false" + if (VISIBILITY) { + PRIMARY_NAV.setAttribute("data-visible", true) + MENU_BUTTON.setAttribute("aria-expanded", true) + MENU_BUTTON.classList.add("open") + } else { + PRIMARY_NAV.setAttribute("data-visible", false) + MENU_BUTTON.setAttribute("aria-expanded", false) + MENU_BUTTON.classList.remove("open") + } + }) }) diff --git a/static/main/js/text_swap.js b/static/main/js/text_swap.js index c7912f0..5494fd6 100644 --- a/static/main/js/text_swap.js +++ b/static/main/js/text_swap.js @@ -1,17 +1,19 @@ -const DISPLAY_NAME = document.getElementById("swap-text") -const NAMES = [ - "Kristiāns", - "Francis", - "Cagulis", - "Kristiāns Francis Cagulis", - "KFC", - "Kristofers", - "Solo", - "Kristofers Solo", - "Salaspils 1", - "Šis puisis", -] +window.addEventListener("DOMContentLoaded", () => { + const DISPLAY_NAME = document.getElementById("swap-text") + const NAMES = [ + "Kristiāns", + "Francis", + "Cagulis", + "Kristiāns Francis Cagulis", + "KFC", + "Kristofers", + "Solo", + "Kristofers Solo", + "Salaspils 1", + "Šis puisis", + ] -DISPLAY_NAME.addEventListener("click", () => { - DISPLAY_NAME.innerHTML = NAMES[Math.floor(Math.random() * NAMES.length)] + DISPLAY_NAME.addEventListener("click", () => { + DISPLAY_NAME.innerHTML = NAMES[Math.floor(Math.random() * NAMES.length)] + }) }) diff --git a/static/main/js/typewriter.js b/static/main/js/typewriter.js index 847f27b..cbf7635 100644 --- a/static/main/js/typewriter.js +++ b/static/main/js/typewriter.js @@ -1,36 +1,38 @@ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) -window.addEventListener("load", async () => { - const TEXT_DISPLAY = document.getElementById("rotating-text") - const PHRASES = ["Software Developer", "Jedi", "Student"] - let current_phrase = [] - let is_end = false +window.addEventListener("DOMContentLoaded", () => { + window.addEventListener("load", async () => { + const TEXT_DISPLAY = document.getElementById("rotating-text") + const PHRASES = ["Software Developer", "Jedi", "Student"] + let current_phrase = [] + let is_end = false - while (1) { - for (let phrase in PHRASES) { - if (!is_end) { - for (let character in PHRASES[phrase]) { - current_phrase.push(PHRASES[phrase][character]) - TEXT_DISPLAY.innerHTML = current_phrase.join("") - await sleep(150) - } - if (current_phrase.join("") == PHRASES[phrase]) { - await sleep(1000) - is_end = true - } - } else { - while (1) { - current_phrase.pop() - if (!current_phrase.length) { - is_end = false - TEXT_DISPLAY.innerHTML = " " - await sleep(500) - break + while (1) { + for (let phrase in PHRASES) { + if (!is_end) { + for (let character in PHRASES[phrase]) { + current_phrase.push(PHRASES[phrase][character]) + TEXT_DISPLAY.innerHTML = current_phrase.join("") + await sleep(150) + } + if (current_phrase.join("") == PHRASES[phrase]) { + await sleep(1000) + is_end = true + } + } else { + while (1) { + current_phrase.pop() + if (!current_phrase.length) { + is_end = false + TEXT_DISPLAY.innerHTML = " " + await sleep(500) + break + } + TEXT_DISPLAY.innerHTML = current_phrase.join("") + await sleep(80) } - TEXT_DISPLAY.innerHTML = current_phrase.join("") - await sleep(80) } } } - } + }) }) diff --git a/static/main/js/validation.js b/static/main/js/validation.js index 2f7e6ed..9fb0fef 100644 --- a/static/main/js/validation.js +++ b/static/main/js/validation.js @@ -88,8 +88,8 @@ $(document).ready(function () { $("#submit-btn").remove() } } -}) -$("#register-form").submit(function (e) { - e.preventDefault() + $("#submit-btn").click(function () { + $("#register-form").submit() + }) }) diff --git a/static/projects/js/projects.js b/static/projects/js/projects.js index e36699d..540b6d8 100644 --- a/static/projects/js/projects.js +++ b/static/projects/js/projects.js @@ -1,9 +1,11 @@ -document.getElementById("cards").onmousemove = (e) => { - for (const CARD of document.getElementsByClassName("card")) { - const RECT = CARD.getBoundingClientRect(), - x = e.clientX - RECT.left, - y = e.clientY - RECT.top - CARD.style.setProperty("--mouse-x", `${x}px`) - CARD.style.setProperty("--mouse-y", `${y}px`) +window.addEventListener("DOMContentLoaded", () => { + document.getElementById("cards").onmousemove = (e) => { + for (const CARD of document.getElementsByClassName("card")) { + const RECT = CARD.getBoundingClientRect(), + x = e.clientX - RECT.left, + y = e.clientY - RECT.top + CARD.style.setProperty("--mouse-x", `${x}px`) + CARD.style.setProperty("--mouse-y", `${y}px`) + } } -} +}) diff --git a/templates/layout.html b/templates/layout.html index e380e67..4a60752 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -5,8 +5,6 @@ - - @@ -27,7 +25,6 @@ <link rel="stylesheet" type="text/css" href="{% static 'main/css/layout.css' %}"/> - <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script> <script src="{% static 'main/js/navigation.js' %}" defer></script> <script src="{% static 'main/js/lightmode.js' %}" defer></script> {% block meta %}{% endblock %} diff --git a/templates/main/validation.html b/templates/main/validation.html index fd5587c..49be582 100644 --- a/templates/main/validation.html +++ b/templates/main/validation.html @@ -5,6 +5,7 @@ <link rel="stylesheet" type="text/css" href="{% static 'main/css/validation.css' %}"/> + <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script> <script src="{% static 'main/js/validation.js' %}" defer></script> {% endblock %} {% block content %} diff --git a/templates/projects/traffic_light_detector/traffic_light_detector.html b/templates/projects/traffic_light_detector/traffic_light_detector.html index d8ef044..64c62ae 100644 --- a/templates/projects/traffic_light_detector/traffic_light_detector.html +++ b/templates/projects/traffic_light_detector/traffic_light_detector.html @@ -137,8 +137,8 @@ detected, according to the expected signal - permission to continue the route. </p> <p> - Ierosinātais risinājums sastāv no 4 pamatprincipiem, kas likvidē cilvēka reakcijas laika ietekmi - uz satiksmes sastrēgumu realizāciju: + The proposed solution consists of 4 basic principles that eliminate the impact of + human reaction time on the realisation of traffic congestion: </p> <ul> <li> @@ -163,7 +163,7 @@ received, using the basic module for the audible signal or the optional light and other user interfaces formats. </li> </ul> - <p>Aprakstītā ierīce pamatprincipu un funkcionalitātes nodrošināšanai izmanto:</p> + <p>The device described uses the following to provide the basic principles and functionality:</p> <ul> <li> Raspberry Pi 4 microcontroller -