Jump to content

User:SD0001/AllCollapseToggle.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/**
 * Simple script to to provide an option in the left sidebar "Tools" menu (p-tb)
 * to uncollapse/collapse all hatted discussions and navboxes on a page.
 * Requested by Atsme, [[Special:Diff/902814062]]
 */
 
 $.when(mw.loader.using('mediawiki.util'), $.ready).then(function() {

	var i = 0;
	$(mw.util.addPortletLink('p-tb', '#', 'Uncollpase all', 'collapse-toggle', 
	'Collapse or uncollapse all hatted discussions and navboxes on this page')).click(function() {
		$('.mw-collapsible-toggle-default').click();
		if (i % 2 == 0) {
			$('.mw-collapsible-toggle-collapsed').click();
			this.childNodes[0].textContent = 'Collapse all';
		} else {
			$('.mw-collapsible-toggle-expanded').click();
			this.childNodes[0].textContent = 'Uncollapse all';
		}
		i++;
	});

});