MediaWiki:Common.js: Difference between revisions
MediaWiki interface page
More actions
Content deleted Content added
imported>76561198045853337 No edit summary |
imported>76561198045853337 rm code that works incorrectly |
||
Line 46: | Line 46: | ||
}; |
}; |
||
}); |
}); |
||
var pages = Array.from(infobox.getElementsByClassName('upgrade_page')); |
|||
var maxWidth = Math.max.apply(null, pages.map(function(page) { return page.offsetWidth })); |
|||
var maxHeight = Math.max.apply(null, pages.map(function(page) { return page.offsetHeight })); |
|||
pages.forEach(function(page) { |
|||
var $page = $(page); |
|||
$page.css({ |
|||
'min-width': maxWidth, |
|||
'min-height':maxHeight |
|||
}); |
|||
}); |
|||
}); |
}); |
||
} |
} |
Revision as of 23:27, 6 August 2021
/* Any JavaScript here will be loaded for all users on every page load. */
/*
const countDownDate = 'January 21 2021 07:00:00 GMT+0000';
function getTimeRemaining(endtime) {
const total = Date.parse(endtime) - Date.parse(new Date());
const seconds = Math.floor((total / 1000) % 60);
const minutes = Math.floor((total / 1000 / 60) % 60);
const hours = Math.floor((total / (1000 * 60 * 60)) % 24);
const days = Math.floor(total / (1000 * 60 * 60 * 24));
return {
total: total,
days: days,
hours: hours,
minutes: minutes,
seconds: seconds
};
}
function tick(id, endtime) {
const clock = document.getElementById(id);
if(clock != null)
{
const t = getTimeRemaining(endtime);
clock.innerHTML = t.days + "d " + t.hours + "h " + t.minutes + "m " + t.seconds + "s ";
if (t.total <= 0) { clearInterval(timeinterval); }
}
}
function initializeClock(id, endtime) {
const timeinterval = setInterval(function() { tick(id, endtime) }, 1000);
tick(id, endtime);
}
initializeClock('launch_timer', countDownDate);
*/
function setupPagination() {
document.querySelectorAll('.mw-parser-output .upgrade_panel').forEach(function(infobox) {
Array.from(infobox.getElementsByClassName('upgrade_page_button')).forEach(function(button) {
button.parentElement.onclick = function(e) {
e.preventDefault();
var level = button.dataset.level;
Array.from(infobox.getElementsByClassName('upgrade_page')).forEach(function(page) { page.classList.toggle('hidden', page.dataset.page != level) });
Array.from(infobox.getElementsByClassName('upgrade_page_button')).forEach(function(btn) { btn.classList.toggle('active', btn === button) });
infobox.getElementsByClassName('upgrade_put_level')[0].textContent = button.getElementsByClassName('upgrade_get_level')[0].textContent;
};
});
});
}
setupPagination();