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 41e1260 commit 9b17861
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 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.

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

// Initialize Fancybox
Fancybox.bind(postBody, '[data-fancybox]', {
// Fancybox options
const fancyboxOptions = {
Carousel: {
infinite: false,
},
Expand Down Expand Up @@ -65,9 +65,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 @@ -85,9 +85,22 @@ 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.show(
Array.from(group).map(el => ({
src: el.href,
type: 'image',
})),
{
...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 9b17861

Please sign in to comment.