2206
редагувань
Admin (обговорення | внесок) (JS: перенести toolbar всередину hero на сторінках країн) |
Admin (обговорення | внесок) (Cities portlet: skin-aware (Minerva drawer + Vector portlet), розрізняє існуючі/неіснуючі міста) |
||
| Рядок 2: | Рядок 2: | ||
$(function () { | $(function () { | ||
var pageName = mw.config.get("wgPageName") || ""; | var pageName = mw.config.get("wgPageName") || ""; | ||
if (pageName !== "🇷🇴_Румунія") return; | if (pageName !== "🇷🇴_Румунія") return; | ||
var cities = [ | var cities = [ | ||
{ title: "Бухарест", page: "Румунія/Бухарест" }, | { title: "Бухарест", page: "Румунія/Бухарест", exists: true }, | ||
{ title: "Клуж-Напока", page: "Румунія/Клуж-Напока" }, | { title: "Клуж-Напока", page: "Румунія/Клуж-Напока", exists: false }, | ||
{ title: "Тімішоара", page: "Румунія/Тімішоара" }, | { title: "Тімішоара", page: "Румунія/Тімішоара", exists: false }, | ||
{ title: "Брашов", page: "Румунія/Брашов" }, | { title: "Брашов", page: "Румунія/Брашов", exists: false }, | ||
{ title: "Ясси", page: "Румунія/Ясси" }, | { title: "Ясси", page: "Румунія/Ясси", exists: false }, | ||
{ title: "Сібіу", page: "Румунія/Сібіу" } | { title: "Сібіу", page: "Румунія/Сібіу", exists: false } | ||
]; | ]; | ||
var skin = mw.config.get("skin"); | |||
if (skin === "minerva") { | |||
buildMinervaCities(cities); | |||
} else { | |||
buildDesktopCitiesPortlet(cities); | |||
} | |||
}); | |||
function buildDesktopCitiesPortlet(cities) { | |||
var portlet = null; | var portlet = null; | ||
if (document.getElementById("p-tb")) { | if (document.getElementById("p-tb")) { | ||
portlet = mw.util.addPortlet("p-cities", "Міста", "#p-tb"); | portlet = mw.util.addPortlet("p-cities", "Міста", "#p-tb"); | ||
} | } | ||
if (!portlet) { | if (!portlet) { | ||
| Рядок 26: | Рядок 31: | ||
if (nav && nav.parentNode) { | if (nav && nav.parentNode) { | ||
nav.parentNode.insertBefore(portlet, nav.nextSibling); | nav.parentNode.insertBefore(portlet, nav.nextSibling); | ||
} else { | } else { | ||
return; | return; | ||
} | } | ||
} | } | ||
cities.forEach(function (city) { | |||
mw.util.addPortletLink("p-cities", mw.util.getUrl(city.page), city.title); | |||
}); | |||
} | |||
function buildMinervaCities(cities) { | |||
var drawer = document.getElementById("mw-mf-page-left"); | |||
if (!drawer) return; | |||
// Прибрати дефолтний portlet якщо він був створений (раптом) | |||
var stale = document.getElementById("p-cities"); | |||
if (stale && stale.parentNode) stale.parentNode.removeChild(stale); | |||
var section = document.createElement("div"); | |||
section.className = "cities-drawer-section"; | |||
var heading = document.createElement("h3"); | |||
heading.className = "cities-drawer-section__heading"; | |||
heading.textContent = "Міста"; | |||
section.appendChild(heading); | |||
var ul = document.createElement("ul"); | |||
ul.className = "toggle-list__list cities-drawer-section__list"; | |||
cities.forEach(function (city) { | cities.forEach(function (city) { | ||
var | var li = document.createElement("li"); | ||
li.className = "toggle-list-item cities-drawer-item"; | |||
if (!city.exists) li.classList.add("cities-drawer-item--missing"); | |||
var a = document.createElement("a"); | |||
a.className = "toggle-list-item__anchor"; | |||
a.href = city.exists | |||
? mw.util.getUrl(city.page) | |||
: mw.util.getUrl(city.page, { action: "edit", redlink: 1 }); | |||
var icon = document.createElement("span"); | |||
icon.className = "minerva-icon cities-drawer-item__icon"; | |||
a.appendChild(icon); | |||
var label = document.createElement("span"); | |||
label.className = "toggle-list-item__label"; | |||
label.textContent = city.title; | |||
a.appendChild(label); | |||
li.appendChild(a); | |||
ul.appendChild(li); | |||
}); | }); | ||
} | |||
section.appendChild(ul); | |||
drawer.appendChild(section); | |||
} | |||
}); | }); | ||