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
Rayanth (talk | contribs)
No edit summary
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 317: Line 317:
})(jQuery);
})(jQuery);
}catch(e){console.log("Pehuen screwed up! Post on the forums.", e);}
}catch(e){console.log("Pehuen screwed up! Post on the forums.", e);}
mw.loader.using(['mediawiki.util'], function () {
  $(function () {
    console.log("✅ Citizen Search Trigger Loaded");
    const fakeSearchBox = document.getElementById('skin-citizen-search-trigger');
    const realSearchToggle = document.getElementById('citizen-search-details');
    if (!fakeSearchBox) {
      console.log("⚠️ Fake search box not found.");
      return;
    }
    fakeSearchBox.addEventListener('click', function () {
      console.log("🔍 Search trigger clicked");
      if (realSearchToggle) {
        realSearchToggle.open = true;
        setTimeout(() => {
          const input = document.getElementById('searchInput');
          if (input) input.focus();
        }, 100);
      } else {
        console.log("❌ Real search toggle not found, falling back to / key");
        const event = new KeyboardEvent('keydown', {
          key: '/',
          keyCode: 191,
          code: 'Slash',
          which: 191,
          bubbles: true,
          cancelable: true
        });
        document.dispatchEvent(event);
      }
    });
  });
});
mw.loader.using(['jquery', 'mediawiki.api'], function () {
    $(function () {
        $('.main-banner[data-files]').each(function () {
            var $box = $(this);
           
            var list = String($box.attr('data-files'))
                .split(/\s*\|\s*|\s*,\s*/)
                .filter(Boolean);
            if (!list.length) return;
            var pick = list[Math.floor(Math.random() * list.length)];
            // Use MediaWiki API to resolve actual file path
            new mw.Api().get({
                action: 'query',
                titles: 'File:' + pick,
                prop: 'imageinfo',
                iiprop: 'url',
                format: 'json'
            }).done(function (data) {
                var pages = data.query.pages;
                for (var pageId in pages) {
                    if (pages.hasOwnProperty(pageId) && pages[pageId].imageinfo) {
                        var url = pages[pageId].imageinfo[0].url;
                        var $img = $('<img>', {
                            src: url,
                            width: 2450,
                            height: 450,
                            alt: ''
                        });
                        $box.empty().append($img);
                    }
                }
            });
        });
    });
});