6 changed files with 77 additions and 32 deletions
-
17source/_asso.erb
-
12source/_infos.erb
-
55source/javascripts/site.js
-
2source/layouts/layout.erb
-
2source/stylesheets/_variables.scss
-
21source/stylesheets/site.css.scss
@ -1,25 +1,44 @@ |
|||
document.addEventListener('DOMContentLoaded', () => { |
|||
const modalBackground = document.querySelector("#modal-background") |
|||
// const close = modalBackground.querySelector(".close")
|
|||
modalBackground.addEventListener("click", () => { |
|||
const modals = document.querySelectorAll("[data-modal].show") |
|||
modals.forEach((m) => { |
|||
m.classList.remove("show") |
|||
m.classList.add("hide") |
|||
}) |
|||
modalBackground.classList.remove("show") |
|||
}) |
|||
window.modals = { |
|||
init: function () { |
|||
this.modalBackground = document.querySelector("#modal-background") |
|||
this.closeButton = this.modalBackground.querySelector(".close") |
|||
|
|||
document.querySelectorAll("[data-modal-target]").forEach((e) => { |
|||
const target = e.dataset.modalTarget |
|||
const modal = document.querySelector(`[data-modal="${target}"]`) |
|||
modalBackground.appendChild(modal) |
|||
this.modalBackground.addEventListener("click", () => { |
|||
const modals = document.querySelectorAll("[data-modal].show") |
|||
modals.forEach(m => this.close(m)) |
|||
this.modalBackground.classList.remove("show") |
|||
}) |
|||
|
|||
e.addEventListener("click", () => { |
|||
modalBackground.classList.add("show") |
|||
document.querySelectorAll("[data-modal-target]").forEach(e => { |
|||
const target = e.dataset.modalTarget |
|||
const modal = this.get(target) |
|||
this.modalBackground.appendChild(modal) |
|||
e.addEventListener("click", () => this.open(modal)) |
|||
}) |
|||
|
|||
const target = window.location.hash.substr(1) |
|||
const modal = this.get(target) |
|||
if (modal) this.open(modal) |
|||
}, |
|||
|
|||
get: function (name) { |
|||
return document.querySelector(`[data-modal="${name}"]`) |
|||
}, |
|||
|
|||
open: function (modal) { |
|||
modal.appendChild(this.closeButton) |
|||
this.modalBackground.classList.add("show") |
|||
modal.classList.remove("hide") |
|||
modal.classList.add("show") |
|||
}) |
|||
}) |
|||
}, |
|||
|
|||
close: function (modal) { |
|||
modal.classList.remove("show") |
|||
modal.classList.add("hide") |
|||
this.modalBackground.appendChild(this.closeButton) |
|||
} |
|||
} |
|||
|
|||
window.modals.init() |
|||
}) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue