MediaWiki:Common.js
A Bahá’í concordance
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.
/* FILTER BY AUTHOR VIEW */
var bahaullah = $('.author-bahaullah');
var bab = $('.author-bab');
var abdulbaha = $('.author-abdulbaha');
function setInfoDisplay (val) {
// Set radio
$('input[name="authorDisplay"][value="' + val + '"]').prop('checked', true);
switch (val) {
case 'none':
bahaullah.show();
bab.show();
abdulbaha.show();
break;
case 'bahaullah':
bahaullah.show();
bab.hide();
abdulbaha.hide();
break;
case 'bab':
bahaullah.hide();
bab.show();
abdulbaha.hide();
break;
case 'abdulbaha':
bahaullah.hide();
bab.hide();
abdulbaha.show();
break;
case 'allAuthors':
bahaullah.show();
bab.show();
abdulbaha.show();
break;
}
}
if (bahaullah.length) {
$(
// '<fieldset>' +
// '<legend>Publication info</legend>' +
'<div style="margin-left: 10px; margin-bottom: -2px; margin-top: 5px;">Display quotes: ' +
'<label><input name="authorDisplay" type="radio" value="allAuthors"> All</label> ' +
'<label><input name="authorDisplay" type="radio" value="bahaullah"> Bahá’u’lláh</label> ' +
'<label><input name="authorDisplay" type="radio" value="bab"> The Báb</label> ' +
'<label><input name="authorDisplay" type="radio" value="abdulbaha"> ‘Abdu’l-Bahá</label>' +
'</div>'
// '</fieldset>'
).click(function (e) {
if (e.target.nodeName.toLowerCase() !== 'input') {
return;
}
var val = e.target.value;
localStorage.setItem('author', val);
setInfoDisplay(val);
}).appendTo($('.author-info').last());
setInfoDisplay(localStorage.getItem('author') || 'year');
}
/* AUTO COLLAPSE TOC */
window.addEventListener('DOMContentLoaded', function() { try {
if (document.getElementById('toc').getElementsByTagName('ul')[0].style.display != 'none') { toggleToc(); }
} catch (exception) {} }, false);
/* Hide category container when no categoies can exist (special pages) ****************************/
var catlinksElement = document.querySelector('.catlinks-allhidden');
var navElement = document.querySelector('nav.p-navbar.not-collapsible.small.mb-2');
var sidebartransElement = document.querySelector('.sidebar-item.sidebar-menu-translations.col');
var langElement = document.querySelector('.interlanguage-link');
if (catlinksElement && navElement) {
navElement.parentNode.removeChild(navElement);
}
if (langElement) {
sidebartransElement.style.display = 'block';
}
/* ADD A URL IN THE FOOTER TO TRAFFIC STATISTICS PAGES */
$(function () {
var allowedNamespaces = [0, 14];
var ns = mw.config.get('wgNamespaceNumber');
if (!allowedNamespaces.includes(ns) || mw.config.get('wgAction') !== 'view') return;
var pageTitle = mw.config.get('wgPageName');
var decodedTitle = pageTitle.replace(/_/g, ' ');
var encodedTitle = encodeURIComponent(decodedTitle).replace(/%20/g, '+');
var statsURL = 'https://digitalbahairesources.org/pageview-analysis?website_id=12&titles=%5B%22' +
encodedTitle + '%22%5D&from_year=2024&from_month=7&to_year=2025&to_month=7';
var $link = $('<a>')
.attr('href', statsURL)
.attr('target', '_blank')
.text('📊 View Traffic Statistics')
.css({ marginLeft: '1em' });
var $container = $('#footer-info > div').first();
if ($container.length) {
$container.append($link);
}
});