From: Eduardo Date: Sat, 2 Dec 2023 20:27:40 +0000 (+0100) Subject: script to show the forms X-Git-Url: http://git.edufdez.es/?a=commitdiff_plain;h=fad3bb746d671b649f194d8c361e6433c093cfc1;p=thericegoat.com.git script to show the forms --- diff --git a/src/assets/js/forms_scripts.js b/src/assets/js/forms_scripts.js new file mode 100644 index 0000000..1af5339 --- /dev/null +++ b/src/assets/js/forms_scripts.js @@ -0,0 +1,58 @@ +/*____::::::::::_:::::::::__:::____:::_::::::::::_:::::::::__::::::::::_:::::::::_____::::::::::_::::::::_ +_____:+:________:+:____:+:_:+:____:+:_:+:________:+:____:+:_:+:_____________:+:______:+:_______:+:____:+:_ +____+:+________+:+____+:+_+:+____+:+_+:+________+:+____+:+_+:+____________+:+_______+:+_______+:+_________ +___+#++:++#___+#+____+:+_+#+____+:+_:#::+::#___+#+____+:+_+#++:++#______+#+________+#++:++#__+#++:++#++___ +__+#+________+#+____+#+_+#+____+#+_+#+________+#+____+#+_+#+__________+#+_________+#+______________+#+____ +_#+#________#+#____#+#_#+#____#+#_#+#________#+#____#+#_#+#_________#+#______#+#_#+#_______#+#____#+#_____ +##########_#########___########__###________#########__##########_#########_###_##########_########_____*/ + +/* + @author Eduardo Fernandez + @url https://edufdez.es + @license All Rights Reserved. + @created 2023-12-02 + @modified 2023-12-02 + @description This script is used to show/hide the form based on the 't' parameter in the URL. + If the 't' parameter is not present in the URL, then the form will be hidden. +*/ + +document.addEventListener("DOMContentLoaded", function () { + prepareForm(); +}); + +function prepareForm() { + const url = new URL(window.location.href); + const filteredUrl = url.pathname.split("/").filter((el) => el != ""); + const page = filteredUrl.pop(); + const params = url.searchParams; + if (page !== "forms") { + return; + } + + const formType = params.get("t"); + console.log(formType); // Print the value of 't' parameter + + const elements = document.querySelectorAll(".no-" + formType); + elements.forEach((element) => HideElement(element)); + + // get all elements + const allElements = document.querySelectorAll(".content *"); + console.log(allElements); + allElements.forEach((element) => { + if (element.classList.contains("no-" + formType)) { + HideElement(element); + } else { + element.classList.forEach((className) => { + if (className.startsWith("only-")) { + if (!element.classList.contains("only-" + formType)) { + HideElement(element); + } + } + }); + } + }); +} + +function HideElement(element) { + element.style.display = "none"; +}