MediaWiki:Common.js

From Deadlink 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});
			}
		}
	});
});

$(function () {
  $(".druid-title-tab").off("click")
    .on('click', function () {
      var $parent = $(this).closest(".druid-container");
      $parent.find(".druid-toggleable").removeClass("focused");
      var i = $(this).attr("data-druid");
      $parent.find(".druid-toggleable[data-druid=" + i + "]").addClass("focused");
  });
    
  $(".druid-section-tab").off("click")
    .on('click', function () {
      var $parent = $(this).closest(".druid-section-container");
      $parent.find(".druid-toggleable").removeClass("focused");
      var i = $(this).attr("data-druid");
      $parent.find(".druid-toggleable[data-druid=" + i + "]").addClass("focused");
  });

  $(".druid-collapsible").off("click")
    .on('click', function () {
      var kind = $(this).attr("data-druid-section");
      $(this).toggleClass("druid-collapsible-collapsed");
      $(this)
        .closest(".druid-container")
        .find("[data-druid-section-row=" + kind + "]")
        .toggleClass("druid-collapsed");
  });
});

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