From 408ba693e43dd9d80e050be28d4378c633ccbecd Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Sat, 20 Sep 2025 17:58:06 +0200 Subject: [PATCH 1/2] maint(pat-zoom): Small code improvements. --- src/pat/zoom/zoom.js | 8 ++++---- src/pat/zoom/zoom.test.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pat/zoom/zoom.js b/src/pat/zoom/zoom.js index 39fc0e39d..57bc863af 100644 --- a/src/pat/zoom/zoom.js +++ b/src/pat/zoom/zoom.js @@ -12,10 +12,10 @@ var zoom = { init: function ($el, opts) { return $el.each(function () { - var $block = $(this), - options = parser.parse($block, opts); + const $block = $(this); + const options = parser.parse($block, opts); - let $slider = $("", { + const $slider = $("", { type: "range", step: "any", value: 1, @@ -28,7 +28,7 @@ var zoom = { }, onZoom: function (event) { - var $block = event.data; + const $block = event.data; $block.css("zoom", this.value); }, }; diff --git a/src/pat/zoom/zoom.test.js b/src/pat/zoom/zoom.test.js index 543f748e0..9c1133d52 100644 --- a/src/pat/zoom/zoom.test.js +++ b/src/pat/zoom/zoom.test.js @@ -40,7 +40,7 @@ describe("pat-zoom", function () { pattern.init($block); var $range = $block.prev(); $range.val("1.5"); - $range.change(); + $range.trigger("change"); // Fairly lax test so it passes in different browsers. expect($block.css("zoom")).toBe("1.5"); }); From a469da4d01631efe77255afbd4f2ab2799caacd5 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Sat, 20 Sep 2025 21:14:20 +0200 Subject: [PATCH 2/2] maint(pat-gallery): Small code improvements. --- src/pat/gallery/gallery.js | 32 ++++++++++++++++++-------------- src/pat/gallery/gallery.test.js | 8 ++++++++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/pat/gallery/gallery.js b/src/pat/gallery/gallery.js index 8cbf7a5de..de1abdca9 100644 --- a/src/pat/gallery/gallery.js +++ b/src/pat/gallery/gallery.js @@ -65,6 +65,20 @@ export default Base.extend({ return template; }, + pswp_options() { + return { + scaleMode: this.options.scaleMethod, + loop: this.options.loop, + slideshowDelay: this.options.delay, + hideAnimationDuration: this.options.effectDuration, + showAnimationDuration: this.options.effectDuration, + pinchToClose: false, + closeOnScroll: false, + // Fix reload on gallery close which was induced by a history back call. + history: false, + }; + }, + initialize_trigger() { const image_wrapper_els = dom.querySelectorAllAndMe( this.el, @@ -108,6 +122,7 @@ export default Base.extend({ // Now - when all is set - prevent default action. e.preventDefault(); + // Get the index of the clicked gallery item in the list of images. const index = this.images .map((it) => it.src) @@ -115,21 +130,10 @@ export default Base.extend({ trigger_el.getAttribute("href") || trigger_el.getAttribute("src") ) || 0; - const options = { - // Get the index of the clicked gallery item in the list of images. - index: index, - scaleMode: this.options.scaleMethod, - loop: this.options.loop, - slideshowDelay: this.options.delay, - hideAnimationDuration: this.options.effectDuration, - showAnimationDuration: this.options.effectDuration, - pinchToClose: false, - closeOnScroll: false, - // Fix reload on gallery close which was induced by a history back call. - history: false, - }; + const pswp_options = this.pswp_options(); + pswp_options.index = index; // start at clicked image - const gallery = new PhotoSwipe(pswp_el, PhotoSwipeUI, this.images, options); + const gallery = new PhotoSwipe(pswp_el, PhotoSwipeUI, this.images, pswp_options); const gallery_reinit_sizes_debouncer = utils.debounce(() => { gallery.updateSize(true); // reinit Items diff --git a/src/pat/gallery/gallery.test.js b/src/pat/gallery/gallery.test.js index 6c1263c0d..9d39881a4 100644 --- a/src/pat/gallery/gallery.test.js +++ b/src/pat/gallery/gallery.test.js @@ -39,6 +39,10 @@ describe("pat-gallery", function () { return; }); + jest.spyOn(instance, "pswp_options").mockImplementation(function () { + return { getThumbBoundsFn: () => ({ x:0, y:0, w:100 }) }; + }); + await utils.timeout(1); expect(spy_init_trigger).toHaveBeenCalled(); @@ -77,6 +81,10 @@ describe("pat-gallery", function () { return; }); + jest.spyOn(instance, "pswp_options").mockImplementation(function () { + return { getThumbBoundsFn: () => ({ x:0, y:0, w:100 }) }; + }); + await utils.timeout(1); expect(spy_init_trigger).toHaveBeenCalledTimes(1);