Skip to content
Merged

Upgrade #1266

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/pat/gallery/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -108,28 +122,18 @@ 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)
.indexOf(
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
Expand Down
8 changes: 8 additions & 0 deletions src/pat/gallery/gallery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/pat/zoom/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $("<input/>", {
const $slider = $("<input/>", {
type: "range",
step: "any",
value: 1,
Expand All @@ -28,7 +28,7 @@ var zoom = {
},

onZoom: function (event) {
var $block = event.data;
const $block = event.data;
$block.css("zoom", this.value);
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/pat/zoom/zoom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand Down