User:GhostInTheMachine/FoldSections.js

The importance of User:GhostInTheMachine/FoldSections.js has been the subject of debate and reflection for years. User:GhostInTheMachine/FoldSections.js has had a significant impact on multiple aspects of society and daily life. Since its emergence, User:GhostInTheMachine/FoldSections.js has aroused the interest and curiosity of experts in different fields, as well as the general population. In this article, we will explore the background of User:GhostInTheMachine/FoldSections.js, its evolution over time, and its relevance today. Likewise, we will analyze the possible future implications of User:GhostInTheMachine/FoldSections.js and its influence in different areas.
// Adds an arrow to sections to make them collapsible
// Cloned from ]

mw.hook('wikipage.content').add(function(content) {
	if (mw.config.get('skin') === 'minerva') return;

	mw.loader.load();
	mw.util.addCSS('{display:none!important}');

	// repair the contributions list after phab T298638
	mw.util.addCSS('h4.mw-index-pager-list-header { width: inherit; height: inherit; padding-top: 7px; position: relative !important; background-color: cornsilk; }');

	mainpart = $('.mw-parser-output, .mw-pager-body', content);
	mainpart.find(':header').each(function() {
		var level = +this.nodeName,
			heading = $(this),
			icon = $('<i class="mw-ui-icon-before mw-ui-icon-small mw-ui-icon mw-ui-icon-expand" style="margin-bottom: 4px;"></i>');

		icon.click(function() {
			var levelMatch = 'h1';
			for (var i = 2; i <= level; i++) levelMatch += ',h' + i + ':has(*)';

			icon.toggleClass('mw-ui-icon-next');
			icon.toggleClass('mw-ui-icon-expand');
			heading.nextUntil(levelMatch).toggleClass('hide-sect-h' + level);
		});

		if (window.collapseSections) icon.click();
		heading.prepend(icon);
	});
});