User:Alexis Jazz/MakeMobileCollapsible.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Alexis Jazz/MakeMobileCollapsible. |
// 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>
var MMCollap = {};
MMCollap.do = function(classes,int) {
/* Outcommented 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.
classes = ['collapsible','collapsed','collapsible-toggle','collapsible-content','collapsible-toggle-placeholder','collapsible-toggle-expanded'];
if ( $('.MMC-collapsible,.MMC-collapsed')[0] ) {
for(int=0;int<classes.length;int++){
$('.MMC-'+classes[int]).addClass('mw-'+classes[int]);
}
}*/
MMCollap.els = $('.mw-collapsible');
if ( MMCollap.els[0] ) {
if ( MMCollap.els.length > 1 && ( ['enwiki'].indexOf(mw.config.get('wgDBname')) != -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.
}
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
});
}
};
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
//</nowiki>