Skip to content

Commit

Permalink
Update: Dispatch event on close
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnitto committed Jan 5, 2024
1 parent acbaf94 commit b08e4d5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
14 changes: 10 additions & 4 deletions Resources/Private/Assets/Fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ function init(options = {}) {
container?.addEventListener("click", pswpContentEventListener);
});

lightbox.on("destroy", () => {
dispatchEvent({ type: "fetch", action: "close" });
});

lightbox.on("contentLoad", async (event) => {
const { content } = event;
let src = content?.data?.src;
Expand Down Expand Up @@ -87,10 +91,7 @@ async function fetchUrl(url, fetchLinkAppend) {
}
const markup = await response.text();
url = completeUrl(url);
const event = new CustomEvent("neosphotoswipe", {
detail: { url, lightbox: url + fetchLinkAppend, type: "fetch" },
});
document.dispatchEvent(event);
dispatchEvent({ url, lightbox: url + fetchLinkAppend, type: "fetch", action: "open" });
return markup;
}

Expand Down Expand Up @@ -130,6 +131,11 @@ function toggleLoadingClass(show = true) {
getPswpContainer()?.classList.toggle("pswp--fetch-loading", show);
}

function dispatchEvent(detail) {
const event = new CustomEvent("neosphotoswipe", { detail });
document.dispatchEvent(event);
}

window.neosPhotoSwipe = window.neosPhotoSwipe || {};
window.neosPhotoSwipe.fetch = {
init,
Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/Modules/Fetch.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b08e4d5

Please sign in to comment.