Mercurial > hg > batmud > maputils
annotate www/search.js @ 1818:41469a2f3904
Sync.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 30 Oct 2017 03:24:36 +0200 |
parents | d7deea635463 |
children | 4641b8cbf1fc |
rev | line source |
---|---|
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 // |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 // Frontend map/location search JavaScript functionality |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 // Written by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 // (C) Copyright 2017 Tecnic Software productions (TNSP) |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 // |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 |
1807
d419124e284a
More work on the front-end.
Matti Hamalainen <ccr@tnsp.org>
parents:
1805
diff
changeset
|
7 var mapServer = "wss://tnsp.org:4200"; |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 var fieldPattern, fieldRes, fieldLog; |
1793
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
9 var msgLog, mapWS, mapList = []; |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 function mapAddEventOb(evobj, evtype, evcallback) |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 if (evobj == null || typeof(evobj) == 'undefined') |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 return; |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 if (evobj.addEventListener) |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 evobj.addEventListener(evtype, evcallback, false); |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 else |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 if (evobj.attachEvent) |
1813 | 21 evobj.attachEvent("on"+evtype, evcallback); |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 else |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 evobj["on"+evtype] = evcallback; |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 } |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 function mapAddEvent(obname, evtype, evcallback) |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 mapAddEventOb(document.getElementById(obname), evtype, evcallback); |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 } |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 |
1793
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
33 function mapCapitalize(str) |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
34 { |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
35 return str.substr(0,1).toUpperCase() + str.substr(1); |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
36 } |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
37 |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
38 |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 function mapLog(msg) |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 if (msgLog.length >= 10) |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 msgLog = msgLog.slice(1, 10); |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 msgLog.push(msg); |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 if (fieldLog) |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 fieldLog.innerHTML = msgLog.join("<br>"); |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 } |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 } |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 function mapPerformSearch() |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 { |
1793
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
55 // Check the search pattern for some sanity before |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
56 // submitting to the server .. though we do checks there also. |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
57 var tmp = fieldPattern.value.trim(); |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
58 if (tmp == "") |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 mapLog("Nothing to search for."); |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 return; |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 } |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 |
1793
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
64 if (tmp.length > 40*40) |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
65 { |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
66 mapLog("Search pattern too large!"); |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
67 return; |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
68 } |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
69 |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
70 // Check which maps are enabled, if any |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
71 var searchList = []; |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
72 for (var i = 0; i < mapList.length; i++) |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
73 { |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
74 var res = mapList[i]; |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
75 var elem = document.getElementById("map_"+ res[0]); |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
76 if (elem && elem.checked) |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
77 searchList.push(res[0]); |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
78 } |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
79 |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
80 if (searchList.length == 0 && mapList.length > 0) |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
81 { |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
82 mapLog("No maps selected!"); |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
83 return; |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
84 } |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
85 |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
86 // Are we running an old query? |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 if (mapWS) |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 mapLog("Old query not finished."); |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 return; |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 } |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 |
1793
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
93 // Open a WebSocket connection .. |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
94 mapWS = new WebSocket(mapServer); |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 if (!mapWS) |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 mapLog("Could not create WebSocket connection?"); |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 return; |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 } |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 btnSearch.disabled = true; |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 mapWS.onopen = function() |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 // Web Socket is connected, send data using send() |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 mapLog("Sending query to server."); |
1807
d419124e284a
More work on the front-end.
Matti Hamalainen <ccr@tnsp.org>
parents:
1805
diff
changeset
|
107 mapWS.send("MAPSEARCH:"+ -1 +":"+ searchList.join(":") +"\n" + fieldPattern.value); |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 }; |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 |
1802 | 110 // Register events |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 mapWS.onmessage = function(evt) |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 if (evt.data.substr(0, 6) == "ERROR:") |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 { |
1804
f498299ff758
Improve error and results handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1802
diff
changeset
|
115 var str = "ERROR! "+ evt.data.substr(6); |
f498299ff758
Improve error and results handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1802
diff
changeset
|
116 mapLog(str); |
f498299ff758
Improve error and results handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1802
diff
changeset
|
117 fieldRes.innerHTML = str; |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 } |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 else |
1802 | 120 if (evt.data.substr(0, 7) == "RESULT:" && evt.data.length >= 9) |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 var results = JSON.parse(evt.data.substr(7)); |
1804
f498299ff758
Improve error and results handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1802
diff
changeset
|
123 var str = ""; |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 mapLog("Receiving results."); |
1804
f498299ff758
Improve error and results handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1802
diff
changeset
|
125 |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 if (results) |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 for (var i = 0; i < results.length; i++) |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 var res = results[i]; |
1807
d419124e284a
More work on the front-end.
Matti Hamalainen <ccr@tnsp.org>
parents:
1805
diff
changeset
|
131 |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 str += "<div class=\"result\">"+ |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 "<a href=\"http://jeskko.pupunen.net/gmap2/?x="+ |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 res[5] +"&y="+ res[6] +"&zoom=10\">"+ |
1793
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
135 res[3] +", "+ res[4] +" at "+ mapCapitalize(res[2]) +"</a>"+ |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 " <span class=\"glob\">["+ res[5] +", "+ res[6] +" global]</span>"+ |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 " <span class=\"perc\">("+ res[0] +"% match)</span>"+ |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 (res[1] ? " <span class=\"cent\">centered</span>" : "")+ |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 "</div>"; |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 } |
1802 | 141 |
142 if (str.length == 0) | |
1804
f498299ff758
Improve error and results handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1802
diff
changeset
|
143 str = "No matches found."; |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 } |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 else |
1804
f498299ff758
Improve error and results handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1802
diff
changeset
|
146 str = "ERROR: Could not parse result dataset." |
f498299ff758
Improve error and results handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1802
diff
changeset
|
147 |
f498299ff758
Improve error and results handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1802
diff
changeset
|
148 fieldRes.innerHTML = str; |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 } |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 else |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 if (evt.data.substr(0, 9) == "PROGRESS:") |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 mapLog("Search progress "+ evt.data.substr(9) +"% .."); |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 } |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 else |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 if (evt.data == "END") |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 mapLog("Server ending communication."); |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 mapWS.close(); |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 } |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 else |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 mapLog("Sir! A message for you! "+ evt.data); |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 } |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 }; |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 mapWS.onclose = function() |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 mapWS = null; |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 btnSearch.disabled = false; |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 }; |
1813 | 172 |
173 mapWS.onerror = function() | |
174 { | |
175 mapLog("WebSocket error occured."); | |
176 }; | |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 } |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 |
1790
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
180 function mapGetData() |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
181 { |
1793
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
182 var tmpWS = new WebSocket(mapServer); |
1790
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
183 if (!tmpWS) |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
184 { |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
185 mapLog("Could not create WebSocket connection?"); |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
186 return; |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
187 } |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
188 |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
189 tmpWS.onopen = function() |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
190 { |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
191 tmpWS.send("GETMAPS"); |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
192 }; |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
193 |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
194 tmpWS.onmessage = function(evt) |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
195 { |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
196 if (evt.data.substr(0, 6) == "ERROR:") |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
197 { |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
198 mapLog("ERROR! "+ evt.data.substr(6)); |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
199 } |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
200 else |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
201 if (evt.data.substr(0, 5) == "MAPS:" && evt.data.length > 8) |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
202 { |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
203 var results = JSON.parse(evt.data.substr(5)); |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
204 mapLog("Receiving map information."); |
1793
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
205 if (results && Array.isArray(results)) |
1790
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
206 { |
1793
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
207 mapList = results; |
1790
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
208 var str = ""; |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
209 for (var i = 0; i < results.length; i++) |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
210 { |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
211 var res = results[i]; |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
212 var id = "map_"+ res[0]; |
1793
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
213 str += |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
214 "<input class=\"map\" id=\""+ id + |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
215 "\" type=\"checkbox\" checked=\"checked\">"+ |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
216 "<label for=\""+ id +"\">"+ mapCapitalize(res[0]) +"</label>"; |
1790
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
217 } |
1793
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
218 var elem = document.getElementById("mapList"); |
1790
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
219 elem.innerHTML = str; |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
220 } |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
221 else |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
222 fieldRes.innerHTML = "ERROR!"; |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
223 } |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
224 else |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
225 if (evt.data == "END") |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
226 { |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
227 tmpWS.close(); |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
228 } |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
229 else |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
230 { |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
231 mapLog("Sir! A message for you! "+ evt.data); |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
232 } |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
233 }; |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
234 |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
235 tmpWS.onclose = function() |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
236 { |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
237 tmpWS = null; |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
238 }; |
1813 | 239 |
240 tmpWS.onerror = function() | |
241 { | |
242 mapLog("WebSocket error occured."); | |
243 }; | |
1790
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
244 } |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
245 |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
246 |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
247 function mapInitSearch() |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
248 { |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
249 msgLog = []; |
1790
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
250 mapGetData(); |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1787
diff
changeset
|
251 |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
252 fieldPattern = document.getElementById("pattern"); |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
253 fieldRes = document.getElementById("results"); |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 fieldLog = document.getElementById("log"); |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
255 btnSearch = document.getElementById("btnSearch"); |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
256 |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
257 mapAddEventOb(btnSearch, "click", mapPerformSearch); |
1793
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
258 |
1818 | 259 mapAddEvent("btnClear", "click", |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
260 function () |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
261 { |
1818 | 262 mapLog("Cleared search pattern and results."); |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
263 fieldRes.innerHTML = ""; |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
264 fieldPattern.value = ""; |
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
265 }); |
1793
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
266 |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
267 mapAddEvent("btnMaps", "click", |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
268 function () |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
269 { |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
270 var same = true, first = true; |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
271 for (var i = 0; i < mapList.length; i++) |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
272 { |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
273 var res = mapList[i]; |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
274 var elem = document.getElementById("map_"+ res[0]); |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
275 if (elem) |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
276 { |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
277 if (first) |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
278 same = elem.checked; |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
279 else |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
280 if (elem.checked != same) |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
281 { |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
282 same = false; |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
283 break; |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
284 } |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
285 first = false; |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
286 } |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
287 } |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
288 |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
289 same = !same; |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
290 |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
291 for (var i = 0; i < mapList.length; i++) |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
292 { |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
293 var res = mapList[i]; |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
294 var elem = document.getElementById("map_"+ res[0]); |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
295 if (elem) |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
296 elem.checked = same; |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
297 } |
e65dde84a6a8
Various improvements to the front-end code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
298 }); |
1787
ccf488dac4c2
Some prototyping/initial code for the map search client-side stuff, JavaScript part.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
299 } |