MediaWiki:Vector.js: Difference between revisions
Jump to navigation
Jump to search
| Line 99: | Line 99: | ||
/* CLICKABLE HOME BUTTON AT THE TOP IN MOBILE VIEW */ | /* CLICKABLE HOME BUTTON AT THE TOP IN MOBILE VIEW */ | ||
/* 1. THE MAIN BLOCK (For regular pages) */ | |||
$(document).ready(function() { | $(document).ready(function() { | ||
$('#left-navigation').on('click', function(e) { | $('#left-navigation').on('click', function(e) { | ||
| Line 107: | Line 108: | ||
}); | }); | ||
/* 2. | /* 2. THE SPECIAL BLOCK (For Login, CreateAccount, Preferences) */ | ||
(function() { | (function() { | ||
var specialPage = mw.config.get('wgCanonicalSpecialPageName'); | var specialPage = mw.config.get('wgCanonicalSpecialPageName'); | ||
| Line 113: | Line 114: | ||
if (targetPages.indexOf(specialPage) !== -1) { | if (targetPages.indexOf(specialPage) !== -1) { | ||
window.addEventListener('click', function(e) { | |||
// On Special pages, Vector often uses p-namespaces or p-personal instead | |||
var navIds = ['left-navigation', 'p-namespaces', 'p-personal']; | |||
var nav = null; | |||
for (var i = 0; i < navIds.length; i++) { | |||
nav = document.getElementById(navIds[i]); | |||
if (nav) break; | |||
} | |||
if (nav) { | if (nav) { | ||
var rect = nav.getBoundingClientRect(); | var rect = nav.getBoundingClientRect(); | ||
// Check if | // Check if click is in the top-left 80px zone | ||
if (e.clientX >= rect.left && e.clientX <= rect.left + 80 && | if (e.clientX >= rect.left && e.clientX <= rect.left + 80 && | ||
e.clientY >= rect.top && e.clientY <= rect.bottom) { | e.clientY >= rect.top && e.clientY <= rect.bottom) { | ||
window.location.href = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php'; | window.location.href = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php'; | ||
} | } | ||
} | } | ||
}, true); | }, true); | ||
} | } | ||
})(); | })(); | ||
Revision as of 03:19, 2 February 2026
/* All JavaScript here will be loaded for users of the Vector skin */
/* Move subcategories to the top on Category:Forklifts and Category:Video_Games */
if ( mw.config.get( 'wgPageName' ) === 'Category:Forklifts' || mw.config.get( 'wgPageName' ) === 'Category:Video_Games' ) {
$( function() {
var subcats = $( '#mw-subcategories' );
var content = $( '.mw-parser-output' );
if ( subcats.length && content.length ) {
subcats.insertBefore( content );
$( 'body' ).addClass( 'move-subcategories-up-active' );
$( '#bodyContent' ).css( { 'display': 'flex', 'flex-direction': 'column' } );
content.css( 'order', '2' );
subcats.css( 'order', '1' );
}
} );
}
/* SHOW ALL BUTTON */
mw.loader.using(['mediawiki.util', 'jquery'], function() {
$(function() {
$('.cargo-show-all-btn').on('click', function() {
var $this = $(this);
var $grid = $this.siblings('.cargo-hidden-grid');
// Toggle visibility
$grid.toggleClass('grid-visible');
// Dynamic text switching
var isVisible = $grid.hasClass('grid-visible');
var originalText = $this.text();
if (isVisible) {
$this.data('original-text', originalText);
$this.text(originalText.replace('Show All', 'Hide')).addClass('btn-active');
} else {
$this.text($this.data('original-text')).removeClass('btn-active');
}
});
});
});
/* NEWS SLIDESHOW */
mw.loader.using('mediawiki.util').then(function () {
mw.hook('wikipage.content').add(function () {
document.querySelectorAll('.news-slideshow-container').forEach(function (container) {
var slides = container.querySelectorAll('.news-slideshow-slide');
if (slides.length <= 1) return;
var current = 0;
var intervalId = null;
var delay = 8000; // 8 seconds
function showSlide(index) {
slides.forEach(function (slide, i) {
slide.classList.toggle('active', i === index);
});
}
function startSlideshow() {
if (intervalId !== null) return;
intervalId = setInterval(function () {
current = (current + 1) % slides.length;
showSlide(current);
}, delay);
}
function stopSlideshow() {
if (intervalId !== null) {
clearInterval(intervalId);
intervalId = null;
}
}
// Initial state
showSlide(current);
startSlideshow();
// Pause on hover
container.addEventListener('mouseenter', stopSlideshow);
container.addEventListener('mouseleave', startSlideshow);
});
});
});
/* FORM TABLE */
document.addEventListener('click', function (e) {
const header = e.target.closest('.pf-collapsible');
if (!header) return;
const targetId = header.dataset.target;
const section = document.getElementById(targetId);
if (!section) return;
const isOpen = section.style.display === 'block';
section.style.display = isOpen ? 'none' : 'block';
});
/* CLICKABLE HOME BUTTON AT THE TOP IN MOBILE VIEW */
/* 1. THE MAIN BLOCK (For regular pages) */
$(document).ready(function() {
$('#left-navigation').on('click', function(e) {
if (e.target === this || $(e.target).is('::before')) {
window.location.href = mw.config.get('wgArticlePath').replace('$1', '');
}
});
});
/* 2. THE SPECIAL BLOCK (For Login, CreateAccount, Preferences) */
(function() {
var specialPage = mw.config.get('wgCanonicalSpecialPageName');
var targetPages = ['Userlogin', 'CreateAccount', 'Preferences'];
if (targetPages.indexOf(specialPage) !== -1) {
window.addEventListener('click', function(e) {
// On Special pages, Vector often uses p-namespaces or p-personal instead
var navIds = ['left-navigation', 'p-namespaces', 'p-personal'];
var nav = null;
for (var i = 0; i < navIds.length; i++) {
nav = document.getElementById(navIds[i]);
if (nav) break;
}
if (nav) {
var rect = nav.getBoundingClientRect();
// Check if click is in the top-left 80px zone
if (e.clientX >= rect.left && e.clientX <= rect.left + 80 &&
e.clientY >= rect.top && e.clientY <= rect.bottom) {
window.location.href = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php';
}
}
}, true);
}
})();