MediaWiki:Common.js: Difference between revisions

Add Purge link to page tools
No edit summary
(Add Purge link to page tools)
(11 intermediate revisions by 2 users not shown)
Line 550: Line 550:
if (!isOverflown) {
if (!isOverflown) {
var headElem = document.getElementById('mw-header-container');
var headElem = document.getElementById('mw-header-container');
if (headElem !== undefined) {
if ((headElem !== undefined) && (headElem !== null)) {
var headStyles = getComputedStyle(headElem);
var headStyles = getComputedStyle(headElem);
if ((headStyles !== undefined) && (headStyles.position !== 'static')) {
if ((headStyles !== undefined) && (headStyles.position !== 'static')) {
Line 671: Line 671:
});
});
}
}
}
function initCollapsibleElements() {
/* 2024-02-18 Allow collapsing of elements with class 'mw-collapsible', in line
* with desktop view behaviour. Extension:MobileFrontend disables this, but
* it is still desirable for our use case
*/
mw.loader.using('jquery.makeCollapsible').then(function () { $('.mw-collapsible').makeCollapsible(); });
}
}


Line 764: Line 772:
     return true;
     return true;
   }
   }
}
function addToPageTools() {
if (isUserLoggedIn()) {
$.when(mw.loader.using(['mediawiki.util']), $.ready).then( function() {
mw.util.addPortletLink(
'p-cactions',
mw.util.getUrl() + '?action=purge',
'Purge',
't-purgecache',
'Purge the cache for this page',
null,
null
);
});
}
}
}


function showIOSAppDownloadLink() {
function showIOSAppDownloadLink() {
     var shouldShowDownload = /iPhone|iPad|iPod/i.test(window.navigator.userAgent) && window.navigator.userAgent.indexOf('gonative melvorwiki') === -1;
     var shouldShowDownload = /iPhone|iPad|iPod/i.test(window.navigator.userAgent) && window.navigator.userAgent.indexOf('gonative melvorwiki') === -1;
     var els = document.getElementsByClassName('ios-app-download');
     if (shouldShowDownload) {
     for (var i = 0; i < els.length; i++) {
    $('.ios-app-download').removeClass('d-none');
        if (shouldShowDownload) {
    } else {
            els[i].classList.remove('d-none');
    $('.ios-app-download').addClass('d-none');
        }
     }
}
 
function showAndroidAppDownloadLink() {
    var shouldShowDownload = /Android/i.test(window.navigator.userAgent) && window.navigator.userAgent.indexOf('gonative melvorwiki') === -1;
    if (shouldShowDownload) {
    $('.android-app-download').removeClass('d-none');
    } else {
    $('.android-app-download').addClass('d-none');
     }
     }
}
}
Line 779: Line 811:
// Table sticky headers
// Table sticky headers
initStickyHeaders();
initStickyHeaders();
// Collapsible elements (for Extension:MobileFrontend)
initCollapsibleElements();
// Wiki app native navigation
// Wiki app native navigation
initWikiAppSidebar();
initWikiAppSidebar();
});
document.addEventListener("DOMContentLoaded", function() {
// Show iOS App download link
// Show iOS App download link
showIOSAppDownloadLink();
showIOSAppDownloadLink();
// Show Android App download link
showAndroidAppDownloadLink();
// Add links to Page Tools navigation
addToPageTools();
});
});