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 6be9ebe commit ad7b6cc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 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.

40 changes: 26 additions & 14 deletions js/src/forum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,17 @@ app.initializers.add('darkle/fancybox', () => {
};

CommentPost.prototype.cleanupFancybox = function() {
Fancybox.close();
this.carousels.forEach(carousel => carousel.destroy());
this.carousels.clear();
if (Fancybox.getInstance()) {
Fancybox.close(true); // Force close any open instance
}
if (this.carousels) {
this.carousels.forEach(carousel => {
if (carousel && typeof carousel.destroy === 'function') {
carousel.destroy();
}
});
this.carousels.clear();
}
this.fancyboxInitialized = false;
};

Expand Down Expand Up @@ -81,7 +89,7 @@ app.initializers.add('darkle/fancybox', () => {
this.carousels.set(gallery.id, carousel);
}
});

const fancyboxOptions = {
Carousel: {
infinite: false,
Expand All @@ -107,41 +115,44 @@ app.initializers.add('darkle/fancybox', () => {
}
}
},
"close": (fancybox, event) => {
event.preventDefault();
"closing": (fancybox) => {
// Perform any necessary cleanup or actions before Fancybox closes
},
"destroy": (fancybox) => {
// Perform any necessary cleanup after Fancybox is destroyed
}
},
dragToClose: true,
dragToClose: false,
};

postBody.querySelectorAll('a[data-fancybox]').forEach(link => {
let isDragging = false;
let startX, startY;

link.addEventListener('mousedown', (e) => {
isDragging = false;
startX = e.clientX;
startY = e.clientY;
});

link.addEventListener('mousemove', (e) => {
if (Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5) {
isDragging = true;
}
});

link.addEventListener('click', (e) => {
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);

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

// Sync slide changes between Carousel and Fancybox
fancyboxInstance.on('Carousel.ready Carousel.change', (fancybox) => {
const slide = fancybox.getSlide();
Expand All @@ -157,4 +168,5 @@ app.initializers.add('darkle/fancybox', () => {
}
});
});
};
};
});

0 comments on commit ad7b6cc

Please sign in to comment.