MediaWiki:Gadget-GlobalScript.js: Difference between revisions

From Pikipedia, the Pikmin wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Tag: Reverted
Line 1: Line 1:
/* Any JavaScript here will be loaded for all skins on both desktop and mobile */
/* Any JavaScript here will be loaded for all skins on both desktop and mobile */
/* Syntax highlighter */
syntaxHighlighterSiteConfig = {
timeout: 100,
voidTags: ['br', 'hr', 'BR', 'HR']
}


/* Add autocollapse support to mw-collapsible */
/* Add autocollapse support to mw-collapsible */

Revision as of 11:03, February 27, 2023

/* Any JavaScript here will be loaded for all skins on both desktop and mobile */

/* Syntax highlighter */
syntaxHighlighterSiteConfig = {
	timeout: 100,
	voidTags: ['br', 'hr', 'BR', 'HR']
}

/* 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;
		var boxes = $(gallery).find('.gallerybox');
		var onlyVideos = videos.length == boxes.length ? true : false;
		videos.each(function(ii, video) {
			if (onlyVideos)
				$(video).css('height', 'auto');
			$(video).parent().css({'max-width': 'calc(100% - 30px)', 'margin': '15px auto'});
		});
		var timeOut = onlyVideos ? 1000 : 0;
		setTimeout(function() {
			var height = 0;
			$(gallery).find('.gallerybox .thumb').each(function(ii, thumb) {
				if ($(thumb).innerHeight() > height)
					height = $(thumb).innerHeight();
			});
			videos.each(function(ii, video) {
				maxHeight = height - 30;
				$(video).parent().parent().css({'height': height, 'display': 'flex'});
				$(video).parent().css({'width': '100%', 'min-width': '125px', 'margin': 'auto'});
				$(video).css({'height': 'auto', 'max-height': maxHeight});
			});
		}, timeOut);
	});
});

/* 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');
			}
		);
});