Difference between revisions of "MediaWiki:Common.js"
From Marathon Documentation
Line 2: | Line 2: | ||
function set_expand_sizes() { |
function set_expand_sizes() { |
||
− | var t = $(this) |
+ | var t, th = $(this), r, fw, fh, mw, mh, mul, ew, eh; |
+ | t = th[0]; |
||
− | t.width(t.width()).height(t.height()); |
||
− | t. |
+ | 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); |
||
− | }, 1); |
||
+ | 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'; |
||
⚫ | |||
} |
} |
||
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; } |
||
Line 14: | Line 19: | ||
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-height')); } |
||
return false; |
return false; |
||
− | } |
+ | }).each(set_expand_sizes); |
Revision as of 12:31, 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-height')); } return false; }).each(set_expand_sizes);