Mercurial > hg > batmud > maputils
changeset 2392:1885ccfe9ee8
Cleanup.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 06 Nov 2021 19:13:06 +0200 |
parents | c603badcad70 |
children | a5cbe64e04c0 |
files | src/tooltip.js |
diffstat | 1 files changed, 34 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/src/tooltip.js Sat Nov 06 18:32:06 2021 +0200 +++ b/src/tooltip.js Sat Nov 06 19:13:06 2021 +0200 @@ -9,6 +9,34 @@ var myy = 0; +function mapGetWindowSize() +{ + var winW = 0, winH = 0; + if (typeof(window.innerWidth) == 'number') + { + // Non-MSIE + winW = window.innerWidth; + winH = 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; + } + else + if (document.body && (document.body.clientWidth || document.body.clientHeight)) + { + // MSIE 4 compatible + winW = document.body.clientWidth; + winH = document.body.clientHeight; + } + + return { w: winW, h: winH }; +} + + // Add or remove given CSS class to specified element function mapSetStyle(uid, ustyle, uset) { @@ -56,40 +84,21 @@ // Update the tooltip box -function mapUpdateTooltip(e) +function mapUpdateTooltip(ev) { - var x = document.all ? (window.event.x + document.body.scrollLeft) : e.pageX; - var y = document.all ? (window.event.y + document.body.scrollTop) : e.pageY; + var x = document.all ? (window.event.x + document.body.scrollLeft) : ev.pageX; + var y = document.all ? (window.event.y + document.body.scrollTop) : ev.pageY; if (mytt != null) { - var winW = 0, winH = 0; + const dim = mapGetWindowSize(); var boxW = mytt.clientWidth + 25, boxH = mytt.clientHeight + 25; - if (typeof(window.innerWidth) == 'number') - { - // Non-MSIE - winW = window.innerWidth; - winH = 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; - } else - if (document.body && (document.body.clientWidth || document.body.clientHeight)) - { - // MSIE 4 compatible - winW = document.body.clientWidth; - winH = document.body.clientHeight; - } - - if (x + boxW + 15 >= winW) + if (x + boxW + 15 >= dim.w) x -= boxW; else x += 15; - if (y + boxH + 15 >= winH) + if (y + boxH + 15 >= dim.h) y -= boxH; else y += 15;