2206
редагувань
Admin (обговорення | внесок) (Common.js v5: diagnostic + manual fallback) |
Admin (обговорення | внесок) (cities sidebar v6: insert portlet into DOM before addPortletLink) |
||
| Рядок 1: | Рядок 1: | ||
mw.loader.using(["mediawiki.util"], function () { | |||
mw.loader.using([ | |||
$(function () { | $(function () { | ||
var pageName = mw.config.get( | var pageName = mw.config.get("wgPageName") || ""; | ||
console.log( | console.log("[nomadica] common.js v6, wgPageName =", pageName); | ||
if (pageName !== "🇷🇴_Румунія") return; | |||
var cities = [ | |||
{ title: "Бухарест", page: "Румунія/Бухарест" }, | |||
{ title: "Клуж-Напока", page: "Румунія/Клуж-Напока" }, | |||
{ title: "Тімішоара", page: "Румунія/Тімішоара" }, | |||
{ title: "Брашов", page: "Румунія/Брашов" }, | |||
{ title: "Ясси", page: "Румунія/Ясси" }, | |||
{ title: "Сібіу", page: "Румунія/Сібіу" } | |||
]; | |||
// Спробувати вставити перед #p-tb (TOOLBOX) — стандартний хвостовий портлет. | |||
// Якщо нема — після #p-navigation. | |||
var portlet = null; | |||
if (document.getElementById("p-tb")) { | |||
portlet = mw.util.addPortlet("p-cities", "Міста", "#p-tb"); | |||
console.log("[nomadica] inserted before #p-tb"); | |||
} | |||
if (!portlet) { | |||
portlet = mw.util.addPortlet("p-cities", "Міста"); | |||
var nav = document.getElementById("p-navigation"); | |||
if (nav && nav.parentNode) { | |||
nav.parentNode.insertBefore(portlet, nav.nextSibling); | |||
console.log("[nomadica] manually inserted after #p-navigation"); | |||
} else { | } else { | ||
console. | console.log("[nomadica] FAILED to find anchor for portlet"); | ||
return; | |||
} | } | ||
} | } | ||
cities.forEach(function (city) { | |||
var link = mw.util.addPortletLink("p-cities", mw.util.getUrl(city.page), city.title); | |||
console.log("[nomadica] addPortletLink", city.title, "→", link ? "OK" : "FAIL"); | |||
}); | |||
}); | }); | ||
}); | }); | ||