Mercurial > hg > batmud > maputils
changeset 2728:4e2f9e5b0579
Change mapGetWindowSize() to mapGetElementSize(elem) and adjust users accordingly.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 07 Mar 2024 11:07:24 +0200 |
parents | 6683547af623 |
children | c57773becd12 |
files | src/citymap.js src/tooltip.js src/worldmap.js |
diffstat | 3 files changed, 34 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/src/citymap.js Thu Mar 07 11:05:40 2024 +0200 +++ b/src/citymap.js Thu Mar 07 11:07:24 2024 +0200 @@ -31,31 +31,26 @@ } -function mapGetWindowSize() +function mapGetElementSize(elem) { - var winW = 0, winH = 0; - if (typeof(window.innerWidth) == 'number') + var elemW, elemH; + if (elem.clientWidth || elem.clientHeight) { - // Non-MSIE - winW = window.innerWidth; - winH = window.innerHeight; + elemW = elem.clientWidth; + elemH = elem.clientHeight; } else - if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) + if (typeof(elem.innerWidth) == 'number') { - // MSIE 6+ in 'standards compliant mode' - winW = document.documentElement.clientWidth; - winH = document.documentElement.clientHeight; + elemW = elem.innerWidth; + elemH = elem.innerHeight; } else - if (document.body && (document.body.clientWidth || document.body.clientHeight)) { - // MSIE 4 compatible - winW = document.body.clientWidth; - winH = document.body.clientHeight; + elemW = elemH = 0; } - return { w: winW, h: winH }; + return { w: elemW, h: elemH }; } @@ -80,7 +75,7 @@ var y = document.all ? (window.event.y + document.body.scrollTop) : ev.pageY; if (mapTipItem != null) { - const dim = mapGetWindowSize(); + const dim = mapGetElementSize(window); var boxW = mapTipItem.clientWidth + 25, boxH = mapTipItem.clientHeight + 25; if (x + boxW + 15 >= dim.w) @@ -166,7 +161,7 @@ function mapSetWindowPosToID(eid) { - const dim = mapGetWindowSize(); + const dim = mapGetElementSize(mapElem); var nelem = document.getElementById('maploc'+eid); if (nelem) {
--- a/src/tooltip.js Thu Mar 07 11:05:40 2024 +0200 +++ b/src/tooltip.js Thu Mar 07 11:07:24 2024 +0200 @@ -8,31 +8,26 @@ var mapTipXC = 0, mapTipYC = 0; -function mapGetWindowSize() +function mapGetElementSize(elem) { - var winW = 0, winH = 0; - if (typeof(window.innerWidth) == 'number') + var elemW, elemH; + if (typeof(elem.innerWidth) == 'number') { - // Non-MSIE - winW = window.innerWidth; - winH = window.innerHeight; + elemW = elem.innerWidth; + elemH = elem.innerHeight; } else - if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) + if (elem.clientWidth || elem.clientHeight) { - // MSIE 6+ in 'standards compliant mode' - winW = document.documentElement.clientWidth; - winH = document.documentElement.clientHeight; + elemW = elem.clientWidth; + elemH = elem.clientHeight; } else - if (document.body && (document.body.clientWidth || document.body.clientHeight)) { - // MSIE 4 compatible - winW = document.body.clientWidth; - winH = document.body.clientHeight; + elemW = elemH = 0; } - return { w: winW, h: winH }; + return { w: elemW, h: elemH }; } @@ -43,7 +38,7 @@ var y = document.all ? (window.event.y + document.body.scrollTop) : ev.pageY; if (mapTipItem != null) { - const dim = mapGetWindowSize(); + const dim = mapGetElementSize(window); var boxW = mapTipItem.clientWidth + 25, boxH = mapTipItem.clientHeight + 25; if (x + boxW + 15 >= dim.w)
--- a/src/worldmap.js Thu Mar 07 11:05:40 2024 +0200 +++ b/src/worldmap.js Thu Mar 07 11:07:24 2024 +0200 @@ -37,37 +37,32 @@ } -function mapGetWindowSize() +function mapGetElementSize(elem) { - var winW = 0, winH = 0; - if (typeof(window.innerWidth) == 'number') + var elemW, elemH; + if (elem.clientWidth || elem.clientHeight) { - // Non-MSIE - winW = window.innerWidth; - winH = window.innerHeight; + elemW = elem.clientWidth; + elemH = elem.clientHeight; } else - if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) + if (typeof(elem.innerWidth) == 'number') { - // MSIE 6+ in 'standards compliant mode' - winW = document.documentElement.clientWidth; - winH = document.documentElement.clientHeight; + elemW = elem.innerWidth; + elemH = elem.innerHeight; } else - if (document.body && (document.body.clientWidth || document.body.clientHeight)) { - // MSIE 4 compatible - winW = document.body.clientWidth; - winH = document.body.clientHeight; + elemW = elemH = 0; } - return { w: winW, h: winH }; + return { w: elemW, h: elemH }; } function mapSetWindowPos(px, py) { - const dim = mapGetWindowSize(); + const dim = mapGetElementSize(mapElem); mapDragPos.x = px - (dim.w / 2); mapDragPos.y = py - (dim.h / 2);