Skip to content

Commit 5abca91

Browse files
committed
fix(pat gallery): Unhide/hide the gallery template when opening/closing it. Fixes some layout issues when gallery isn't closed properly.
1 parent 30227e6 commit 5abca91

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/pat/gallery/gallery.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ export default Base.extend({
3434

3535
// Use default template, if no other template is defined.
3636
if (!document.getElementById("photoswipe-template")) {
37-
const Template = (await import("./template.html")).default;
38-
const template_el = document.createElement("div");
39-
template_el.setAttribute("class", "pat-gallery__template-wrapper");
40-
template_el.innerHTML = Template;
41-
document.body.appendChild(template_el);
37+
const raw_template = (await import("./template.html")).default;
38+
this.template = document.createElement("div");
39+
this.template.setAttribute("class", "pat-gallery__template-wrapper");
40+
this.template.setAttribute("hidden", "");
41+
this.template.innerHTML = raw_template;
42+
document.body.appendChild(this.template);
4243
}
4344

4445
this.initialize_trigger();
@@ -78,6 +79,7 @@ export default Base.extend({
7879
const trigger_el = e.currentTarget;
7980
e.preventDefault();
8081

82+
this.template.removeAttribute("hidden");
8183
const pswpElement = document.querySelector(".pswp");
8284

8385
const index =
@@ -129,6 +131,7 @@ export default Base.extend({
129131
gallery.listen("destroy", () => {
130132
// show original overlay value on body after closing
131133
document.body.style.overflow = this.orig_body_overflow;
134+
this.template.setAttribute("hidden", "");
132135
});
133136

134137
gallery.init();

0 commit comments

Comments
 (0)