More responsiveness
This commit is contained in:
parent
a866692311
commit
a922d0d9de
9 changed files with 65 additions and 90 deletions
|
|
@ -1,56 +1,12 @@
|
|||
const dispatchModalClosed = (modal) => {
|
||||
const dispatchModal = (event, modal) => {
|
||||
let evt = new CustomEvent(
|
||||
"modalClosed",
|
||||
{
|
||||
detail: {
|
||||
message: modal
|
||||
},
|
||||
bubbles: true,
|
||||
cancelable: true
|
||||
}
|
||||
);
|
||||
document.dispatchEvent(evt);
|
||||
};
|
||||
|
||||
const dispatchModalClosing = (modal) => {
|
||||
let evt = new CustomEvent(
|
||||
"modalClosing",
|
||||
{
|
||||
detail: {
|
||||
message: modal
|
||||
},
|
||||
bubbles: true,
|
||||
cancelable: true
|
||||
}
|
||||
);
|
||||
document.dispatchEvent(evt);
|
||||
};
|
||||
|
||||
const dispatchModalOpened = (modal) => {
|
||||
let evt = new CustomEvent(
|
||||
"modalOpened",
|
||||
{
|
||||
detail: {
|
||||
message: modal
|
||||
},
|
||||
bubbles: true,
|
||||
cancelable: true
|
||||
}
|
||||
);
|
||||
document.dispatchEvent(evt);
|
||||
};
|
||||
|
||||
const dispatchModalOpening = (modal) => {
|
||||
let evt = new CustomEvent(
|
||||
"modalOpening",
|
||||
{
|
||||
detail: {
|
||||
message: modal
|
||||
},
|
||||
bubbles: true,
|
||||
cancelable: true
|
||||
}
|
||||
);
|
||||
event, {
|
||||
detail: {
|
||||
modal: modal
|
||||
},
|
||||
bubbles: true,
|
||||
cancelable: false
|
||||
});
|
||||
document.dispatchEvent(evt);
|
||||
};
|
||||
|
||||
|
|
@ -60,10 +16,10 @@ window.addEventListener("DOMContentLoaded", (evt) => {
|
|||
window.onclick = (event) => {
|
||||
if (event.target.classList.contains("modal")) {
|
||||
let modal = event.target;
|
||||
dispatchModalClosing(modal);
|
||||
dispatchModal("modalClosing", modal);
|
||||
modal.classList.remove("visible");
|
||||
modal.removeAttribute("active");
|
||||
dispatchModalClosed(modal);
|
||||
dispatchModal("modalClosed", modal);
|
||||
document.body.classList.remove("modal-no-scroll");
|
||||
}
|
||||
};
|
||||
|
|
@ -72,10 +28,10 @@ window.addEventListener("DOMContentLoaded", (evt) => {
|
|||
document.querySelectorAll(".modal .close").forEach((closeBtn) => {
|
||||
closeBtn.addEventListener('click', (evt) => {
|
||||
let modal = closeBtn.parentElement.parentElement;
|
||||
dispatchModalClosing(modal);
|
||||
dispatchModal("modalClosing", modal);
|
||||
modal.classList.remove("visible");
|
||||
modal.removeAttribute("active");
|
||||
dispatchModalClosed(modal);
|
||||
dispatchModal("modalClosed", modal);
|
||||
document.body.classList.remove("modal-no-scroll");
|
||||
});
|
||||
});
|
||||
|
|
@ -84,10 +40,10 @@ window.addEventListener("DOMContentLoaded", (evt) => {
|
|||
document.body.addEventListener('keydown', (evt) => {
|
||||
if (evt.key == "Escape") {
|
||||
let modal = document.querySelector(".modal[active]");
|
||||
dispatchModalClosing(modal);
|
||||
dispatchModal("modalClosing", modal);
|
||||
modal.classList.remove("visible");
|
||||
modal.removeAttribute("active");
|
||||
dispatchModalClosed(modal);
|
||||
dispatchModal("modalClosed", modal);
|
||||
document.body.classList.remove("modal-no-scroll");
|
||||
}
|
||||
});
|
||||
|
|
@ -96,21 +52,17 @@ window.addEventListener("DOMContentLoaded", (evt) => {
|
|||
document.querySelectorAll("[for-modal]").forEach((modalTrigerEl) => {
|
||||
modalTrigerEl.addEventListener('click', (evt) => {
|
||||
let modal = document.getElementById(modalTrigerEl.getAttribute("for-modal"));
|
||||
|
||||
dispatchModalOpening(modal);
|
||||
|
||||
dispatchModal("modalOpening", modal);
|
||||
modal.classList.add("visible");
|
||||
modal.setAttribute("active", "");
|
||||
|
||||
dispatchModalOpened(modal);
|
||||
|
||||
dispatchModal("modalOpened", modal);
|
||||
document.body.classList.add("modal-no-scroll");
|
||||
});
|
||||
});
|
||||
|
||||
// Destroy embeds on modal close
|
||||
document.addEventListener("modalClosed", (evt) => {
|
||||
evt.detail.message.querySelectorAll("iframe").forEach((iframe) => {
|
||||
evt.detail.modal.querySelectorAll("iframe").forEach((iframe) => {
|
||||
const origSrc = iframe.getAttribute("src");
|
||||
iframe.removeAttribute("src");
|
||||
iframe.setAttribute("data-src", origSrc);
|
||||
|
|
@ -120,7 +72,7 @@ window.addEventListener("DOMContentLoaded", (evt) => {
|
|||
|
||||
// Re-init embeds on modal open
|
||||
document.addEventListener("modalOpening", (evt) => {
|
||||
evt.detail.message.querySelectorAll("iframe").forEach((iframe) => {
|
||||
evt.detail.modal.querySelectorAll("iframe").forEach((iframe) => {
|
||||
if (iframe.hasAttribute("data-src")) {
|
||||
const origSrc = iframe.getAttribute("data-src");
|
||||
iframe.removeAttribute("data-src");
|
||||
|
|
|
|||
Loading…
Reference in a new issue