MediaWiki:Gadget-GlobalScript.js: Difference between revisions

From the Kingdom Hearts Wiki, the Kingdom Hearts encyclopedia
Jump to navigationJump to search
mNo edit summary
No edit summary
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 */
/* Fix media negative margin bug for wide galleries */
$(function() {
$('.gallerybox audio').each(function(i, obj) {
if ($(this).parent().css('margin-top') < '15px')
$(this).parent().css('margin', '15px auto');
});
});


/* Add autocollapse support to mw-collapsible */
/* Add autocollapse support to mw-collapsible */
Line 19: Line 11:
}
}
mw.hook('wikipage.collapsibleContent').add(mwCollapsibleSetup);
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'});
});
});
});

Revision as of 05:32, 17 February 2023

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