Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdarkle committed Sep 9, 2024
1 parent d4fae3b commit aac989b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 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.

22 changes: 20 additions & 2 deletions js/src/forum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ app.initializers.add('darkle/fancybox', () => {
if (carouselEl) {
const carousel = carousels.get(carouselEl.id);
if (carousel) {
carousel.slideTo(lastSlide.index, { friction: 0 });
// Use setTimeout to delay the carousel slide
setTimeout(() => {
carousel.slideTo(lastSlide.index, { friction: 0 });
}, 0);
}
}
}
Expand Down Expand Up @@ -108,19 +111,34 @@ app.initializers.add('darkle/fancybox', () => {
const group = postBody.querySelectorAll(`a[data-fancybox="${groupName}"]`);
const index = Array.from(group).indexOf(link);

// Store the current scroll position
const scrollPosition = window.pageYOffset;

Fancybox.show(
Array.from(group).map(el => {
const img = el.querySelector('img');
return {
src: img.getAttribute('data-src') || img.src,
thumb: img.src,
type: 'image',
triggerEl: el, // Add this line to set the triggerEl
triggerEl: el,
};
}),
{
...fancyboxOptions,
startIndex: index,
on: {
...fancyboxOptions.on,
destroy: (fancybox) => {
if (fancyboxOptions.on.destroy) {
fancyboxOptions.on.destroy(fancybox);
}
// Restore the scroll position after a short delay
setTimeout(() => {
window.scrollTo(0, scrollPosition);
}, 0);
},
},
}
);
}
Expand Down

0 comments on commit aac989b

Please sign in to comment.