MediaWiki:Gadget-GlobalScript.js

Revision as of 08:28, February 18, 2023 by Porplemontage (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all skins on both desktop and mobile */

/* Add autocollapse support to mw-collapsible */
function mwCollapsibleSetup($collapsibleContent) {
	var $element, autoCollapseThreshold = 2;
	$.each($collapsibleContent, function(index, element) {
		$element = $(element);
		if ($collapsibleContent.length >= autoCollapseThreshold && $element.hasClass('autocollapse'))
			$element.data('mw-collapsible').collapse();
	});
}
mw.hook('wikipage.collapsibleContent').add(mwCollapsibleSetup);

/* Gallery videos */
$(function() {
	$('.gallery').each(function(i, gallery) {
		var videos = $(gallery).find('.gallerybox video');
		if (!videos.length)
			return;
		videos.each(function(ii, video) {
			$(video).parent().css({'width': '100%', 'max-width': 'calc(100% - 30px)', 'margin': 'auto'});
		});
		var height = 0;
		$(gallery).find('.gallerybox .thumb').each(function(ii, thumb) {
			if ($(thumb).innerHeight() > height)
				height = $(thumb).innerHeight();
		});
		videos.each(function(ii, video) {
			var maxHeight = height - 30;
			$(video).css({'width': '100%', 'max-height': maxHeight});
			$(video).parent().parent().css({'height': height, 'display': 'flex'});
		});
	});
});

/* Pikan */
$(function() {
	if (mw.config.get('wgAction') === 'edit' || mw.config.get('wgAction') === 'submit')
		mw.loader.getScript('/MediaWiki:Pikan-core.js?action=raw&ctype=text/javascript').then(
			function() {
				mw.loader.load('/MediaWiki:Pikan-pikipedia.js?action=raw&ctype=text/javascript');
			}
		);
});