Skip to content

Commit c55fc16

Browse files
committed
add new hooks
1 parent 9e5a17d commit c55fc16

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

assets/js/app.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,52 @@ const Hooks = {
857857
// }
858858
// },
859859
},
860+
LoadFromHash: {
861+
mounted() {
862+
const hash = window.location.hash.substring(1);
863+
if (hash) {
864+
try {
865+
const data = JSON.parse(decodeURIComponent(atob(hash)));
866+
this.pushEvent("hash_load_success", data);
867+
} catch (error) {
868+
this.pushEvent("hash_load_failure", { error: error.message });
869+
}
870+
}
871+
872+
this.handleEvent("close-window", ({ delay }) => {
873+
setTimeout(() => {
874+
window.close();
875+
}, delay || 0);
876+
});
877+
},
878+
},
879+
LazyLoadImage: {
880+
mounted() {
881+
const container = this.el;
882+
const img = container.querySelector("img");
883+
884+
if (!img) return;
885+
886+
const dataSrc = img.getAttribute("data-src");
887+
if (!dataSrc) return;
888+
889+
// Find the parent link element to listen for hover
890+
const trigger = container.closest(".group");
891+
if (!trigger) return;
892+
893+
let hasLoaded = false;
894+
895+
const loadImage = () => {
896+
console.log("loading image", dataSrc);
897+
if (hasLoaded) return;
898+
hasLoaded = true;
899+
img.src = dataSrc;
900+
img.classList.remove("invisible");
901+
};
902+
903+
trigger.addEventListener("mouseenter", loadImage);
904+
},
905+
},
860906
} satisfies Record<string, Partial<ViewHook> & Record<string, unknown>>;
861907

862908
// Accessible focus handling

0 commit comments

Comments
 (0)