|
|
| (16 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| /* Any JavaScript here will be loaded for all users on every page load. */ | | /* Force viewport meta for mobile responsiveness */ |
| /* Google Translate Widget */
| | (function() { |
| $(document).ready(function() { | | var existing = document.querySelector('meta[name="viewport"]'); |
| // Add translate section to sidebar
| | if (existing) { |
| var translateHtml = '<div id="google-translate-sidebar" style="padding: 8px 0;">' +
| | existing.setAttribute('content', 'width=device-width, initial-scale=1'); |
| '<div id="google_translate_element"></div>' +
| | } else { |
| '</div>';
| | var meta = document.createElement('meta'); |
|
| | meta.name = 'viewport'; |
| $('.mw-portlet-lang, #p-lang').last().after(translateHtml);
| | meta.content = 'width=device-width, initial-scale=1'; |
|
| | document.head.appendChild(meta); |
| // Load Google Translate script
| | } |
| var script = document.createElement('script');
| | })(); |
| script.src = '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit';
| | |
| document.body.appendChild(script);
| | $(document).ready(function () { |
| | |
| | /* ===== PIN MAIN MENU ON DESKTOP ===== */ |
| | if (window.innerWidth >= 1000) { |
| | 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 (unpinnedContainer && mainMenu) { |
| | if (pinnedContainer && !pinnedContainer.contains(mainMenu)) { |
| | pinnedContainer.appendChild(mainMenu); |
| | } |
| | } |
| | |
| | // Click pin button if available |
| | var pinButton = document.querySelector('.vector-pinnable-header-pin-button'); |
| | if (pinButton) pinButton.click(); |
| | } |
| | |
| | /* ===== MOVE TRANSLATE LINK INTO SIDEBAR ===== */ |
| | // Find translate link from Tools menu |
| | var $translateLi = $('#p-tb li').filter(function () { |
| | return $(this).find('a').attr('href') && |
| | $(this).find('a').attr('href').indexOf('Translate') !== -1; |
| }); | | }); |
|
| |
|
| function googleTranslateElementInit() {
| | var translateHref = '#'; |
| new google.translate.TranslateElement({
| | if ($translateLi.length) { |
| pageLanguage: 'en',
| | translateHref = $translateLi.find('a').attr('href'); |
| layout: google.translate.TranslateElement.InlineLayout.SIMPLE,
| | $translateLi.hide(); // Hide from Tools menu |
| autoDisplay: false
| | } |
| }, 'google_translate_element');
| | |
| | // Also check ULS trigger (MediaWiki translate extension button) |
| | var $ulsBtn = $('#p-lang-btn, .uls-trigger, #pt-uls'); |
| | if ($ulsBtn.length) { |
| | translateHref = $ulsBtn.attr('href') || translateHref; |
| } | | } |
| /* Force main menu to be pinned on desktop */
| | |
| $(document).ready(function() {
| | |
| // Force pin the main menu
| | /* ===== CLEAN UP TOOLS MENU — REMOVE LESS USEFUL ITEMS ===== */ |
| var pinnedContainer = document.getElementById('vector-main-menu-pinned-container');
| | // Optional: hide items you don't want in Tools |
| var unpinnedContainer = document.getElementById('vector-main-menu-unpinned-container');
| | var hideFromTools = ['t-permalink', 't-info']; // add IDs to hide |
| var mainMenu = document.getElementById('vector-main-menu');
| | hideFromTools.forEach(function(id) { |
|
| | $('#' + id).hide(); |
| 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');
| |
| }
| |