MediaWiki:Gadget-MakeMobileCollapsible.js: Difference between revisions

From Seeds of the Word, the encyclopedia of the influence of the Gospel on culture
Content deleted Content added
Created page with "// MakeMobileCollapsible, enables collapsible templates/infoboxes on the mobile site. // See https://en.wikipedia.org/wiki/Wikipedia:MakeMobileCollapsible for more information. // This is a spinoff from Factotum. (https://en.wikipedia.org/wiki/User:Alexis_Jazz/Factotum) // MakeMobileCollapsible is public domain, irrevocably released as WTFPL Version 2[www.wtfpl.net/about/] by its author, Alexis Jazz. →‎globals $:false,mw:false: //<nowiki> let MMCollap = {}; MMCollap.do..."
 
No edit summary
 
Line 1: Line 1:
// MakeMobileCollapsible, enables collapsible templates/infoboxes on the mobile site.
// MakeMobileCollapsible, enables collapsible templates/infoboxes on the mobile site.
// See https://en.wikipedia.org/wiki/Wikipedia:MakeMobileCollapsible for more information.
// See https://en.wikipedia.org/wiki/Wikipedia:MakeMobileCollapsible for more information.
// This is a spinoff from Factotum. (https://en.wikipedia.org/wiki/User:Alexis_Jazz/Factotum)
// MakeMobileCollapsible, enables collapsible templates/infoboxes on the mobile site.
// This is a spinoff from Factotum. (https://en.wikipedia.org/wiki/User:Alexis_Jazz/Factotum)
// This is a spinoff from Factotum. (https://en.wikipedia.org/wiki/User:Alexis_Jazz/Factotum)
// MakeMobileCollapsible is public domain, irrevocably released as WTFPL Version 2[www.wtfpl.net/about/] by its author, Alexis Jazz.
// MakeMobileCollapsible is public domain, irrevocably released as WTFPL Version 2[www.wtfpl.net/about/] by its author, Alexis Jazz.

/*globals $:false,mw:false*/
/*globals $:false,mw:false*/
//<nowiki>
let MMCollap = {};
let MMCollap = {};
MMCollap.do = function() {
MMCollap.do = function() {

// Commented out for now, to be revisited later as some people raised potential concerns with providing mobile-only features:
// Allow content to be collapsible only on the mobile site which could be useful as mobile displays are smaller, so the threshold to wish to make something collapsible could be greater
// to achieve this, change "mw-" to "MMC-" in all classes used. Do NOT use custom toggles as they won't be hidden on the desktop site.
// let classes = ['collapsible','collapsed','collapsible-toggle','collapsible-content','collapsible-toggle-placeholder','collapsible-toggle-expanded'];
// if ( $('.MMC-collapsible,.MMC-collapsed')[0] ) {
// for(let int=0; int<classes.length; int++){
// $('.MMC-'+classes[int]).addClass('mw-'+classes[int]);
// }
// }
MMCollap.els = $('.mw-collapsible');
MMCollap.els = $('.mw-collapsible');
if ( MMCollap.els[0] ) {
if ( MMCollap.els[0] ) {
if ( MMCollap.els.length > 1 && ( ['enwiki'].indexOf(mw.config.get('wgDBname')) != -1) ) {
if ( MMCollap.els.length > 1 ) {
$('.autocollapse').addClass('mw-collapsed'); //the "autocollapse" class is handled by code in Common.js on enwiki, but Common.js isn't loaded on mobile.
// the "autocollapse" class is handled by code in Common.js on enwiki, but Common.js isn't loaded on mobile.
$('.autocollapse').addClass('mw-collapsed');
}
}
mw.loader.using(['jquery.makeCollapsible']).then( function () {
mw.loader.using(['jquery.makeCollapsible']).then( function () {
Line 28: Line 21:
}
}
};
};
mw.hook( 'wikipage.content' ).add( MMCollap.do ); //make collapsible content collapsible whenever the page is rendered, on load but also e.g. after saving an edit
//make collapsible content collapsible whenever the page is rendered, on load but also e.g. after saving an edit
mw.hook( 'wikipage.content' ).add( MMCollap.do );
//</nowiki>

Latest revision as of 10:55, August 25, 2024

// MakeMobileCollapsible, enables collapsible templates/infoboxes on the mobile site.
// See https://en.wikipedia.org/wiki/Wikipedia:MakeMobileCollapsible for more information.
// This is a spinoff from Factotum. (https://en.wikipedia.org/wiki/User:Alexis_Jazz/Factotum)
// MakeMobileCollapsible, enables collapsible templates/infoboxes on the mobile site.
// This is a spinoff from Factotum. (https://en.wikipedia.org/wiki/User:Alexis_Jazz/Factotum)
// MakeMobileCollapsible is public domain, irrevocably released as WTFPL Version 2[www.wtfpl.net/about/] by its author, Alexis Jazz.

/*globals $:false,mw:false*/
let MMCollap = {};
MMCollap.do = function() {
	MMCollap.els = $('.mw-collapsible');
	if ( MMCollap.els[0] ) {
		if ( MMCollap.els.length > 1 ) {
			// the "autocollapse" class is handled by code in Common.js on enwiki, but Common.js isn't loaded on mobile.
			$('.autocollapse').addClass('mw-collapsed');
		}
		mw.loader.using(['jquery.makeCollapsible']).then( function () {
			mw.loader.addStyleTag('.mw-parser-output .mw-collapsible-toggle{font-weight:normal;min-width:6em}');
			$(MMCollap.els).makeCollapsible(); //T111565 FTFY
		});
	}
};
//make collapsible content collapsible whenever the page is rendered, on load but also e.g. after saving an edit
mw.hook( 'wikipage.content' ).add( MMCollap.do );