MediaWiki:Common.js
Jump to navigation
Jump to search
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)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
(function ($, mw) {
'use strict';
function setLogoHref() {
var logoLink = document.querySelector('#p-logo a');
if (logoLink) {
logoLink.setAttribute('href', 'https://timero.com.br/');
}
}
function ensureFontAwesome() {
if (!document.querySelector('link[data-timero-fa]')) {
var fa = document.createElement('link');
fa.rel = 'stylesheet';
fa.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css';
fa.setAttribute('data-timero-fa', '1');
document.head.appendChild(fa);
}
}
function resetRoutePill(pill) {
if (!pill) return;
pill.style.transform = '';
pill.style.fontWeight = '800';
pill.style.boxShadow = 'none';
pill.style.filter = 'none';
}
function activateRoutePill(pill) {
if (!pill) return;
pill.style.transform = 'translateY(-1px)';
pill.style.fontWeight = '900';
pill.style.boxShadow = '0 0 0 1px rgba(255,255,255,0.05) inset, 0 0 22px rgba(255,255,255,0.05)';
pill.style.filter = 'brightness(1.08)';
}
function closeAllRoutes(section) {
if (!section) return;
var details = section.querySelectorAll('.route-detail');
for (var i = 0; i < details.length; i++) {
details[i].style.display = 'none';
}
var pills = section.querySelectorAll('.route-pill[data-route]');
for (var j = 0; j < pills.length; j++) {
resetRoutePill(pills[j]);
}
section.setAttribute('data-open-route', '');
}
window.expandRoute = function (routeId) {
var section = document.getElementById('routes-section');
if (!section) return;
var target = document.getElementById(routeId);
if (!target) return;
var currentOpen = section.getAttribute('data-open-route');
if (currentOpen === routeId) {
closeAllRoutes(section);
return;
}
closeAllRoutes(section);
target.style.display = 'block';
target.style.animation = 'route-in 0.3s ease both';
section.setAttribute('data-open-route', routeId);
var activePill = document.getElementById('pill-' + routeId);
activateRoutePill(activePill);
if (typeof target.scrollIntoView === 'function') {
setTimeout(function () {
target.scrollIntoView({
behavior: 'smooth',
block: 'nearest'
});
}, 80);
}
};
function bindRouteViewer(context) {
var scope = context && context.querySelector ? context : document;
var section = scope.querySelector('#routes-section') || document.getElementById('routes-section');
if (!section) return;
var pills = section.querySelectorAll('.route-pill[data-route]');
for (var i = 0; i < pills.length; i++) {
var pill = pills[i];
if (pill.dataset.timeroBound === '1') continue;
pill.dataset.timeroBound = '1';
pill.setAttribute('role', 'button');
pill.setAttribute('tabindex', '0');
pill.addEventListener('click', function () {
expandRoute(this.getAttribute('data-route'));
});
pill.addEventListener('keydown', function (e) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
expandRoute(this.getAttribute('data-route'));
}
});
}
var closeButtons = section.querySelectorAll('.route-close[data-route]');
for (var j = 0; j < closeButtons.length; j++) {
var closeBtn = closeButtons[j];
if (closeBtn.dataset.timeroBound === '1') continue;
closeBtn.dataset.timeroBound = '1';
closeBtn.setAttribute('role', 'button');
closeBtn.setAttribute('tabindex', '0');
closeBtn.addEventListener('click', function () {
expandRoute(this.getAttribute('data-route'));
});
closeBtn.addEventListener('keydown', function (e) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
expandRoute(this.getAttribute('data-route'));
}
});
}
}
function init(context) {
setLogoHref();
ensureFontAwesome();
bindRouteViewer(context || document);
}
$(function () {
init(document);
});
if (mw && mw.hook) {
mw.hook('wikipage.content').add(function ($content) {
init(($content && $content[0]) || document);
});
}
})(jQuery, mediaWiki);