# HG changeset patch # User Matti Hamalainen # Date 1521650353 -7200 # Node ID cdccda315a0f32fa1cfde345eba5f40095055ea5 # Parent 34c9eca1c7264f1432947a2e1a8ff972ff645166 Change mgalGetWindowSize() to mgalGetElementOrWindowSize(elemname) that either returns size for given element by its id name, or the window size. diff -r 34c9eca1c726 -r cdccda315a0f mgallery.js --- a/mgallery.js Wed Mar 21 18:07:42 2018 +0200 +++ b/mgallery.js Wed Mar 21 18:39:13 2018 +0200 @@ -82,40 +82,43 @@ } -function mgalGetWindowSize() +function mgalGetElementOrWindowSize(nelem) { - var winW = 0, winH = 0; + if (nelem) + { + var elem = document.getElementById(nelem); + if (elem) + return [elem.clientWidth, elem.clientHeight]; + } + if (typeof(window.innerWidth) == 'number') { // Non-MSIE - winW = window.innerWidth; - winH = window.innerHeight; + return [window.innerWidth, window.innerHeight]; } - else + if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { // MSIE 6+ in 'standards compliant mode' - winW = document.documentElement.clientWidth; - winH = document.documentElement.clientHeight; + return [document.documentElement.clientWidth, document.documentElement.clientHeight]; } - else + if (document.body && (document.body.clientWidth || document.body.clientHeight)) { // MSIE 4 compatible - winW = document.body.clientWidth; - winH = document.body.clientHeight; + return [document.body.clientWidth, document.body.clientHeight]; } - return [winW, winH]; + return null; } function mgalAdjustImageDo() { var eimg = document.getElementById("imageImage"); - var win = mgalGetWindowSize(); - var madj = 0.92; - if (eimg) + var win = mgalGetElementOrWindowSize(); + var madj = 0.90; + if (eimg && win != null) { if (eimg.width > eimg.height) {