« MediaWiki:Gadget-Accueil.glow.js » : différence entre les versions
Page de l’interface de MediaWiki
Autres actions
Sync homepage from repository (commit b06f0a0) |
Sync homepage from repository (commit 0e34c54) |
||
| Ligne 1 : | Ligne 1 : | ||
( function ( mw ) { | ( function ( mw ) { | ||
"use strict"; | |||
const accueil = mw.libs && mw.libs.wikithionvilleAccueil; | |||
if (!accueil) return; | |||
if ( !accueil ) | accueil.initCardGlow = ( listener, container ) => { | ||
if (!listener || !container || accueil.reduceMotion) | |||
return; | |||
let frame = null; | |||
const pointerEventName = | const pointerEventName = | ||
window.PointerEvent | window.PointerEvent | ||
? | ? "pointermove" | ||
: | : "mousemove"; | ||
const cards = listener.querySelectorAll(".home-card"); | |||
if (!cards.length) return; | |||
if ( !cards.length ) | |||
function moveGlows(event) { | function moveGlows(event) { | ||
if (!event) return; | if (!event) return; | ||
frame = null; | |||
const bounds = container.getBoundingClientRect(); | |||
const posX = accueil.clamp(event.clientX, bounds.left, bounds.right); | |||
const posY = accueil.clamp(event.clientY, bounds.top, bounds.bottom); | |||
for (const card of cards) { | |||
const glow = card.querySelector(".home-card__glow"); | |||
const origin = card.querySelector(".home-card__glow-origin") || glow; | |||
if ( !glow || !origin ) continue; | |||
const rect = origin.getBoundingClientRect(); | |||
const translateX = posX - rect.left - rect.width / 2; | |||
const translateY = posY - rect.top - rect.height / 2; | |||
const transform = `translate3d(${translateX}px, ${translateY}px, 0)`; | |||
glow.style.transform = transform; | |||
} | } | ||
} | } | ||
function rAF(event) { | function rAF(event) { | ||
if ( frame | if (frame) return; | ||
frame = window.requestAnimationFrame(() => { | |||
moveGlows(event) | |||
}); | |||
} | } | ||
listener.addEventListener(pointerEventName, rAF, { passive: true } ); | listener.addEventListener(pointerEventName, rAF, { passive: true }); | ||
listener.addEventListener("wheel", rAF, { passive: true }); | listener.addEventListener("wheel", rAF, { passive: true }); | ||
}; | }; | ||
}( mediaWiki ) ); | }( mediaWiki ) ); | ||
Dernière version du 12 juin 2026 à 13:00
( function ( mw ) {
"use strict";
const accueil = mw.libs && mw.libs.wikithionvilleAccueil;
if (!accueil) return;
accueil.initCardGlow = ( listener, container ) => {
if (!listener || !container || accueil.reduceMotion)
return;
let frame = null;
const pointerEventName =
window.PointerEvent
? "pointermove"
: "mousemove";
const cards = listener.querySelectorAll(".home-card");
if (!cards.length) return;
function moveGlows(event) {
if (!event) return;
frame = null;
const bounds = container.getBoundingClientRect();
const posX = accueil.clamp(event.clientX, bounds.left, bounds.right);
const posY = accueil.clamp(event.clientY, bounds.top, bounds.bottom);
for (const card of cards) {
const glow = card.querySelector(".home-card__glow");
const origin = card.querySelector(".home-card__glow-origin") || glow;
if ( !glow || !origin ) continue;
const rect = origin.getBoundingClientRect();
const translateX = posX - rect.left - rect.width / 2;
const translateY = posY - rect.top - rect.height / 2;
const transform = `translate3d(${translateX}px, ${translateY}px, 0)`;
glow.style.transform = transform;
}
}
function rAF(event) {
if (frame) return;
frame = window.requestAnimationFrame(() => {
moveGlows(event)
});
}
listener.addEventListener(pointerEventName, rAF, { passive: true });
listener.addEventListener("wheel", rAF, { passive: true });
};
}( mediaWiki ) );