Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdarkle committed Sep 8, 2024
1 parent bfa39fe commit 2f00ec9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 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.

23 changes: 15 additions & 8 deletions js/src/forum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ app.initializers.add('darkle/fancybox', () => {
const carousel = new Carousel(gallery, {
Dots: false,
infinite: false,
dragFree: true,
dragFree: false,
});
carousels.set(gallery.id, carousel);
}
});

// Initialize Fancybox
Fancybox.bind(postBody, '[data-fancybox]', {
// Setup Fancybox for all images
const fancyboxOptions = {
Carousel: {
infinite: false,
},
Expand Down Expand Up @@ -72,9 +72,9 @@ app.initializers.add('darkle/fancybox', () => {
},
},
dragToClose: false,
});
};

// Prevent default link behavior and handle dragging
// Handle clicks on Fancybox-enabled links
postBody.querySelectorAll('a[data-fancybox]').forEach(link => {
let isDragging = false;
let startX, startY;
Expand All @@ -92,9 +92,16 @@ app.initializers.add('darkle/fancybox', () => {
});

link.addEventListener('click', (e) => {
if (isDragging) {
e.preventDefault();
e.stopPropagation();
e.preventDefault();
if (!isDragging) {
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), {
...fancyboxOptions,
startIndex: index,
});
}
});
});
Expand Down
14 changes: 6 additions & 8 deletions src/DefineGalleryTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,22 @@ public function __invoke(Configurator $config)
<xsl:choose>
<xsl:when test="parent::FANCYBOX-GALLERY-ITEM">
<a data-fancybox="gallery" href="{@url}">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<img>
<xsl:copy-of select="@*"/>
<xsl:attribute name="data-src">
<xsl:value-of select="@url"/>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</img>
</a>
</xsl:when>
<xsl:otherwise>
<a data-fancybox="single" href="{@url}">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<img>
<xsl:copy-of select="@*"/>
<xsl:attribute name="data-src">
<xsl:value-of select="@url"/>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</img>
</a>
</xsl:otherwise>
</xsl:choose>
Expand Down

0 comments on commit 2f00ec9

Please sign in to comment.