Difference between revisions of "MediaWiki:Common.js"

From Marathon Documentation
Jump to: navigation, search
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
/* Any JavaScript here will be loaded for all users on every page load. */
 
/* Any JavaScript here will be loaded for all users on every page load. */
   
  +
function set_expand_sizes() {
function open_in_mmv(href) { var t = $('a.image[href="' + (href || this.href) + '"]'); return t && t.length ? t[0].click() && false : true; }
 
  +
var t, th = $(this), r, fw, fh, mw, mh, mul, ew, eh, ph;
  +
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';
  +
ph = Math.min(eh,Math.floor(mh/2));
  +
t.parentNode.setAttribute('data-expand-cont-height', ph);
  +
$(t.parentNode).addClass('expand-image-cont').height(ph);
  +
}
 
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), p = $(this.parentNode); t.toggleClass('expanded-image');
  +
if (t.hasClass('expanded-image')) { t.height(this.naturalHeight).width(this.naturalWidth); p.height(this.naturalHeight); }
  +
else { t.height(t.attr('data-expand-height')).width(t.attr('data-expand-width')); p.height(p.attr('data-expand-cont-height')); }
  +
return false;
  +
}).each(set_expand_sizes);

Latest revision as of 10:53, 17 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, ph;
  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';
  ph = Math.min(eh,Math.floor(mh/2));
  t.parentNode.setAttribute('data-expand-cont-height', ph);
  $(t.parentNode).addClass('expand-image-cont').height(ph);
}
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), p = $(this.parentNode); t.toggleClass('expanded-image');
  if (t.hasClass('expanded-image')) { t.height(this.naturalHeight).width(this.naturalWidth); p.height(this.naturalHeight); }
  else { t.height(t.attr('data-expand-height')).width(t.attr('data-expand-width')); p.height(p.attr('data-expand-cont-height')); }
  return false;
}).each(set_expand_sizes);