Mercurial > hg > batmud > maputils
comparison src/citymap.js @ 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 |
comparison
equal
deleted
inserted
replaced
2727:6683547af623 | 2728:4e2f9e5b0579 |
---|---|
29 | 29 |
30 return { x: xc, y: yc, mx: 0, my: 0 }; | 30 return { x: xc, y: yc, mx: 0, my: 0 }; |
31 } | 31 } |
32 | 32 |
33 | 33 |
34 function mapGetWindowSize() | 34 function mapGetElementSize(elem) |
35 { | 35 { |
36 var winW = 0, winH = 0; | 36 var elemW, elemH; |
37 if (typeof(window.innerWidth) == 'number') | 37 if (elem.clientWidth || elem.clientHeight) |
38 { | 38 { |
39 // Non-MSIE | 39 elemW = elem.clientWidth; |
40 winW = window.innerWidth; | 40 elemH = elem.clientHeight; |
41 winH = window.innerHeight; | |
42 } | 41 } |
43 else | 42 else |
44 if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) | 43 if (typeof(elem.innerWidth) == 'number') |
45 { | 44 { |
46 // MSIE 6+ in 'standards compliant mode' | 45 elemW = elem.innerWidth; |
47 winW = document.documentElement.clientWidth; | 46 elemH = elem.innerHeight; |
48 winH = document.documentElement.clientHeight; | |
49 } | 47 } |
50 else | 48 else |
51 if (document.body && (document.body.clientWidth || document.body.clientHeight)) | 49 { |
52 { | 50 elemW = elemH = 0; |
53 // MSIE 4 compatible | 51 } |
54 winW = document.body.clientWidth; | 52 |
55 winH = document.body.clientHeight; | 53 return { w: elemW, h: elemH }; |
56 } | |
57 | |
58 return { w: winW, h: winH }; | |
59 } | 54 } |
60 | 55 |
61 | 56 |
62 // Add or remove given CSS class to specified element | 57 // Add or remove given CSS class to specified element |
63 function mapSetStyle(uid, ustyle, uset) | 58 function mapSetStyle(uid, ustyle, uset) |
78 { | 73 { |
79 var x = document.all ? (window.event.x + document.body.scrollLeft) : ev.pageX; | 74 var x = document.all ? (window.event.x + document.body.scrollLeft) : ev.pageX; |
80 var y = document.all ? (window.event.y + document.body.scrollTop) : ev.pageY; | 75 var y = document.all ? (window.event.y + document.body.scrollTop) : ev.pageY; |
81 if (mapTipItem != null) | 76 if (mapTipItem != null) |
82 { | 77 { |
83 const dim = mapGetWindowSize(); | 78 const dim = mapGetElementSize(window); |
84 var boxW = mapTipItem.clientWidth + 25, boxH = mapTipItem.clientHeight + 25; | 79 var boxW = mapTipItem.clientWidth + 25, boxH = mapTipItem.clientHeight + 25; |
85 | 80 |
86 if (x + boxW + 15 >= dim.w) | 81 if (x + boxW + 15 >= dim.w) |
87 x -= boxW; | 82 x -= boxW; |
88 else | 83 else |
164 } | 159 } |
165 | 160 |
166 | 161 |
167 function mapSetWindowPosToID(eid) | 162 function mapSetWindowPosToID(eid) |
168 { | 163 { |
169 const dim = mapGetWindowSize(); | 164 const dim = mapGetElementSize(mapElem); |
170 var nelem = document.getElementById('maploc'+eid); | 165 var nelem = document.getElementById('maploc'+eid); |
171 if (nelem) | 166 if (nelem) |
172 { | 167 { |
173 const pos = mapGetElementCoords(nelem); | 168 const pos = mapGetElementCoords(nelem); |
174 mapDragPos.x = pos.x - (dim.w / 2); | 169 mapDragPos.x = pos.x - (dim.w / 2); |