From 4dc97daf63567b9108c04d18e2961451c3d5a553 Mon Sep 17 00:00:00 2001 From: Kilian Hofmann Date: Fri, 24 May 2024 21:37:33 +0200 Subject: [PATCH] Theme Switcher --- homework/1/colourSelector/index.php | 56 +++++++++++++++++ .../1/colourSelector/js/formValidation.js | 37 +++++++++++ homework/1/themeSwitcher/css/black.css | 13 ++++ homework/1/themeSwitcher/css/pink.css | 14 +++++ homework/1/themeSwitcher/index.php | 62 +++++++++++++++++++ homework/1/themeSwitcher/js/formValidation.js | 37 +++++++++++ homework/colourSelector/index.php | 46 -------------- homework/colourSelector/js/formValidation.js | 33 ---------- 8 files changed, 219 insertions(+), 79 deletions(-) create mode 100644 homework/1/colourSelector/index.php create mode 100644 homework/1/colourSelector/js/formValidation.js create mode 100644 homework/1/themeSwitcher/css/black.css create mode 100644 homework/1/themeSwitcher/css/pink.css create mode 100644 homework/1/themeSwitcher/index.php create mode 100644 homework/1/themeSwitcher/js/formValidation.js delete mode 100644 homework/colourSelector/index.php delete mode 100644 homework/colourSelector/js/formValidation.js diff --git a/homework/1/colourSelector/index.php b/homework/1/colourSelector/index.php new file mode 100644 index 0000000..d60346d --- /dev/null +++ b/homework/1/colourSelector/index.php @@ -0,0 +1,56 @@ + + + + + + + Colour Selector + + + + + + + + +
+
+ > + +
+
+
+ + +
+ Please enter valid hex colour code +
+
+ +
+ +

+ +
+ + + \ No newline at end of file diff --git a/homework/1/colourSelector/js/formValidation.js b/homework/1/colourSelector/js/formValidation.js new file mode 100644 index 0000000..9eeb1b6 --- /dev/null +++ b/homework/1/colourSelector/js/formValidation.js @@ -0,0 +1,37 @@ +"use strict"; + +document.addEventListener("DOMContentLoaded", () => { + const handler = (event) => { + if (!event.target.checkValidity()) { + event.preventDefault(); + event.stopPropagation(); + } + + event.target.classList.add("was-validated"); + }; + + const addValidation = () => { + const forms = document.querySelectorAll(".needs-validation"); + + Array.from(forms).forEach((form) => { + form.addEventListener("submit", handler, false); + }); + }; + + const removeValidation = () => { + const forms = document.querySelectorAll(".needs-validation"); + + Array.from(forms).forEach((form) => { + form.removeEventListener("submit", handler, false); + }); + }; + + const switchHandler = () => { + _switch.checked ? addValidation() : removeValidation(); + document.cookie = `validation=${_switch.checked}`; + }; + + const _switch = document.getElementById("clientSideValidate"); + _switch.addEventListener("change", switchHandler); + switchHandler(); +}); diff --git a/homework/1/themeSwitcher/css/black.css b/homework/1/themeSwitcher/css/black.css new file mode 100644 index 0000000..8e03a45 --- /dev/null +++ b/homework/1/themeSwitcher/css/black.css @@ -0,0 +1,13 @@ +:root { + --bs-body-bg: black; + --bs-body-color: white; +} + +body { + background-color: black; + color: white; +} + +.form-select { + --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e"); +} \ No newline at end of file diff --git a/homework/1/themeSwitcher/css/pink.css b/homework/1/themeSwitcher/css/pink.css new file mode 100644 index 0000000..a21de4a --- /dev/null +++ b/homework/1/themeSwitcher/css/pink.css @@ -0,0 +1,14 @@ +:root { + --bs-body-bg: pink; + --bs-border-color: red; + --bs-body-color: red; +} + +body { + background-color: pink; + color: red; +} + +.form-select { + --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23ff0000' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e"); +} \ No newline at end of file diff --git a/homework/1/themeSwitcher/index.php b/homework/1/themeSwitcher/index.php new file mode 100644 index 0000000..6ccd8e0 --- /dev/null +++ b/homework/1/themeSwitcher/index.php @@ -0,0 +1,62 @@ + + + + + + + Theme Switcher + + + + true, "secure" => true, "samesite" => "strict"]); + Headers::redirect("./"); + } else if (isset($_COOKIE["theme"])) { + $theme = $_COOKIE["theme"]; + } + + Headers::html(); + ?> + + + + + + + + + + + +
+
+ > + +
+
+
+ +
+ Please select a valid state. +
+
+ +
+ +

+ +
+ + + \ No newline at end of file diff --git a/homework/1/themeSwitcher/js/formValidation.js b/homework/1/themeSwitcher/js/formValidation.js new file mode 100644 index 0000000..9eeb1b6 --- /dev/null +++ b/homework/1/themeSwitcher/js/formValidation.js @@ -0,0 +1,37 @@ +"use strict"; + +document.addEventListener("DOMContentLoaded", () => { + const handler = (event) => { + if (!event.target.checkValidity()) { + event.preventDefault(); + event.stopPropagation(); + } + + event.target.classList.add("was-validated"); + }; + + const addValidation = () => { + const forms = document.querySelectorAll(".needs-validation"); + + Array.from(forms).forEach((form) => { + form.addEventListener("submit", handler, false); + }); + }; + + const removeValidation = () => { + const forms = document.querySelectorAll(".needs-validation"); + + Array.from(forms).forEach((form) => { + form.removeEventListener("submit", handler, false); + }); + }; + + const switchHandler = () => { + _switch.checked ? addValidation() : removeValidation(); + document.cookie = `validation=${_switch.checked}`; + }; + + const _switch = document.getElementById("clientSideValidate"); + _switch.addEventListener("change", switchHandler); + switchHandler(); +}); diff --git a/homework/colourSelector/index.php b/homework/colourSelector/index.php deleted file mode 100644 index 8435490..0000000 --- a/homework/colourSelector/index.php +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - Colour Selector - - - - - - - - -
- - -
-
-
- - -
- Please enter valid hex colour code -
-
- -
- - - \ No newline at end of file diff --git a/homework/colourSelector/js/formValidation.js b/homework/colourSelector/js/formValidation.js deleted file mode 100644 index 77f2903..0000000 --- a/homework/colourSelector/js/formValidation.js +++ /dev/null @@ -1,33 +0,0 @@ -"use strict"; - -document.addEventListener("DOMContentLoaded", () => { - const _switch = document.getElementById("clientSideValidate"); - _switch.addEventListener("change", () => - _switch.checked ? addValidation() : removeValidation() - ); -}); - -const handler = (event) => { - if (!event.target.checkValidity()) { - event.preventDefault(); - event.stopPropagation(); - } - - event.target.classList.add("was-validated"); -}; - -const addValidation = () => { - const forms = document.querySelectorAll(".needs-validation"); - - Array.from(forms).forEach((form) => { - form.addEventListener("submit", handler, false); - }); -}; - -const removeValidation = () => { - const forms = document.querySelectorAll(".needs-validation"); - - Array.from(forms).forEach((form) => { - form.removeEventListener("submit", handler, false); - }); -};