MediaWiki:Common.js: Difference between revisions

Amend for ECMASCript 5 compatibility
No edit summary
(Amend for ECMASCript 5 compatibility)
 
(8 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 759: Line 767:


function isUserLoggedIn() {
function isUserLoggedIn() {
  if (mw.config.get('wgUserName') === null) {
if (mw.config.get('wgUserName') === null) {
    return false;
return false;
  } else {
} else {
    return true;
return true;
  }
}
}
 
function addToPageTools() {
if (isUserLoggedIn()) {
var canEdit = mw.config.get('wgIsProbablyEditable');
var isArticle = mw.config.get('wgIsArticle');
var isCurRevision = mw.config.get('wgRevisionId') >= mw.config.get('wgCurRevisionId');
if (canEdit && isArticle && isCurRevision) {
$.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
);
});
}
}
}
}


Line 773: Line 802:
     $('.ios-app-download').addClass('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 778: Line 816:
// Table sticky headers
// Table sticky headers
initStickyHeaders();
initStickyHeaders();
// Collapsible elements (for Extension:MobileFrontend)
initCollapsibleElements();
// Wiki app native navigation
// Wiki app native navigation
initWikiAppSidebar();
initWikiAppSidebar();
// Show iOS App download link
// Show iOS App download link
setTimeout(showIOSAppDownloadLink,1000);
showIOSAppDownloadLink();
// Show Android App download link
showAndroidAppDownloadLink();
// Add links to Page Tools navigation
addToPageTools();
});
});