MediaWiki:Vector.js: Difference between revisions
Jump to navigation
Jump to search
| Line 19: | Line 19: | ||
mw.loader.using(['mediawiki.util', 'jquery'], function() { | mw.loader.using(['mediawiki.util', 'jquery'], function() { | ||
$(function() { | $(function() { | ||
$('.cargo-show-all-btn | |||
// 1. THE SHOW ALL / HIDE TOGGLE | |||
$(document).on('click', '.cargo-show-all-btn', function() { | |||
var $this = $(this); | var $this = $(this); | ||
var $grid = $this.siblings('.cargo-hidden-grid'); | var $grid = $this.siblings('.cargo-hidden-grid'); | ||
$grid.toggleClass('grid-visible'); | $grid.toggleClass('grid-visible'); | ||
if ($grid.hasClass('grid-visible')) { | if ($grid.hasClass('grid-visible')) { | ||
$this.text($this.text().replace('Show All', 'Hide')).addClass('btn-active'); | $this.text($this.text().replace('Show All', 'Hide')).addClass('btn-active'); | ||
| Line 61: | Line 33: | ||
} | } | ||
}); | }); | ||
// 2. THE SAME-TAB | |||
// This forces every Cargo link to stay in the current window | |||
$(document).on('click', '.cargoMoreResults a, .cargoPreviousResults a', function(e) { | |||
this.target = "_self"; | |||
}); | |||
// 3. AUTO-OPEN ON RELOAD | |||
// If the URL has an 'offset' (meaning user is on page 2, 3, etc), open the grid | |||
if (window.location.search.indexOf('offset=') > -1) { | |||
$('.cargo-hidden-grid').addClass('grid-visible'); | |||
$('.cargo-show-all-btn').each(function() { | |||
$(this).text($(this).text().replace('Show All', 'Hide')).addClass('btn-active'); | |||
}); | |||
} | |||
}); | }); | ||
}); | }); | ||
Revision as of 19:51, 31 January 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() {
// 1. THE SHOW ALL / HIDE TOGGLE
$(document).on('click', '.cargo-show-all-btn', function() {
var $this = $(this);
var $grid = $this.siblings('.cargo-hidden-grid');
$grid.toggleClass('grid-visible');
if ($grid.hasClass('grid-visible')) {
$this.text($this.text().replace('Show All', 'Hide')).addClass('btn-active');
} else {
$this.text($this.text().replace('Hide', 'Show All')).removeClass('btn-active');
}
});
// 2. THE SAME-TAB
// This forces every Cargo link to stay in the current window
$(document).on('click', '.cargoMoreResults a, .cargoPreviousResults a', function(e) {
this.target = "_self";
});
// 3. AUTO-OPEN ON RELOAD
// If the URL has an 'offset' (meaning user is on page 2, 3, etc), open the grid
if (window.location.search.indexOf('offset=') > -1) {
$('.cargo-hidden-grid').addClass('grid-visible');
$('.cargo-show-all-btn').each(function() {
$(this).text($(this).text().replace('Show All', 'Hide')).addClass('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';
});