Mercurial > hg > batmud > maputils
annotate tooltip.js @ 1769:57276229a8c8
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 26 Oct 2017 22:20:25 +0300 |
parents | 31a454a73f8e |
children | 78dcae610ce3 |
rev | line source |
---|---|
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
1 // |
917 | 2 // Tooltip and other utility functions in JavaScript for BatMUD maps |
3 // by Matti 'ccr' Hamalainen (Ggr Pupunen) <ccr@tnsp.org> | |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
4 // |
1 | 5 var myhl = -1; |
6 var mytt = null; | |
750
7b990bddefab
Minor glitch- and bugfixes; Add links to location list also.
Matti Hamalainen <ccr@tnsp.org>
parents:
745
diff
changeset
|
7 var myx = 0; |
7b990bddefab
Minor glitch- and bugfixes; Add links to location list also.
Matti Hamalainen <ccr@tnsp.org>
parents:
745
diff
changeset
|
8 var myy = 0; |
1 | 9 document.onmousemove = utt; |
10 | |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
11 |
1 | 12 // Change background style of given element |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
13 function shc(uid, ucolor) |
913
32532d4de594
Cleanups; Make the "selected" location blink.
Matti Hamalainen <ccr@tnsp.org>
parents:
750
diff
changeset
|
14 { |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
15 document.getElementById(uid).style['background'] = ucolor; |
1 | 16 } |
17 | |
18 | |
19 // Hilite map and list elements of given number | |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
20 function qh(marker) |
913
32532d4de594
Cleanups; Make the "selected" location blink.
Matti Hamalainen <ccr@tnsp.org>
parents:
750
diff
changeset
|
21 { |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
22 if (myhl >= 0) qn(myhl); |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
23 shc('maploc'+marker, 'white'); |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
24 shc('listloc'+marker, 'white'); |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
25 myhl = marker; |
1 | 26 } |
27 | |
28 // Unlite | |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
29 function qn(marker) |
913
32532d4de594
Cleanups; Make the "selected" location blink.
Matti Hamalainen <ccr@tnsp.org>
parents:
750
diff
changeset
|
30 { |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
31 shc('maploc'+ marker, 'black'); |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
32 shc('listloc'+ marker, 'black'); |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
33 myhl = -1; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
34 htt(); |
1 | 35 } |
36 | |
37 | |
38 // Update the tooltip box | |
913
32532d4de594
Cleanups; Make the "selected" location blink.
Matti Hamalainen <ccr@tnsp.org>
parents:
750
diff
changeset
|
39 function utt(e) |
32532d4de594
Cleanups; Make the "selected" location blink.
Matti Hamalainen <ccr@tnsp.org>
parents:
750
diff
changeset
|
40 { |
1769 | 41 var x = document.all ? (window.event.x + document.body.scrollLeft) : e.pageX; |
42 var y = document.all ? (window.event.y + document.body.scrollTop) : e.pageY; | |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
43 if (mytt != null) |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
44 { |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
45 var winW = 0, winH = 0; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
46 var boxW = mytt.clientWidth + 25, boxH = mytt.clientHeight + 25; |
1204 | 47 |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
48 if (typeof(window.innerWidth) == 'number') |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
49 { |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
50 // Non-MSIE |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
51 winW = window.innerWidth; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
52 winH = window.innerHeight; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
53 } else |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
54 if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
55 { |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
56 // MSIE 6+ in 'standards compliant mode' |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
57 winW = document.documentElement.clientWidth; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
58 winH = document.documentElement.clientHeight; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
59 } else |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
60 if (document.body && (document.body.clientWidth || document.body.clientHeight)) |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
61 { |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
62 // MSIE 4 compatible |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
63 winW = document.body.clientWidth; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
64 winH = document.body.clientHeight; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
65 } |
1 | 66 |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
67 if (x + boxW + 15 >= winW) |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
68 x -= boxW; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
69 else |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
70 x += 15; |
1 | 71 |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
72 if (y + boxH + 15 >= winH) |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
73 y -= boxH; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
74 else |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
75 y += 15; |
750
7b990bddefab
Minor glitch- and bugfixes; Add links to location list also.
Matti Hamalainen <ccr@tnsp.org>
parents:
745
diff
changeset
|
76 |
1769 | 77 myx = x; |
78 myy = y; | |
750
7b990bddefab
Minor glitch- and bugfixes; Add links to location list also.
Matti Hamalainen <ccr@tnsp.org>
parents:
745
diff
changeset
|
79 |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
80 mytt.style.left = x + "px"; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
81 mytt.style.top = y + "px"; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
82 } |
1 | 83 } |
84 | |
85 // Show tooltip | |
913
32532d4de594
Cleanups; Make the "selected" location blink.
Matti Hamalainen <ccr@tnsp.org>
parents:
750
diff
changeset
|
86 function stt(id) |
32532d4de594
Cleanups; Make the "selected" location blink.
Matti Hamalainen <ccr@tnsp.org>
parents:
750
diff
changeset
|
87 { |
1681 | 88 htt(); |
750
7b990bddefab
Minor glitch- and bugfixes; Add links to location list also.
Matti Hamalainen <ccr@tnsp.org>
parents:
745
diff
changeset
|
89 |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
90 mytt = document.getElementById("tt"+ id); |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
91 |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
92 mytt.style.left = myx + "px"; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
93 mytt.style.top = myy + "px"; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
94 mytt.style.display = "block"; |
1 | 95 } |
96 | |
97 // Hide tooltip | |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
98 function htt() |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
99 { |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
100 if (mytt) |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
101 { |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
102 mytt.style.display = "none"; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
103 } |
1 | 104 } |
745
41e771e28153
Add functionality to highlight some location marker from the map.
Matti Hamalainen <ccr@tnsp.org>
parents:
736
diff
changeset
|
105 |
41e771e28153
Add functionality to highlight some location marker from the map.
Matti Hamalainen <ccr@tnsp.org>
parents:
736
diff
changeset
|
106 |
750
7b990bddefab
Minor glitch- and bugfixes; Add links to location list also.
Matti Hamalainen <ccr@tnsp.org>
parents:
745
diff
changeset
|
107 // Highlight one location (by index number) during page load |
913
32532d4de594
Cleanups; Make the "selected" location blink.
Matti Hamalainen <ccr@tnsp.org>
parents:
750
diff
changeset
|
108 var httID; |
32532d4de594
Cleanups; Make the "selected" location blink.
Matti Hamalainen <ccr@tnsp.org>
parents:
750
diff
changeset
|
109 var httST = 0; |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
110 |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
111 function httBlink(marker) |
913
32532d4de594
Cleanups; Make the "selected" location blink.
Matti Hamalainen <ccr@tnsp.org>
parents:
750
diff
changeset
|
112 { |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
113 httST = !httST; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
114 var mcolor = httST ? "white" : "black"; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
115 shc("maploc"+ marker, mcolor); |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
116 shc("listloc"+ marker, mcolor); |
913
32532d4de594
Cleanups; Make the "selected" location blink.
Matti Hamalainen <ccr@tnsp.org>
parents:
750
diff
changeset
|
117 } |
32532d4de594
Cleanups; Make the "selected" location blink.
Matti Hamalainen <ccr@tnsp.org>
parents:
750
diff
changeset
|
118 |
32532d4de594
Cleanups; Make the "selected" location blink.
Matti Hamalainen <ccr@tnsp.org>
parents:
750
diff
changeset
|
119 |
745
41e771e28153
Add functionality to highlight some location marker from the map.
Matti Hamalainen <ccr@tnsp.org>
parents:
736
diff
changeset
|
120 function httOnLoad() |
41e771e28153
Add functionality to highlight some location marker from the map.
Matti Hamalainen <ccr@tnsp.org>
parents:
736
diff
changeset
|
121 { |
1672
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
122 var hstr = window.location.href; |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
123 if (hstr.indexOf("?") >= 0) |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
124 { |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
125 var name = unescape(hstr.substr(hstr.indexOf("?") + 1).toLowerCase()); |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
126 httID = setInterval(function (qname) { httBlink(qname); }, 500, name); |
be1d08c529c4
Clean up tooltip.js and make it work with stricter content security settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1205
diff
changeset
|
127 } |
745
41e771e28153
Add functionality to highlight some location marker from the map.
Matti Hamalainen <ccr@tnsp.org>
parents:
736
diff
changeset
|
128 } |