Welcome to Super-Shiritori!
Please remember:
- No vandalism – Do not add nonsense, false info, spam, or blank pages.
- Respect others – Be polite and assume good faith.
- Use reliable information – Make sure edits are accurate and IMPORTANT.
- Stay constructive – Help us grow the wiki with content, especially with the Word compendium.
⚠️ Repeated vandalism or rule-breaking may result in warnings or blocks. If you see vandalism, please revert it and notify an admin.
Add infobox gallery tab-switching and mobile infobox reordering (below lead paragraph, Wikipedia-style) |
Fix: toggle is-inactive class instead of .hidden property to match the sanitizer-safe markup |
||
| Line 18: | Line 18: | ||
} ); | } ); | ||
slides.forEach( function ( slide ) { | slides.forEach( function ( slide ) { | ||
slide. | // A plain "hidden" attribute gets stripped by MediaWiki's | ||
// sanitizer, so a CSS class carries visibility instead. | |||
slide.classList.toggle( 'is-inactive', slide.getAttribute( 'data-ia-slide' ) !== index ); | |||
} ); | } ); | ||
} ); | } ); | ||
Revision as of 05:21, 5 September 2026
/* Behavior for Template:Infobox_application. Lives in Common.js (not
* Cosmos.js) so it keeps working regardless of which skin a reader/editor
* has selected. */
( function () {
// Clickable tab bar for multi-image infoboxes (image1/caption1,
// image2/caption2, ...). Without this, only the first <div data-ia-slide>
// is visible -- everything still renders, it just can't be switched.
function initInfoboxGalleries() {
document.querySelectorAll( '.infobox-application__gallery' ).forEach( function ( gallery ) {
var tabs = gallery.querySelectorAll( '.infobox-application__gallery-tab' );
var slides = gallery.querySelectorAll( '.infobox-application__gallery-slide' );
tabs.forEach( function ( tab ) {
tab.addEventListener( 'click', function () {
var index = tab.getAttribute( 'data-ia-tab' );
tabs.forEach( function ( t ) {
t.classList.toggle( 'is-active', t === tab );
} );
slides.forEach( function ( slide ) {
// A plain "hidden" attribute gets stripped by MediaWiki's
// sanitizer, so a CSS class carries visibility instead.
slide.classList.toggle( 'is-inactive', slide.getAttribute( 'data-ia-slide' ) !== index );
} );
} );
} );
} );
}
// On narrow screens the infobox drops its desktop float (see
// Template:Infobox_application/styles.css) and becomes a full-width
// block -- but it's still first in the wikitext/DOM, so without this it
// would render ABOVE the lead paragraph instead of below it, the way
// Wikipedia's mobile view places infoboxes. This moves it to just after
// the first non-empty paragraph of the article (mirrors MobileFrontend's
// own behavior, which Cosmos doesn't have).
function relocateInfoboxOnMobile() {
if ( window.innerWidth > 550 ) {
return;
}
document.querySelectorAll( '.mw-parser-output > .infobox-application' ).forEach( function ( box ) {
var sib = box.nextElementSibling;
while ( sib && ( sib.tagName !== 'P' || !sib.textContent.trim() ) ) {
sib = sib.nextElementSibling;
}
if ( sib ) {
sib.insertAdjacentElement( 'afterend', box );
}
} );
}
function init() {
initInfoboxGalleries();
relocateInfoboxOnMobile();
}
if ( document.readyState === 'loading' ) {
document.addEventListener( 'DOMContentLoaded', init );
} else {
init();
}
}() );
