Difference between revisions of "MediaWiki:Common.js"

From Marathon Documentation
Jump to: navigation, search
Line 17: Line 17:
 
var t = $(this); t.toggleClass('expanded-image');
 
var t = $(this); t.toggleClass('expanded-image');
 
if (t.hasClass('expanded-image')) { t.height(this.naturalHeight).width(this.naturalWidth); }
 
if (t.hasClass('expanded-image')) { t.height(this.naturalHeight).width(this.naturalWidth); }
else { t.height(t.attr('data-expand-height')).width(t.attr('data-expand-height')); }
+
else { t.height(t.attr('data-expand-height')).width(t.attr('data-expand-width')); }
 
return false;
 
return false;
 
}).each(set_expand_sizes);
 
}).each(set_expand_sizes);

Revision as of 13:19, 16 June 2015

/* Any JavaScript here will be loaded for all users on every page load. */

function set_expand_sizes() {
  var t, th = $(this), r, fw, fh, mw, mh, mul, ew, eh;
  t = th[0];
  r = (fw = parseInt(t.getAttribute('data-file-width'))) / (fh = parseInt(t.getAttribute('data-file-height')));
  mw = parseInt(th.css('maxWidth')); mh = parseInt(th.css('maxHeight'));
  mul = Math.min(mw/fw, mh/fh);
  t.setAttribute('data-expand-width', (ew = Math.round(mul * fw)));
  t.setAttribute('data-expand-height', (eh = Math.round(mul * fh)));
  t.removeAttribute('width');t.removeAttribute('height');
  t.style.width = ew + 'px';t.style.height = eh + 'px';
  t.style.maxHeight='none';t.style.maxWidth = 'none';
}
function open_in_mmv(href) { var t = $('a.image[href="' + (href || this.href) + '"]').not(":has(img.expand-image)"); return t && t.length ? (t[0].click() || false) && false : true; }
$('img.expand-image').removeClass('expand-on-hover').click(function () {
  var t = $(this); t.toggleClass('expanded-image');
  if (t.hasClass('expanded-image')) { t.height(this.naturalHeight).width(this.naturalWidth); }
  else { t.height(t.attr('data-expand-height')).width(t.attr('data-expand-width')); }
  return false;
}).each(set_expand_sizes);