Jump to content
Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
>MangoFVTT
No edit summary
>MangoFVTT
No edit summary
 
Line 13: Line 13:


         function onSearchTriggerClick() {
         function onSearchTriggerClick() {
             if (skin === "citizen") {
             if (skin === "citizen" && searchToggle) {
                 // Citizen does not have a visible search bar, you need to expand the search card first
                 // Citizen does not have a visible search bar, you need to expand the search card first
                 // And Citizen will focus the input automatically
                 // And Citizen will focus the input automatically
                 searchToggle?.click();
                 searchToggle.click();
             } else {
             } else {
                 // This should work for all skins that has visible search bar
                 // This should work for all skins that has visible search bar

Latest revision as of 20:16, 4 August 2026

/* Any JavaScript here will be loaded for all users on every page load. */
(function () {
    var pageName = mw.config.get("wgPageName");
    var skin = mw.config.get("skin");
    var isMainPage = mw.config.get("wgIsMainPage");

    function onMainPage() {
        var searchTrigger = document.getElementById(
            "ygdren-homepage-search-trigger"
        );
        var searchInput = document.getElementById("searchInput");
        var searchToggle;

        function onSearchTriggerClick() {
            if (skin === "citizen" && searchToggle) {
                // Citizen does not have a visible search bar, you need to expand the search card first
                // And Citizen will focus the input automatically
                searchToggle.click();
            } else {
                // This should work for all skins that has visible search bar
                searchInput.focus();
            }
        }

        // Attach click event listener to search button on the main page
        if (searchTrigger && searchInput) {
            if (skin === "citizen") {
                searchToggle = document.getElementById("citizen-search-summary");
            }
            searchTrigger.addEventListener("click", onSearchTriggerClick);
        }
    }

    function init() {
        // Wait for page content to be fully loaded
        mw.hook("wikipage.content").add(function () {
            if (isMainPage) {
                onMainPage();
            }
        });
    }

    init();
})();