MediaWiki:Common.js

From Funtasia Wiki
Jump to navigation Jump to search

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.
mw.loader.getScript( 'https://commons.wiki.gg/index.php?title=MediaWiki:Common-base.js&action=raw&ctype=text/javascript' ).then(function(){
////////////////////////////////////////////////////////////////////////////////


/**
 * image size fix for <gallery>
 */
$(function(){
	$(".mw-gallery-traditional .thumb").each(function(){
		var $this = $(this);
		/* $this.css('display', 'flex'); // do this in common.css: .mw-gallery-traditional .thumb{ display: flex; } */
		$this.css('height', $this.height()+'px').find('>div').css('margin', 'auto');
		var $img = $this.find('img').first();
		if(!$img.length){
			return;
		}
		var $width = $img.attr('width') - 0; //cast to number.
		var $filewidth = $img.attr('data-file-width') - 0;
		if($filewidth < $width){
			var $fileheight = $img.attr('data-file-height');
			if( $filewidth * 2 > $width){
				$img.attr({'width': $filewidth, 'height': $fileheight});
			}else{
				$img.attr({'width': $filewidth*2, 'height': $fileheight*2});
			}
		}
	});
});


////////////////////////////////////////////////////////////////////////////////
/*end of mw.loader.getScript().then callback*/ });