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 54f1f1c commit 6a0c396
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 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.

18 changes: 11 additions & 7 deletions js/src/forum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ import { extend } from 'flarum/common/extend';
import CommentPost from 'flarum/forum/components/CommentPost';
import { Fancybox } from '@fancyapps/ui';
import { Carousel } from '@fancyapps/ui';
import '@fancyapps/ui/dist/fancybox/fancybox.css';
import '@fancyapps/ui/dist/carousel/carousel.css';

app.initializers.add('darkle/fancybox', () => {
extend(CommentPost.prototype, 'oncreate', function (vnode) {
// Wrap images with anchor tags for Fancybox
// Wrap images with anchor tags for Fancybox, only if not already wrapped
this.element
.querySelectorAll('.Post-body img:not(.emoji):not(.Avatar):not(.PostMeta-ip img):not([data-reaction]):not([data-link-preview]):not(.flamoji img):not(.countryFlag):not(.no-fancybox)')
.forEach((node) => {
const src = node.getAttribute('data-src') || node.getAttribute('src');
const fancyboxEl = document.createElement('a');
fancyboxEl.setAttribute('data-fancybox', 'gallery');
fancyboxEl.href = src;
node.parentNode.insertBefore(fancyboxEl, node);
fancyboxEl.appendChild(node);
if (!node.closest('a[data-fancybox="gallery"]')) {
const src = node.getAttribute('data-src') || node.getAttribute('src');
const fancyboxEl = document.createElement('a');
fancyboxEl.setAttribute('data-fancybox', 'gallery');
fancyboxEl.href = src;
node.parentNode.insertBefore(fancyboxEl, node);
fancyboxEl.appendChild(node);
}
});

// Initialize Carousel
Expand Down

0 comments on commit 6a0c396

Please sign in to comment.