| ---
|
| import "@fancyapps/ui/dist/fancybox/fancybox.css";
|
| import "@/styles/fancybox-custom.css";
|
|
|
| ---
|
|
|
| <script>
|
| let Fancybox: any;
|
|
|
| async function setup() {
|
| const selectors = [
|
| ".custom-md img, #post-cover img, .moment-images img",
|
| ".moment-images a[data-fancybox]",
|
| "[data-fancybox]:not(.moment-images a)"
|
| ];
|
|
|
|
|
| const hasElements = selectors.some(selector => document.querySelector(selector));
|
|
|
| if (!hasElements) return;
|
|
|
|
|
| if (!Fancybox) {
|
| const mod = await import("@fancyapps/ui");
|
| Fancybox = mod.Fancybox;
|
| }
|
|
|
|
|
| const commonOptions = {
|
| Thumbs: {
|
| autoStart: true,
|
| showOnStart: "yes",
|
| },
|
| Toolbar: {
|
| display: {
|
| left: ["infobar"],
|
| middle: [
|
| "zoomIn",
|
| "zoomOut",
|
| "toggle1to1",
|
| "rotateCCW",
|
| "rotateCW",
|
| "flipX",
|
| "flipY",
|
| ],
|
| right: ["slideshow", "thumbs", "close"],
|
| },
|
| },
|
| animated: true,
|
| dragToClose: true,
|
| keyboard: {
|
| Escape: "close",
|
| Delete: "close",
|
| Backspace: "close",
|
| PageUp: "next",
|
| PageDown: "prev",
|
| ArrowUp: "next",
|
| ArrowDown: "prev",
|
| ArrowRight: "next",
|
| ArrowLeft: "prev",
|
| },
|
| fitToView: true,
|
| preload: 3,
|
| infinite: true,
|
| Panzoom: {
|
| maxScale: 3,
|
| minScale: 1,
|
| },
|
| caption: false,
|
| };
|
|
|
|
|
| Fancybox.bind(".custom-md img, #post-cover img, .moment-images img", {
|
| ...commonOptions,
|
| groupAll: true,
|
| Carousel: {
|
| transition: "slide",
|
| preload: 2,
|
| },
|
| });
|
|
|
|
|
| Fancybox.bind(".moment-images a[data-fancybox]", {
|
| ...commonOptions,
|
| source: (el: any) => el.getAttribute("data-src") || el.getAttribute("href"),
|
| });
|
|
|
|
|
| Fancybox.bind("[data-fancybox]:not(.moment-images a)", commonOptions);
|
| }
|
|
|
| function cleanupFancybox() {
|
| if (Fancybox) {
|
| Fancybox.close();
|
| Fancybox.unbind(document.body);
|
| }
|
| }
|
|
|
|
|
| setup();
|
|
|
|
|
| document.addEventListener("swup:content:replace", setup);
|
| document.addEventListener("swup:visit:start", cleanupFancybox);
|
| </script>
|
|
|