Mercurial > hg > mgallery
changeset 208:cdccda315a0f
Change mgalGetWindowSize() to mgalGetElementOrWindowSize(elemname) that
either returns size for given element by its id name, or the window size.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 21 Mar 2018 18:39:13 +0200 |
parents | 34c9eca1c726 |
children | 671b7cfebf87 |
files | mgallery.js |
diffstat | 1 files changed, 17 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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) {