MediaWiki:Common.js: відмінності між версіями

Матеріал з Країнопедії
(revert: остаточно прибираю JS body-class flip)
Мітка: Ручний відкіт
(JS: перенести toolbar всередину hero на сторінках країн)
Рядок 38: Рядок 38:
     });
     });
   });
   });
});
// Move .vector-page-toolbar into hero block (only on country pages with hero)
$(function () {
  var pageName = mw.config.get("wgPageName") || "";
  if (pageName !== "🇷🇴_Румунія") return;
  var hero = document.querySelector(".vector-page-titlebar");
  var toolbar = document.querySelector(".vector-page-toolbar");
  if (hero && toolbar && toolbar.parentNode !== hero) {
    hero.appendChild(toolbar);
  }
});
});

Версія за 01:21, 4 травня 2026

mw.loader.using(["mediawiki.util"], function () {
  $(function () {
    var pageName = mw.config.get("wgPageName") || "";
    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 {
        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");
    });
  });
});

// Move .vector-page-toolbar into hero block (only on country pages with hero)
$(function () {
  var pageName = mw.config.get("wgPageName") || "";
  if (pageName !== "🇷🇴_Румунія") return;
  var hero = document.querySelector(".vector-page-titlebar");
  var toolbar = document.querySelector(".vector-page-toolbar");
  if (hero && toolbar && toolbar.parentNode !== hero) {
    hero.appendChild(toolbar);
  }
});