annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 //
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 // Positioning, tooltip etc utility functions in JavaScript for BatMUD maps
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 // Programmed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 // (C) Copyright 2006-2024 Tecnic Software productions (TNSP)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 //
2570
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
6 var mapTipData = null;
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
7 var mapTipItem = null, mapTipTitle = null, mapTipNames = null, mapTipFreeform;
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
8 var mapTipXC = 0, mapTipYC = 0;
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
2570
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
10 var mapElem = null, listElem = null, mapElemPrev = null;
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 var mapDragEnable = true, mapDragGoing = false;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 var mapDragPos = { x: 0, y: 0, mx: 0, my: 0 };
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 var mapCurrID;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
2726
b68157126f41 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 2725
diff changeset
16 function mapGetElementCoords(elem)
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 var xc = yc = 0;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 if (elem.offsetParent)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 xc = elem.offsetLeft;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 yc = elem.offsetTop;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 while (elem = elem.offsetParent)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 xc += elem.offsetLeft;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 yc += elem.offsetTop;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 return { x: xc, y: yc, mx: 0, my: 0 };
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
2728
4e2f9e5b0579 Change mapGetWindowSize() to mapGetElementSize(elem) and adjust users accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 2727
diff changeset
34 function mapGetElementSize(elem)
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 {
2728
4e2f9e5b0579 Change mapGetWindowSize() to mapGetElementSize(elem) and adjust users accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 2727
diff changeset
36 var elemW, elemH;
4e2f9e5b0579 Change mapGetWindowSize() to mapGetElementSize(elem) and adjust users accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 2727
diff changeset
37 if (elem.clientWidth || elem.clientHeight)
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 {
2728
4e2f9e5b0579 Change mapGetWindowSize() to mapGetElementSize(elem) and adjust users accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 2727
diff changeset
39 elemW = elem.clientWidth;
4e2f9e5b0579 Change mapGetWindowSize() to mapGetElementSize(elem) and adjust users accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 2727
diff changeset
40 elemH = elem.clientHeight;
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 else
2728
4e2f9e5b0579 Change mapGetWindowSize() to mapGetElementSize(elem) and adjust users accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 2727
diff changeset
43 if (typeof(elem.innerWidth) == 'number')
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 {
2728
4e2f9e5b0579 Change mapGetWindowSize() to mapGetElementSize(elem) and adjust users accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 2727
diff changeset
45 elemW = elem.innerWidth;
4e2f9e5b0579 Change mapGetWindowSize() to mapGetElementSize(elem) and adjust users accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 2727
diff changeset
46 elemH = elem.innerHeight;
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 else
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 {
2728
4e2f9e5b0579 Change mapGetWindowSize() to mapGetElementSize(elem) and adjust users accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 2727
diff changeset
50 elemW = elemH = 0;
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
2728
4e2f9e5b0579 Change mapGetWindowSize() to mapGetElementSize(elem) and adjust users accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 2727
diff changeset
53 return { w: elemW, h: elemH };
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 // Add or remove given CSS class to specified element
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 function mapSetStyle(uid, ustyle, uset)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 var uelem = document.getElementById(uid);
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 if (uelem)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 if (uset)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 uelem.classList.add(ustyle);
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 else
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 uelem.classList.remove(ustyle);
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 // Update the tooltip box
2569
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
72 function mapTooltipUpdate(ev)
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 var x = document.all ? (window.event.x + document.body.scrollLeft) : ev.pageX;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 var y = document.all ? (window.event.y + document.body.scrollTop) : ev.pageY;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 if (mapTipItem != null)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 {
2728
4e2f9e5b0579 Change mapGetWindowSize() to mapGetElementSize(elem) and adjust users accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 2727
diff changeset
78 const dim = mapGetElementSize(window);
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 var boxW = mapTipItem.clientWidth + 25, boxH = mapTipItem.clientHeight + 25;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 if (x + boxW + 15 >= dim.w)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 x -= boxW;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 else
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 x += 15;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 if (y + boxH + 15 >= dim.h)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 y -= boxH;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 else
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 y += 15;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 mapTipXC = x;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 mapTipYC = y;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 mapTipItem.style.left = x + "px";
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 mapTipItem.style.top = y + "px";
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99
2569
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
100 function mapTooltipShow(ev)
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 const eid = ev.target.dataset.id;
2570
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
103 mapTipData = document.getElementById("listloc"+ eid);
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
104 if (mapTipData != null)
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
105 {
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
106 mapTipTitle.textContent = mapTipData.dataset.ttTitle;
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
107 mapTipNames.textContent = mapTipData.dataset.ttNames;
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
108 mapTipFreeform.textContent = mapTipData.dataset.ttFreeform;
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
109 }
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 mapTipItem.style.left = mapTipXC + "px";
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 mapTipItem.style.top = mapTipYC + "px";
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 mapTipItem.style.display = "block";
2570
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
114 mapTooltipUpdate(ev);
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117
2569
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
118 function mapTooltipHide(ev)
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 if (mapTipItem)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 mapTipItem.style.display = "none";
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
2569
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
127 function mapSetActive(eid, uset)
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
128 {
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
129 mapSetStyle('maploc'+eid, "locactive", uset);
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
130 mapSetStyle('listloc'+eid, "locactive", uset);
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
131 }
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
132
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
133
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
134 function mapLocationShow2(ev)
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
135 {
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
136 const eid = ev.target.dataset.id;
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
137
2570
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
138 if (mapElemPrev != null) mapSetActive(mapElemPrev, false);
2569
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
139 mapSetActive(eid, true);
2570
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
140 mapElemPrev = eid;
2569
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
141 }
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
142
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
143
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
144 function mapLocationHide(ev)
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
145 {
2570
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
146 if (mapElemPrev != null) mapSetActive(mapElemPrev, false);
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
147 mapElemPrev = null;
2569
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
148 mapTooltipHide(ev);
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
149 }
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
150
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
151
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
152 function mapLocationShow1(ev)
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
153 {
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
154 const eid = ev.target.dataset.id;
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
155 mapLocationShow2(ev);
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
156
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
157 mapTooltipHide(ev);
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
158 mapTooltipShow(ev);
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
159 }
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
160
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
161
2727
6683547af623 Rename another function.
Matti Hamalainen <ccr@tnsp.org>
parents: 2726
diff changeset
162 function mapSetWindowPosToID(eid)
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 {
2728
4e2f9e5b0579 Change mapGetWindowSize() to mapGetElementSize(elem) and adjust users accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 2727
diff changeset
164 const dim = mapGetElementSize(mapElem);
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 var nelem = document.getElementById('maploc'+eid);
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 if (nelem)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 {
2726
b68157126f41 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 2725
diff changeset
168 const pos = mapGetElementCoords(nelem);
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 mapDragPos.x = pos.x - (dim.w / 2);
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 mapDragPos.y = pos.y - (dim.h / 2);
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 mapElem.scrollLeft = mapDragPos.x;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 mapElem.scrollTop = mapDragPos.y;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 nelem = document.getElementById('listloc'+eid);
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 if (nelem)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 {
2726
b68157126f41 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 2725
diff changeset
179 const pos = mapGetElementCoords(nelem);
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 listElem.scrollTop = pos.y - 10;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184
2569
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
185 function mapLocationClick(ev)
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 const eid = ev.target.dataset.id;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 if (mapCurrID != eid)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 mapSetStyle('maploc'+mapCurrID, "lochilite", false);
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 mapSetStyle('listloc'+mapCurrID, "lochilite", false);
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 mapCurrID = eid;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 mapSetStyle('maploc'+eid, "lochilite", true);
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 mapSetStyle('listloc'+eid, "lochilite", true);
2727
6683547af623 Rename another function.
Matti Hamalainen <ccr@tnsp.org>
parents: 2726
diff changeset
197 mapSetWindowPosToID(eid);
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 function mapDragUpHandler(ev)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 if (mapDragGoing)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 mapDragGoing = false;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 mapElem.style.cursor = "grab";
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 mapElem.style.removeProperty("user-select");
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 function mapDragMoveHandler(ev)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 {
2569
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
214 mapTooltipUpdate(ev);
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 if (mapDragGoing)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 const dx = ev.clientX - mapDragPos.mx;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 const dy = ev.clientY - mapDragPos.my;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 mapElem.scrollLeft = mapDragPos.x - dx;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 mapElem.scrollTop = mapDragPos.y - dy;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225
2569
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
226 function mapDragStartPan(ev)
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 if (mapDragEnable)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 mapElem.style.cursor = "grabbing";
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 mapElem.style.userSelect = "none";
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 mapDragPos = {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 x: mapElem.scrollLeft,
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 y: mapElem.scrollTop,
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 mx: ev.clientX,
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 my: ev.clientY,
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 };
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 mapDragGoing = true;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 function mapOnLoad()
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 mapElem = document.getElementById("smap");
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 listElem = document.getElementById("loclist");
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 mapElem.style.cursor = "grab";
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251
2570
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
252 // Create tooltip div
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
253 mapTipItem = document.createElement("div");
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
254 mapTipItem.id = "tooltip";
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
255 mapTipItem.style.display = "none";
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
256 mapTipTitle = document.createElement("h1");
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
257 mapTipNames = document.createElement("div");
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
258 mapTipNames.className = "names";
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
259 mapTipFreeform = document.createElement("div");
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
260 mapTipFreeform.className = "freeform";
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
261 mapTipItem.appendChild(mapTipTitle);
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
262 mapTipItem.appendChild(mapTipNames);
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
263 mapTipItem.appendChild(mapTipFreeform);
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
264 document.body.appendChild(mapTipItem);
8f923c830b19 Generate tooltips in citymaps via Javascript instead of building them into div elements in mkcitymap.
Matti Hamalainen <ccr@tnsp.org>
parents: 2569
diff changeset
265
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 // Add event listeners to locations
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 var elems = document.getElementsByClassName("loc");
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 for (let i = 0; i < elems.length; i++)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 var elem = elems[i];
2569
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
271 elem.addEventListener("mouseover", mapTooltipShow);
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
272 elem.addEventListener("mouseout", mapTooltipHide);
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
273 elem.addEventListener("click", mapLocationClick);
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 // .. and location list items
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 var elems = document.getElementsByClassName("item");
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 for (let i = 0; i < elems.length; i++)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 var elem = elems[i];
2569
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
281 elem.addEventListener("mouseover", elem.dataset.info == "true" ? mapLocationShow1 : mapLocationShow2);
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
282 elem.addEventListener("mouseout", mapLocationHide);
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
283 elem.addEventListener("click", mapLocationClick);
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 // And map navigation / tooltip stuff
2569
575e23079e62 Rename some functions for cleaner names and consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 2567
diff changeset
287 mapElem.addEventListener("mousedown", mapDragStartPan);
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 document.addEventListener("mousemove", mapDragMoveHandler);
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 document.addEventListener("mouseup", mapDragUpHandler);
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 // Finally, scroll to position
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 var slink = window.location.href;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 if ((spos = slink.indexOf("#")) >= 0)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 var eid = unescape(slink.substr(spos + 1).toLowerCase()).trim();
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 var elem = document.getElementById('maploc'+eid);
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 if (elem)
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 {
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 mapCurrID = eid;
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 mapSetStyle('maploc'+eid, "lochilite", true);
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 mapSetStyle('listloc'+eid, "lochilite", true);
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 setTimeout(function()
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 {
2727
6683547af623 Rename another function.
Matti Hamalainen <ccr@tnsp.org>
parents: 2726
diff changeset
306 mapSetWindowPosToID(eid);
2562
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 },
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 50);
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 }
2b81727da194 Refactor some of the javascript snippets out from the HTML files themselves
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 }