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 0d745db commit 5c1ef94
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 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.

20 changes: 15 additions & 5 deletions js/src/forum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ app.initializers.add('darkle/fancybox', () => {
}
});

// Setup Fancybox for all images
const fancyboxOptions = {
Carousel: {
infinite: false,
Expand Down Expand Up @@ -74,7 +73,6 @@ app.initializers.add('darkle/fancybox', () => {
dragToClose: false,
};

// Handle clicks on Fancybox-enabled links
postBody.querySelectorAll('a[data-fancybox]').forEach(link => {
let isDragging = false;
let startX, startY;
Expand All @@ -97,13 +95,25 @@ app.initializers.add('darkle/fancybox', () => {
const groupName = link.getAttribute('data-fancybox');
const group = postBody.querySelectorAll(`a[data-fancybox="${groupName}"]`);
const index = Array.from(group).indexOf(link);
Fancybox.fromNodes(Array.from(group), {

const fancyboxInstance = Fancybox.fromNodes(Array.from(group), {
...fancyboxOptions,
startIndex: index,
});

// Sync slide changes between Carousel and Fancybox
fancyboxInstance.Carousel.on('change', (carousel, slide) => {
const currentSlideIndex = slide.index;
const carouselEl = slide.triggerEl.closest('.fancybox-gallery');
if (carouselEl) {
const carousel = carousels.get(carouselEl.id);
if (carousel) {
carousel.slideTo(currentSlideIndex, { friction: 0 });
}
}
});
}
});
});
};
});
});

0 comments on commit 5c1ef94

Please sign in to comment.