Jump to content

MediaWiki:Common.js

From Farmpedia – Agricultural Encyclopedia for Farmers
Revision as of 09:20, 13 April 2026 by Mamta (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Force viewport meta for mobile responsiveness */
(function() {
    var existing = document.querySelector('meta[name="viewport"]');
    if (existing) {
        existing.setAttribute('content', 'width=device-width, initial-scale=1');
    } else {
        var meta = document.createElement('meta');
        meta.name = 'viewport';
        meta.content = 'width=device-width, initial-scale=1';
        document.head.appendChild(meta);
    }
})();

/* Force main menu to be pinned on desktop */
$(document).ready(function() {
    // Force pin the main menu
    var pinnedContainer = document.getElementById('vector-main-menu-pinned-container');
    var unpinnedContainer = document.getElementById('vector-main-menu-unpinned-container');
    var mainMenu = document.getElementById('vector-main-menu');
    
    if (window.innerWidth >= 1024) {
        if (unpinnedContainer && mainMenu) {
            // Move menu to pinned container if not already there
            if (pinnedContainer && !pinnedContainer.contains(mainMenu)) {
                pinnedContainer.appendChild(mainMenu);
            }
        }
        // Click the pin button if it exists
        var pinButton = document.querySelector('.vector-pinnable-header-pin-button');
        if (pinButton) {
            pinButton.click();
        }
    }
});