MediaWiki:Template:MainPageInfopush.js: Difference between revisions
From VRChat Wiki
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
(function () { | (function () { | ||
mw.loader.using(["oojs-ui-core", "oojs-ui-windows"]).done(() => { | mw.loader.using(["oojs-ui-core", "oojs-ui-windows"]).done(() => { | ||
for (const infopush of document.querySelectorAll(".tpl-infopush")) { | for (const infopush of document.querySelectorAll(".tpl-infopush")) { | ||
try { | try { | ||
Line 68: | Line 13: | ||
if (!articleId) return; | if (!articleId) return; | ||
item.addEventListener("click", () => showArticle(item)); | item.addEventListener("click", () => console.log("showArticle(item)")); | ||
} | } | ||
Revision as of 00:49, 19 August 2024
$(
(function () {
mw.loader.using(["oojs-ui-core", "oojs-ui-windows"]).done(() => {
for (const infopush of document.querySelectorAll(".tpl-infopush")) {
try {
const content = infopush.querySelector(".tpl-infopush-content");
const items = content.querySelectorAll(".tpl-infopush-item");
const total = items.length;
for (const item of items) {
const { articleId } = item.dataset;
if (!articleId) return;
item.addEventListener("click", () => console.log("showArticle(item)"));
}
const navigation = infopush.querySelector(".tpl-infopush-navigation");
let currentOffset = 0;
function showSlide(index) {
currentOffset = (index + total) % total;
content.style.transform = `translateX(-${currentOffset * 100}%)`;
}
const autoAdvanceEvery = 5000;
let autoAdvanceInterval;
function resetAutoAdvance() {
if (autoAdvanceInterval) clearInterval(autoAdvanceInterval);
autoAdvanceInterval = setInterval(function () {
showSlide(currentOffset + 1);
}, autoAdvanceEvery);
}
navigation
.querySelector(".tpl-infopush-navigation-previous")
.addEventListener("click", () => {
showSlide(currentOffset - 1);
resetAutoAdvance();
});
navigation
.querySelector(".tpl-infopush-navigation-next")
.addEventListener("click", () => {
showSlide(currentOffset + 1);
resetAutoAdvance();
});
resetAutoAdvance();
showSlide(0);
} catch (reason) {
console.warn(
"Template:MainPageInfopush",
"Couldn't initialize infopush.",
reason
);
}
}
});
})()
);