From d1a883a2d724b2723e255b3967ca0d1fd2759fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Wed, 13 Mar 2024 14:59:02 +0100 Subject: [PATCH] Add modal for GONG charte --- index.html | 17 +++++++++++++++++ js/main.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 js/main.js diff --git a/index.html b/index.html index f3f246d..2d05973 100644 --- a/index.html +++ b/index.html @@ -21,6 +21,7 @@

La résistance à l'oppression est un droit naturel L. DELGRES

+

LA CHARTE DU GONG - Juin 1963


@@ -41,5 +42,21 @@ {{/data}} + + diff --git a/js/main.js b/js/main.js new file mode 100644 index 0000000..4791b80 --- /dev/null +++ b/js/main.js @@ -0,0 +1,42 @@ +document.addEventListener('DOMContentLoaded', () => { + // Functions to open and close a modal + function openModal($el) { + $el.classList.add('is-active'); + } + + function closeModal($el) { + $el.classList.remove('is-active'); + } + + function closeAllModals() { + (document.querySelectorAll('.modal') || []).forEach(($modal) => { + closeModal($modal); + }); + } + + // Add a click event on buttons to open a specific modal + (document.querySelectorAll('.js-modal-trigger') || []).forEach(($trigger) => { + const modal = $trigger.dataset.target; + const $target = document.getElementById(modal); + + $trigger.addEventListener('click', () => { + openModal($target); + }); + }); + + // Add a click event on various child elements to close the parent modal + (document.querySelectorAll('.modal-background, .modal-close, .modal-card-head .delete, .modal-card-foot .button') || []).forEach(($close) => { + const $target = $close.closest('.modal'); + + $close.addEventListener('click', () => { + closeModal($target); + }); + }); + + // Add a keyboard event to close all modals + document.addEventListener('keydown', (event) => { + if(event.key === "Escape") { + closeAllModals(); + } + }); +});