Jump to content

MediaWiki:Common.js: Difference between revisions

From Farmpedia – Agricultural Encyclopedia for Farmers
No edit summary
No edit summary
Line 1: Line 1:
/* Force main menu to be pinned on desktop */
$(document).ready(function() {
$(document).ready(function() {
 
     // Force pin the main menu
     /* Force main menu pinned */
    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 (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');
         var pinButton = document.querySelector('.vector-pinnable-header-pin-button');
         if (pinButton) pinButton.click();
         if (pinButton) {
            pinButton.click();
        }
     }
     }
 
   
     /* Load Google Translate */
     /* Google Translate Widget */
    var translateHtml = '<div class="mw-portlet" id="p-translate">' +
        '<div class="mw-portlet-header">Translate</div>' +
        '<div class="mw-portlet-body">' +
        '<div id="google_translate_element"></div>' +
        '</div></div>';
   
    var sidebar = document.querySelector('.mw-portlet-navigation, #p-navigation');
    if (sidebar) {
        sidebar.insertAdjacentHTML('afterend', translateHtml);
    }
   
    // Load Google Translate
     var script = document.createElement('script');
     var script = document.createElement('script');
     script.src = '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit';
     script.src = '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit';
     document.body.appendChild(script);
     document.body.appendChild(script);
});
});



Revision as of 01:11, 12 April 2026

/* 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();
        }
    }
    
    /* Google Translate Widget */
    var translateHtml = '<div class="mw-portlet" id="p-translate">' +
        '<div class="mw-portlet-header">Translate</div>' +
        '<div class="mw-portlet-body">' +
        '<div id="google_translate_element"></div>' +
        '</div></div>';
    
    var sidebar = document.querySelector('.mw-portlet-navigation, #p-navigation');
    if (sidebar) {
        sidebar.insertAdjacentHTML('afterend', translateHtml);
    }
    
    // Load Google Translate
    var script = document.createElement('script');
    script.src = '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit';
    document.body.appendChild(script);
});

function googleTranslateElementInit() {
    new google.translate.TranslateElement({
        pageLanguage: 'en',
        layout: google.translate.TranslateElement.InlineLayout.SIMPLE,
        autoDisplay: false
    }, 'google_translate_element');
}