Skip to content

Commit

Permalink
try again
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdarkle committed Sep 9, 2024
1 parent 22d4d42 commit 2d73d10
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion js/dist/forum.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/forum.js.map

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion js/src/forum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ app.initializers.add('darkle/fancybox', () => {
initialSize: 'fit',
},
on: {
done: (fancybox, slide) => {
init: (fancybox) => {
const slide = fancybox.getSlide();
const carouselEl = slide.triggerEl.closest('.fancybox-gallery');
if (carouselEl) {
const carousel = carousels.get(carouselEl.id);
Expand All @@ -63,6 +64,16 @@ app.initializers.add('darkle/fancybox', () => {
}
}
},
destroy: (fancybox) => {
const lastSlide = fancybox.getSlide();
const carouselEl = lastSlide.triggerEl.closest('.fancybox-gallery');
if (carouselEl) {
const carousel = carousels.get(carouselEl.id);
if (carousel) {
carousel.slideTo(lastSlide.index, { friction: 0 });
}
}
},
},
dragToClose: false,
};
Expand Down Expand Up @@ -108,6 +119,19 @@ app.initializers.add('darkle/fancybox', () => {
}
});
});

// Sync carousels with Fancybox
carousels.forEach((carousel, id) => {
carousel.on('change', (carousel) => {
const fancybox = Fancybox.getInstance();
if (fancybox) {
const currentSlide = fancybox.getSlide();
if (currentSlide && currentSlide.triggerEl.closest('.fancybox-gallery').id === id) {
fancybox.setPage(carousel.page);
}
}
});
});
};
});

Expand Down

0 comments on commit 2d73d10

Please sign in to comment.