Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdarkle committed Sep 8, 2024
1 parent 9041adc commit 618035c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 35 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.

36 changes: 6 additions & 30 deletions js/src/forum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,14 @@ app.initializers.add('darkle/fancybox', () => {
extend(CommentPost.prototype, 'oncreate', function () {
const postBody = this.element.querySelector('.Post-body');

// Function to get the correct image URL
const getImageUrl = (element) => {
const img = element.querySelector('img');
return img ? (img.getAttribute('data-src') || img.getAttribute('src')) : element.href;
};

// Initialize Carousel for each gallery
const carousels = [];
postBody.querySelectorAll('.fancybox-gallery').forEach((gallery, index) => {
gallery.id = `gallery-${index}`;
const carousel = new Carousel(gallery, {
new Carousel(gallery, {
Dots: false,
infinite: false,
dragFree: true,
});
carousels.push(carousel);
});

// Initialize Fancybox for both galleries and single images
Expand All @@ -45,39 +37,23 @@ app.initializers.add('darkle/fancybox', () => {
Images: {
initialSize: 'fit',
},
on: {
done: (fancybox, slide) => {
const carousel = carousels.find(c => c.container.id === slide.triggerEl.closest('.fancybox-gallery').id);
if (carousel) {
carousel.slideTo(slide.index, { friction: 0 });
}
},
},
});

// Prevent Fancybox from opening when dragging the carousel
postBody.querySelectorAll('.fancybox-gallery').forEach(gallery => {
let isDragging = false;
let startX, startY;

gallery.addEventListener('mousedown', e => {
gallery.addEventListener('mousedown', () => {
isDragging = false;
startX = e.pageX;
startY = e.pageY;
});

gallery.addEventListener('mousemove', e => {
if (Math.abs(e.pageX - startX) > 5 || Math.abs(e.pageY - startY) > 5) {
isDragging = true;
}
gallery.addEventListener('mousemove', () => {
isDragging = true;
});

gallery.addEventListener('click', e => {
gallery.addEventListener('mouseup', (e) => {
if (isDragging) {
e.preventDefault();
e.stopPropagation();
}
}, true);
});
});
});
});
6 changes: 3 additions & 3 deletions src/DefineGalleryTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ public function __invoke(Configurator $config)

if ($config->tags->exists('IMG')) {
$tag = $config->tags->get('IMG');
$originalTemplate = $tag->template;
$newTemplate = $tag->template;
$tag->template = <<<XML
<xsl:choose>
<xsl:when test="parent::FANCYBOX-GALLERY-ITEM">
<a data-fancybox="gallery" href="{@url}">
$originalTemplate
$newTemplate
</a>
</xsl:when>
<xsl:otherwise>
<a data-fancybox="single" href="{@url}">
$originalTemplate
$newTemplate
</a>
</xsl:otherwise>
</xsl:choose>
Expand Down

0 comments on commit 618035c

Please sign in to comment.