MediaWiki:Timeless.js: Difference between revisions
From The HOA
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
mw.loader.using(['mediawiki.api']).then(function () { | mw.loader.using(['mediawiki.api']).then(function () { | ||
var category = "Resources"; // The name of the category | var category = "Resources"; // The name of the category | ||
var sidebar = $("#mw- | var sidebar = $("#mw-sidebar"); // Targeting the left sidebar in Timeless | ||
// Create a new menu using Timeless' built-in styling classes | // Create a new menu using Timeless' built-in styling classes | ||
Line 22: | Line 22: | ||
$menu.append($heading).append($list); | $menu.append($heading).append($list); | ||
sidebar.append($menu); // Append the menu to the Timeless sidebar | sidebar.append($menu); // Append the menu to the Timeless left sidebar | ||
} | } | ||
}); | }); | ||
}); | }); |
Revision as of 06:56, 7 March 2025
mw.loader.using(['mediawiki.api']).then(function () { var category = "Resources"; // The name of the category var sidebar = $("#mw-sidebar"); // Targeting the left sidebar in Timeless // Create a new menu using Timeless' built-in styling classes var $menu = $("<div>").addClass("portal").attr("id", "custom-category-menu"); // Using Timeless' portal class var $heading = $("<h3>").addClass("portal-heading").text("Pages in " + category); var $list = $("<ul>").addClass("portal-body"); // Fetch category members from the API new mw.Api().get({ action: "query", list: "categorymembers", cmtitle: "Category:" + category, cmlimit: 10, format: "json" }).done(function (data) { if (data.query && data.query.categorymembers.length > 0) { data.query.categorymembers.forEach(function (page) { $list.append($("<li>").append($("<a>").attr("href", mw.util.getUrl(page.title)).text(page.title))); }); $menu.append($heading).append($list); sidebar.append($menu); // Append the menu to the Timeless left sidebar } }); });