MediaWiki:Template:MainPageInfopush.js: Difference between revisions

From VRChat Wiki
No edit summary
No edit summary
Line 1: Line 1:
$(
$(
(async function () {
(function () {
for (const infopush of document.querySelectorAll(".tpl-infopush")) {
//mw.loader.using(["oojs-ui-core", "oojs-ui-windows"]).done(() => {
try {
// var windowManager = new OO.ui.WindowManager();
const content = infopush.querySelector(".tpl-infopush-content");
// $(document.body).append(windowManager.$element);
//
// function showArticle(element) {
// var { articleTitle, articleContent } = element.dataset;
//
// function ArticleDialog(config) {
// ArticleDialog.super.call(this, config);
// this.config = config || {};
// }
//
// OO.inheritClass(ArticleDialog, OO.ui.ProcessDialog);
//
// ArticleDialog.static.name = "ArticleDialog";
// ArticleDialog.static.title = articleTitle;
// ArticleDialog.static.size = "large";
// ArticleDialog.static.actions = [
// {
// action: "close",
// flags: "safe",
// icon: "close",
// label: "Close"
// }
// ];
//
// ArticleDialog.prototype.initialize = function () {
// ArticleDialog.super.prototype.initialize.apply(this, arguments);
// this.content = new OO.ui.PanelLayout({
// $content: atob(articleContent),
// expanded: false,
// padded: true,
// scrollable: true
// });
//
// this.$body.append(this.content.$element);
// };
//
// ArticleDialog.prototype.getActionProcess = function (action) {
// if (action === "close") {
// return new OO.ui.Process(function () {
// this.close({ action: "close" });
// }, this);
// }
// return ArticleDialog.super.prototype.getActionProcess.call(
// this,
// action
// );
// };
//
// var dialog = new ArticleDialog();
//
// windowManager.addWindows([dialog]);
// windowManager.openWindow(dialog);
// }


const items = content.querySelectorAll(".tpl-infopush-item");
for (const infopush of document.querySelectorAll(".tpl-infopush")) {
const total = items.length;
try {
const content = infopush.querySelector(".tpl-infopush-content");


for (const item of items) {
const items = content.querySelectorAll(".tpl-infopush-item");
const { articleId } = item.dataset;
const total = items.length;
if (!articleId) return;


item.addEventListener("click", () => console.log("showArticle(item)"));
for (const item of items) {
}
const { articleId } = item.dataset;
if (!articleId) return;


const navigation = infopush.querySelector(".tpl-infopush-navigation");
item.addEventListener("click", () => showArticle(item));
}


let currentOffset = 0;
const navigation = infopush.querySelector(".tpl-infopush-navigation");
function showSlide(index) {
currentOffset = (index + total) % total;
content.style.transform = `translateX(-${currentOffset * 100}%)`;
}


const autoAdvanceEvery = 5000;
let currentOffset = 0;
function showSlide(index) {
currentOffset = (index + total) % total;
content.style.transform = `translateX(-${currentOffset * 100}%)`;
}


let autoAdvanceInterval;
const autoAdvanceEvery = 5000;
function resetAutoAdvance() {
if (autoAdvanceInterval) clearInterval(autoAdvanceInterval);
autoAdvanceInterval = setInterval(function () {
showSlide(currentOffset + 1);
}, autoAdvanceEvery);
}


navigation
let autoAdvanceInterval;
.querySelector(".tpl-infopush-navigation-previous")
function resetAutoAdvance() {
.addEventListener("click", () => {
if (autoAdvanceInterval) clearInterval(autoAdvanceInterval);
showSlide(currentOffset - 1);
autoAdvanceInterval = setInterval(function () {
resetAutoAdvance();
showSlide(currentOffset + 1);
});
}, autoAdvanceEvery);
}


navigation
navigation
.querySelector(".tpl-infopush-navigation-next")
.querySelector(".tpl-infopush-navigation-previous")
.addEventListener("click", () => {
.addEventListener("click", () => {
showSlide(currentOffset + 1);
showSlide(currentOffset - 1);
resetAutoAdvance();
resetAutoAdvance();
});
});


resetAutoAdvance();
navigation
showSlide(0);
.querySelector(".tpl-infopush-navigation-next")
} catch (reason) {
.addEventListener("click", () => {
console.warn(
showSlide(currentOffset + 1);
"Template:MainPageInfopush",
resetAutoAdvance();
"Couldn't initialize infopush.",
});
reason
 
);
resetAutoAdvance();
}
showSlide(0);
} catch (reason) {
console.warn(
"Template:MainPageInfopush",
"Couldn't initialize infopush.",
reason
);
}
}
}
// });
})()
})()
);
);

Revision as of 00:51, 19 August 2024

$(
	(function () {
		//mw.loader.using(["oojs-ui-core", "oojs-ui-windows"]).done(() => {
		//	var windowManager = new OO.ui.WindowManager();
		//	$(document.body).append(windowManager.$element);
		//
		//	function showArticle(element) {
		//		var { articleTitle, articleContent } = element.dataset;
		//
		//		function ArticleDialog(config) {
		//			ArticleDialog.super.call(this, config);
		//			this.config = config || {};
		//		}
		//
		//		OO.inheritClass(ArticleDialog, OO.ui.ProcessDialog);
		//
		//		ArticleDialog.static.name = "ArticleDialog";
		//		ArticleDialog.static.title = articleTitle;
		//		ArticleDialog.static.size = "large";
		//		ArticleDialog.static.actions = [
		//			{
		//				action: "close",
		//				flags: "safe",
		//				icon: "close",
		//				label: "Close"
		//			}
		//		];
		//
		//		ArticleDialog.prototype.initialize = function () {
		//			ArticleDialog.super.prototype.initialize.apply(this, arguments);
		//			this.content = new OO.ui.PanelLayout({
		//				$content: atob(articleContent),
		//				expanded: false,
		//				padded: true,
		//				scrollable: true
		//			});
		//
		//			this.$body.append(this.content.$element);
		//		};
		//
		//		ArticleDialog.prototype.getActionProcess = function (action) {
		//			if (action === "close") {
		//				return new OO.ui.Process(function () {
		//					this.close({ action: "close" });
		//				}, this);
		//			}
		//			return ArticleDialog.super.prototype.getActionProcess.call(
		//				this,
		//				action
		//			);
		//		};
		//
		//		var dialog = new ArticleDialog();
		//
		//		windowManager.addWindows([dialog]);
		//		windowManager.openWindow(dialog);
		//	}

		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", () => 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
				);
			}
		}
		//	});
	})()
);