Difference between revisions of "MediaWiki:Common.js"

From Marathon Documentation
Jump to: navigation, search
Line 2: Line 2:
   
 
function set_expand_sizes() {
 
function set_expand_sizes() {
var t, th = $(this), r, fw, fh, mw, mh, mul, ew, eh;
+
var t, th = $(this), r, fw, fh, mw, mh, mul, ew, eh, ph;
 
t = th[0];
 
t = th[0];
 
r = (fw = parseInt(t.getAttribute('data-file-width'))) / (fh = parseInt(t.getAttribute('data-file-height')));
 
r = (fw = parseInt(t.getAttribute('data-file-width'))) / (fh = parseInt(t.getAttribute('data-file-height')));
Line 12: Line 12:
 
t.style.width = ew + 'px';t.style.height = eh + 'px';
 
t.style.width = ew + 'px';t.style.height = eh + 'px';
 
t.style.maxHeight='none';t.style.maxWidth = 'none';
 
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').addClass('expand-image-cont-min').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; }
 
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 () {
 
$('img.expand-image').removeClass('expand-on-hover').click(function () {
var t = $(this); t.toggleClass('expanded-image');
+
var t = $(this), p = $(this.parentNode); 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); p.height(this.naturalHeight); }
else { t.height(t.attr('data-expand-height')).width(t.attr('data-expand-width')); }
+
else { t.height(t.attr('data-expand-height')).width(t.attr('data-expand-width')); p.height(p.attr('data-expand-cont-height')); }
 
return false;
 
return false;
 
}).each(set_expand_sizes);
 
}).each(set_expand_sizes);

Revision as of 11:52, 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').addClass('expand-image-cont-min').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);