feat: Add Credits & Attribution page
- add credits.njk - add credits.css - add tooltips.js - add link in footer
This commit is contained in:
47
src/scripts/tooltips.js
Normal file
47
src/scripts/tooltips.js
Normal file
@@ -0,0 +1,47 @@
|
||||
// JS for tooltip hover
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
// Hide inline thumbs when JS is available
|
||||
document.querySelectorAll(".thumb-inline").forEach(img => img.style.display = "none");
|
||||
|
||||
// Tooltip element
|
||||
const tip = document.createElement("div");
|
||||
tip.className = "thumb-tooltip";
|
||||
document.body.appendChild(tip);
|
||||
|
||||
function positionTip(el) {
|
||||
const rect = el.getBoundingClientRect();
|
||||
const tipRect = tip.getBoundingClientRect();
|
||||
let left = rect.left + window.scrollX;
|
||||
if (left + tipRect.width > window.innerWidth) {
|
||||
left = window.innerWidth - tipRect.width - 8; // small margin
|
||||
}
|
||||
tip.style.top = (rect.bottom + window.scrollY + 6) + "px";
|
||||
tip.style.left = left + "px";
|
||||
}
|
||||
|
||||
|
||||
function show(e) {
|
||||
const url = e.currentTarget.getAttribute("data-tooltip");
|
||||
if (!url) return;
|
||||
|
||||
// Preload image to get natural size
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
tip.style.width = img.naturalWidth + "px";
|
||||
tip.style.height = img.naturalHeight + "px";
|
||||
tip.style.backgroundImage = `url("${url}")`;
|
||||
tip.style.display = "block";
|
||||
positionTip(e.currentTarget);
|
||||
};
|
||||
img.src = url;
|
||||
}
|
||||
|
||||
function hide() { tip.style.display = "none"; }
|
||||
|
||||
document.querySelectorAll("li.credit").forEach(item => {
|
||||
item.addEventListener("mouseenter", show);
|
||||
item.addEventListener("mouseleave", hide);
|
||||
item.addEventListener("focusin", show);
|
||||
item.addEventListener("focusout", hide);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user