commit | author | age
|
c25e91
|
1 |
//var ttss_base = 'http://www.ttss.krakow.pl/internetservice/services'; |
JK |
2 |
var ttss_base = '/proxy.php'; |
|
3 |
var ttss_refresh = 20000; // 20 seconds |
|
4 |
|
f50bae
|
5 |
var page_title = document.getElementsByTagName('title')[0]; |
JK |
6 |
|
9e6757
|
7 |
var language = 'en'; |
JK |
8 |
var lang_select = document.getElementById('lang-select'); |
|
9 |
|
|
10 |
var stop_id = ''; |
c25e91
|
11 |
var stop_name = document.getElementById('stop-name'); |
JK |
12 |
var stop_name_form = stop_name.form; |
|
13 |
var stop_name_autocomplete = document.getElementById('stop-name-autocomplete'); |
|
14 |
var stop_name_autocomplete_xhr; |
e95a73
|
15 |
var stop_name_autocomplete_timer; |
c25e91
|
16 |
|
JK |
17 |
var times_xhr; |
|
18 |
var times_timer; |
|
19 |
var times_stop_name = document.getElementById('times-stop-name'); |
|
20 |
var times_alerts = document.getElementById('times-alerts'); |
|
21 |
var times_table = document.getElementById('times-table'); |
|
22 |
var times_lines = document.getElementById('times-lines'); |
|
23 |
|
|
24 |
/* |
|
25 |
var route_xhr; |
|
26 |
var route_line = document.getElementById('route-line'); |
|
27 |
var route_table = document.getElementById('route-table'); |
|
28 |
*/ |
|
29 |
|
|
30 |
var refresh_button = document.getElementById('refresh'); |
|
31 |
var refresh_text = document.getElementById('refresh-text'); |
|
32 |
var refresh_time; |
|
33 |
var refresh_timer; |
|
34 |
|
|
35 |
var alert = document.getElementById('alert'); |
|
36 |
var alert_text = document.getElementById('alert-text'); |
|
37 |
var alert_close = document.getElementById('alert-close'); |
|
38 |
|
0f9bcf
|
39 |
var nav = document.getElementsByTagName('nav')[0]; |
ac721d
|
40 |
|
c25e91
|
41 |
function parseStatus(status) { |
JK |
42 |
switch(status.status) { |
|
43 |
case 'STOPPING': |
9e6757
|
44 |
return lang.boarding_sign; |
c25e91
|
45 |
case 'PREDICTED': |
JK |
46 |
if(status.actualRelativeTime <= 0) |
9e6757
|
47 |
return lang.boarding_sign; |
c25e91
|
48 |
if(status.actualRelativeTime >= 60) |
9e6757
|
49 |
return lang.time_minutes_prefix + Math.floor(status.actualRelativeTime / 60) + lang.time_minutes_suffix; |
JK |
50 |
return lang.time_seconds_prefix + status.actualRelativeTime + lang.time_seconds_suffix; |
c25e91
|
51 |
case 'DEPARTED': |
9e6757
|
52 |
return lang.time_minutes_ago_prefix + Math.floor(-status.actualRelativeTime / 60) + lang.time_minutes_ago_suffix; |
c25e91
|
53 |
default: |
JK |
54 |
return status.mixedTime; |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
function parseTime(date, time) { |
|
59 |
var result = new Date(date.getFullYear(), date.getMonth(), date.getDay()); |
|
60 |
var time_split = time.split(':'); |
|
61 |
result.setHours(time_split[0]); |
|
62 |
result.setMinutes(time_split[1]); |
|
63 |
|
|
64 |
if(result.getTime() - date.getTime() > 72000000) { |
|
65 |
result.setTime(result.getTime() - 86400000); |
|
66 |
} |
|
67 |
|
|
68 |
if(date.getTime() - result.getTime() > 72000000) { |
|
69 |
result.setTime(result.getTime() + 86400000); |
|
70 |
} |
|
71 |
|
|
72 |
return result; |
|
73 |
} |
|
74 |
|
|
75 |
function parseDelay(status) { |
9e6757
|
76 |
if(!status.actualTime) return lang.unknown_sign; |
JK |
77 |
if(!status.plannedTime) return lang.unknown_sign; |
c25e91
|
78 |
|
JK |
79 |
var now = new Date(); |
|
80 |
var actual = parseTime(now, status.actualTime); |
|
81 |
var planned = parseTime(now, status.plannedTime); |
|
82 |
|
9e6757
|
83 |
return lang.time_minutes_prefix + ((actual.getTime() - planned.getTime()) / 1000 / 60) + lang.time_minutes_suffix; |
c25e91
|
84 |
} |
JK |
85 |
|
8fb34c
|
86 |
function parseVehicle(vehicleId) { |
JK |
87 |
if(!vehicleId) return; |
|
88 |
if(vehicleId.substr(0, 15) != '635218529567218') { |
|
89 |
console.log('Unknown vehicle, vehicleId=' + vehicleId); |
|
90 |
return; |
|
91 |
} |
|
92 |
|
|
93 |
var id = parseInt(vehicleId.substr(15)) - 736; |
|
94 |
var prefix; |
|
95 |
var type; |
|
96 |
var low; // low floor: 0 = no, 1 - semi, 2 - full |
|
97 |
|
45237c
|
98 |
// Single exception - old id used in one case |
JK |
99 |
if(id == 831) { |
|
100 |
id = 216; |
|
101 |
} |
|
102 |
|
8fb34c
|
103 |
if(101 <= id && id <= 173) { |
JK |
104 |
prefix = 'HW'; |
|
105 |
type = 'E1'; |
|
106 |
low = 0; |
|
107 |
|
|
108 |
if((108 <= id && id <= 113) || id == 127 || id == 131 || id == 132 || id == 134 || (137 <= id && id <= 139) || (148 <= id && id <= 150) || (153 <= id && id <= 166) || id == 161) { |
|
109 |
prefix = 'RW'; |
|
110 |
} |
|
111 |
} else if(201 <= id && id <= 293) { |
|
112 |
prefix = 'RZ'; |
|
113 |
type = '105Na'; |
|
114 |
low = 0; |
|
115 |
|
|
116 |
if(246 <= id) { |
|
117 |
prefix = 'HZ'; |
|
118 |
} |
|
119 |
if(id == 290) { |
|
120 |
type = '105Nb'; |
|
121 |
} |
|
122 |
} else if(301 <= id && id <= 328) { |
|
123 |
prefix = 'RF'; |
|
124 |
type = 'GT8S'; |
|
125 |
low = 0; |
|
126 |
|
|
127 |
if(id == 313) { |
|
128 |
type = 'GT8C' |
|
129 |
low = 1; |
|
130 |
} |
|
131 |
} else if(401 <= id && id <= 440) { |
|
132 |
prefix = 'HL'; |
|
133 |
type = 'EU8N'; |
|
134 |
low = 1; |
|
135 |
} else if(451 <= id && id <= 462) { |
|
136 |
prefix = 'HK'; |
|
137 |
type = 'N8S-NF'; |
|
138 |
low = 0; |
|
139 |
|
|
140 |
if((451 <= id && id <= 453) || id == 462) { |
|
141 |
type = 'N8C-NF'; |
|
142 |
low = 1; |
|
143 |
} |
|
144 |
} else if(601 <= id && id <= 650) { |
|
145 |
prefix = 'RP'; |
|
146 |
type = 'NGT6 (3)'; |
|
147 |
low = 2; |
|
148 |
|
|
149 |
if(id <= 613) { |
|
150 |
type = 'NGT6 (1)'; |
|
151 |
} else if (id <= 626) { |
|
152 |
type = 'NGT6 (2)'; |
|
153 |
} |
2f7539
|
154 |
} else if(801 <= id && id <= 824) { |
8fb34c
|
155 |
prefix = 'RY'; |
JK |
156 |
type = 'NGT8'; |
|
157 |
low = 2; |
2f7539
|
158 |
} else if(id == 899) { |
JK |
159 |
prefix = 'RY'; |
|
160 |
type = '126N'; |
|
161 |
low = 2; |
|
162 |
} else if(901 <= id && id <= 936) { |
8fb34c
|
163 |
prefix = 'RG'; |
JK |
164 |
type = '2014N'; |
|
165 |
low = 2; |
|
166 |
|
|
167 |
if(915 <= id) { |
|
168 |
prefix = 'HG'; |
|
169 |
} |
|
170 |
} else if(id === 999) { |
|
171 |
prefix = 'HX'; |
|
172 |
type = '405N-Kr'; |
0d4b30
|
173 |
low = 1; |
8fb34c
|
174 |
} else { |
JK |
175 |
console.log('Unknown vehicle, vehicleId=' + vehicleId + ', id=' + id); |
|
176 |
return; |
|
177 |
} |
|
178 |
|
|
179 |
return { |
|
180 |
vehicleId: vehicleId, |
|
181 |
prefix: prefix, |
|
182 |
id: id, |
|
183 |
num: prefix + id, |
|
184 |
type: type, |
|
185 |
low: low |
|
186 |
}; |
|
187 |
} |
|
188 |
|
|
189 |
function displayVehicle(vehicleInfo) { |
|
190 |
if(!vehicleInfo) return document.createTextNode(''); |
|
191 |
|
|
192 |
var span = document.createElement('span'); |
|
193 |
span.className = 'vehicleInfo'; |
9e6757
|
194 |
|
JK |
195 |
var floor_type = ''; |
8fb34c
|
196 |
if(vehicleInfo.low == 0) { |
9e6757
|
197 |
setText(span, lang.high_floor_sign); |
JK |
198 |
floor_type = lang.high_floor; |
8fb34c
|
199 |
} else if(vehicleInfo.low == 1) { |
9e6757
|
200 |
setText(span, lang.partially_low_floor_sign); |
JK |
201 |
floor_type = lang.partially_low_floor; |
8fb34c
|
202 |
} else if(vehicleInfo.low == 2) { |
9e6757
|
203 |
setText(span, lang.low_floor_sign); |
JK |
204 |
floor_type = lang.low_floor; |
8fb34c
|
205 |
} |
9e6757
|
206 |
|
JK |
207 |
span.title = lang.tram_type_pattern |
|
208 |
.replace('$num', vehicleInfo.num) |
|
209 |
.replace('$type', vehicleInfo.type) |
|
210 |
.replace('$floor', floor_type); |
|
211 |
|
8fb34c
|
212 |
return span; |
JK |
213 |
} |
|
214 |
|
c25e91
|
215 |
function deleteChildren(element) { |
JK |
216 |
while(element.lastChild) element.removeChild(element.lastChild); |
|
217 |
} |
|
218 |
|
|
219 |
function addElementWithText(parent, element, text) { |
|
220 |
var elem = document.createElement(element); |
|
221 |
elem.appendChild(document.createTextNode(text)); |
|
222 |
parent.appendChild(elem); |
|
223 |
return elem; |
|
224 |
} |
|
225 |
|
|
226 |
function addCellWithText(parent, text) { |
75d3f6
|
227 |
return addElementWithText(parent, 'td', text); |
c25e91
|
228 |
} |
JK |
229 |
|
|
230 |
function addParaWithText(parent, text) { |
75d3f6
|
231 |
return addElementWithText(parent, 'p', text); |
c25e91
|
232 |
} |
JK |
233 |
|
|
234 |
function setText(element, text) { |
|
235 |
deleteChildren(element); |
|
236 |
element.appendChild(document.createTextNode(text)); |
|
237 |
} |
|
238 |
|
|
239 |
function fail(message, more) { |
|
240 |
if(times_timer) clearTimeout(times_timer); |
|
241 |
|
|
242 |
setText(alert_text, message); |
|
243 |
alert.style.display = 'block'; |
|
244 |
|
|
245 |
console.log(message + ' More details follow.'); |
|
246 |
if(more) console.log(more); |
|
247 |
} |
|
248 |
|
|
249 |
function fail_ajax(data) { |
|
250 |
// abort() is not a failure |
|
251 |
if(data.readyState == 0 && data.statusText == 'abort') return; |
|
252 |
|
|
253 |
if(data.status == 0) { |
9e6757
|
254 |
fail(lang.error_request_failed_connectivity, data); |
c25e91
|
255 |
} else if (data.statusText) { |
9e6757
|
256 |
fail(lang.error_request_failed_status.replace('$status', data.statusText), data); |
c25e91
|
257 |
} else { |
9e6757
|
258 |
fail(lang.error_request_failed, data); |
c25e91
|
259 |
} |
JK |
260 |
} |
|
261 |
|
e54544
|
262 |
function fail_hide() { |
JK |
263 |
alert.style.display = 'none'; |
|
264 |
} |
|
265 |
|
ac721d
|
266 |
function loading_start() { |
0f9bcf
|
267 |
nav.className += ' loading'; |
ac721d
|
268 |
} |
JK |
269 |
|
|
270 |
function loading_end() { |
0f9bcf
|
271 |
nav.className = nav.className.replace(' loading', ''); |
ac721d
|
272 |
} |
JK |
273 |
|
24a102
|
274 |
function loadTimes(stopId, clearRoute) { |
c25e91
|
275 |
if(!stopId) stopId = stop_id; |
JK |
276 |
if(!stopId) return; |
|
277 |
|
|
278 |
if(times_timer) clearTimeout(times_timer); |
|
279 |
if(times_xhr) times_xhr.abort(); |
|
280 |
|
9e6757
|
281 |
console.log('loadTimes(' + stopId + ', ' + clearRoute + ')'); |
JK |
282 |
|
|
283 |
window.location.hash = '#!' + language + stop_id; |
c25e91
|
284 |
refresh_button.removeAttribute('disabled'); |
JK |
285 |
|
ac721d
|
286 |
loading_start(); |
c25e91
|
287 |
times_xhr = $.get( |
JK |
288 |
ttss_base + '/passageInfo/stopPassages/stop' |
|
289 |
+ '?stop=' + encodeURIComponent(stopId) |
|
290 |
+ '&mode=departure' |
|
291 |
).done(function(data) { |
|
292 |
setText(times_stop_name, data.stopName); |
9e6757
|
293 |
setText(page_title, lang.page_title_stop_name.replace('$stop', data.stopName)); |
c25e91
|
294 |
deleteChildren(times_alerts); |
JK |
295 |
deleteChildren(times_table); |
|
296 |
deleteChildren(times_lines); |
|
297 |
/* |
|
298 |
if(clearRoute) { |
|
299 |
deleteChildren(route_line); |
|
300 |
deleteChildren(route_table); |
|
301 |
} |
|
302 |
*/ |
|
303 |
|
|
304 |
for(var i = 0, il = data.generalAlerts.length; i < il; i++) { |
09944e
|
305 |
addParaWithText(times_alerts, data.generalAlerts[i].title); |
c25e91
|
306 |
} |
JK |
307 |
|
|
308 |
for(var i = 0, il = data.old.length; i < il; i++) { |
|
309 |
var tr = document.createElement('tr'); |
|
310 |
addCellWithText(tr, data.old[i].patternText); |
8fb34c
|
311 |
var dir_cell = addCellWithText(tr, data.old[i].direction); |
JK |
312 |
dir_cell.appendChild(displayVehicle(parseVehicle(data.old[i].vehicleId))); |
c25e91
|
313 |
var status = parseStatus(data.old[i]); |
JK |
314 |
addCellWithText(tr, status); |
|
315 |
addCellWithText(tr, ''); |
|
316 |
|
|
317 |
tr.className = 'active'; |
|
318 |
times_table.appendChild(tr); |
|
319 |
} |
|
320 |
|
|
321 |
for(var i = 0, il = data.actual.length; i < il; i++) { |
|
322 |
var tr = document.createElement('tr'); |
|
323 |
addCellWithText(tr, data.actual[i].patternText); |
8fb34c
|
324 |
var dir_cell = addCellWithText(tr, data.actual[i].direction); |
JK |
325 |
dir_cell.appendChild(displayVehicle(parseVehicle(data.actual[i].vehicleId))); |
c25e91
|
326 |
var status = parseStatus(data.actual[i]); |
e2b283
|
327 |
var status_cell = addCellWithText(tr, status); |
c25e91
|
328 |
var delay = parseDelay(data.actual[i]); |
e2b283
|
329 |
var delay_cell = addCellWithText(tr, delay); |
c25e91
|
330 |
|
9e6757
|
331 |
if(status == lang.boarding_sign) { |
e2b283
|
332 |
tr.className = 'success'; |
JK |
333 |
status_cell.className = 'status-boarding'; |
|
334 |
} else if(parseInt(delay) > 9) { |
|
335 |
tr.className = 'danger'; |
|
336 |
delay_cell.className = 'status-delayed'; |
|
337 |
} else if(parseInt(delay) > 3) { |
|
338 |
tr.className = 'warning'; |
|
339 |
} |
c25e91
|
340 |
times_table.appendChild(tr); |
JK |
341 |
} |
|
342 |
|
|
343 |
for(var i = 0, il = data.routes.length; i < il; i++) { |
|
344 |
var tr = document.createElement('tr'); |
|
345 |
addCellWithText(tr, data.routes[i].name); |
|
346 |
addCellWithText(tr, data.routes[i].directions.join(' - ')); |
|
347 |
addCellWithText(tr, data.routes[i].authority); |
|
348 |
|
|
349 |
/* |
|
350 |
tr.addEventListener('click', function(routeId, routeTr){ return function(e) { |
|
351 |
var trs = tr.parentNode; |
|
352 |
for(var i = 0; i < trs.childNodes.length; i++) { |
|
353 |
trs.childNodes[i].removeAttribute('class'); |
|
354 |
} |
|
355 |
routeTr.className = 'warning'; |
|
356 |
|
|
357 |
if(route_xhr) route_xhr.abort(); |
|
358 |
route_xhr = $.get( |
|
359 |
ttss_base + '/routeInfo/routeStops' |
|
360 |
+ '?routeId=' + encodeURIComponent(routeId) |
|
361 |
).done(function(data) { |
|
362 |
setText(route_line, data.route.name + ': ' |
|
363 |
+ data.route.directions.join(' - ')); |
|
364 |
deleteChildren(route_table); |
|
365 |
|
|
366 |
routeTr.className = 'success'; |
|
367 |
|
|
368 |
for(var i = 0, il = data.stops.length; i < il; i++) { |
|
369 |
var tr = document.createElement('tr'); |
|
370 |
addCellWithText(tr, data.stops[i].name); |
|
371 |
route_table.appendChild(tr); |
|
372 |
} |
|
373 |
}).fail(fail_ajax); |
|
374 |
}}(data.routes[i].id, tr)); |
|
375 |
*/ |
|
376 |
|
|
377 |
times_lines.appendChild(tr); |
|
378 |
|
|
379 |
for(var j = 0, jl = data.routes[i].alerts.length; j < jl; j++) { |
|
380 |
addParaWithText( |
|
381 |
times_alerts, |
9e6757
|
382 |
lang.line_alert_pattern |
JK |
383 |
.replace('$line', data.routes[i].name) |
09944e
|
384 |
.replace('$alert', data.routes[i].alerts[j].title) |
c25e91
|
385 |
); |
JK |
386 |
} |
|
387 |
} |
|
388 |
|
|
389 |
startTimer(new Date()); |
e54544
|
390 |
fail_hide(); |
c25e91
|
391 |
|
JK |
392 |
times_timer = setTimeout(function(){ loadTimes(); }, ttss_refresh); |
ac721d
|
393 |
}).fail(fail_ajax).always(loading_end); |
c25e91
|
394 |
} |
JK |
395 |
|
|
396 |
function declinate(num, singular, plural) { |
|
397 |
if(num == 1) return num + ' ' + singular; |
|
398 |
return num + ' ' + plural; |
|
399 |
} |
|
400 |
|
|
401 |
function startTimer(date) { |
|
402 |
if(date) { |
9e6757
|
403 |
setText(refresh_text, lang.last_refreshed.replace('$time', lang.time_now)); |
c25e91
|
404 |
refresh_time = date; |
JK |
405 |
} |
|
406 |
if(!refresh_time) return; |
|
407 |
if(refresh_timer) clearInterval(refresh_timer); |
|
408 |
|
|
409 |
var now = new Date(); |
|
410 |
var ms = now.getTime() - refresh_time.getTime(); |
|
411 |
|
|
412 |
var interval = 1000; |
|
413 |
if(ms >= 120000) interval = 60000; |
|
414 |
|
|
415 |
refresh_timer = setInterval(function() { |
|
416 |
var now = new Date(); |
|
417 |
var ms = now.getTime() - refresh_time.getTime(); |
|
418 |
|
|
419 |
if(ms >= 120000) { |
9e6757
|
420 |
setText(refresh_text, lang.last_refreshed.replace( |
JK |
421 |
'$time', |
|
422 |
lang.time_minutes_ago_prefix + Math.floor(ms / 60000) |
|
423 |
+ lang.time_minutes_ago_suffix |
|
424 |
)); |
c25e91
|
425 |
startTimer(); |
JK |
426 |
} else { |
9e6757
|
427 |
setText(refresh_text, lang.last_refreshed.replace( |
JK |
428 |
'$time', |
|
429 |
lang.time_seconds_ago_prefix + Math.floor(ms / 1000) |
|
430 |
+ lang.time_seconds_ago_suffix |
|
431 |
)); |
c25e91
|
432 |
} |
JK |
433 |
}, interval); |
|
434 |
} |
|
435 |
|
b50208
|
436 |
var decodeEntitiesTextArea = document.createElement('textarea'); |
JK |
437 |
function decodeEntities(text) { |
|
438 |
decodeEntitiesTextArea.innerHTML = text; |
|
439 |
return decodeEntitiesTextArea.value; |
|
440 |
} |
|
441 |
|
9e6757
|
442 |
function translate() { |
JK |
443 |
var elements = document.querySelectorAll('*[data-translate]'); |
|
444 |
|
|
445 |
var text_name; |
|
446 |
for(var i = 0; i < elements.length; i++) { |
|
447 |
text_name = elements[i].dataset.translate; |
|
448 |
if(lang[text_name] == undefined) { |
|
449 |
console.log('Missing translation: ' + text_name); |
|
450 |
continue; |
|
451 |
} |
|
452 |
setText(elements[i], lang[text_name]); |
|
453 |
} |
|
454 |
|
|
455 |
stop_name.setAttribute('placeholder', lang.stop_name_placeholder); |
|
456 |
|
|
457 |
if(stop_id) return; |
|
458 |
|
|
459 |
if(stop_name_autocomplete.value) { |
|
460 |
setText(refresh_text, lang.select_stop_click_go); |
|
461 |
} else { |
|
462 |
setText(refresh_text, lang.enter_stop_name_to_begin); |
|
463 |
} |
|
464 |
} |
|
465 |
|
|
466 |
function change_language(lang) { |
|
467 |
if(!lang || lang.length != 2) return; |
|
468 |
if(lang == language) return; |
|
469 |
lang_select.value = lang; |
|
470 |
if(!lang_select.value) { |
|
471 |
lang_select.value = language; |
|
472 |
return; |
|
473 |
} |
|
474 |
language = lang; |
|
475 |
|
|
476 |
var script = document.createElement('script'); |
|
477 |
script.type = 'text/javascript'; |
|
478 |
script.src = 'lang_' + lang + '.js'; |
|
479 |
script.id = 'lang_script'; |
|
480 |
script.onload = translate; |
|
481 |
|
|
482 |
document.body.removeChild(document.getElementById('lang_script')); |
|
483 |
document.body.appendChild(script); |
|
484 |
|
|
485 |
window.location.hash = '#!' + language + stop_id; |
|
486 |
} |
|
487 |
|
|
488 |
function hash() { |
|
489 |
if(window.location.hash.match(/^#![0-9]+$/)) { |
|
490 |
loadTimes(parseInt(window.location.hash.substr(2))); |
|
491 |
} else if(window.location.hash.match(/^#![a-z]{2}[0-9]*$/)) { |
|
492 |
var stop = parseInt(window.location.hash.substr(4)); |
|
493 |
if(stop) stop_id = stop; |
|
494 |
change_language(window.location.hash.substr(2, 2)); |
|
495 |
loadTimes(stop_id); |
|
496 |
} |
|
497 |
} |
|
498 |
|
e95a73
|
499 |
function stop_autocomplete() { |
JK |
500 |
if(stop_name_autocomplete_xhr) stop_name_autocomplete_xhr.abort(); |
|
501 |
|
|
502 |
stop_name_autocomplete_xhr = $.get( |
ced309
|
503 |
'stops.php?query=' + encodeURIComponent(stop_name.value) |
e95a73
|
504 |
).done(function(data) { |
JK |
505 |
deleteChildren(stop_name_autocomplete); |
ced309
|
506 |
for(var i = 0, il = data.length; i < il; i++) { |
JK |
507 |
if(data[i].type != 'stop') continue; |
e95a73
|
508 |
if(data[i].id > 6000) continue; |
JK |
509 |
var opt = document.createElement('option'); |
|
510 |
opt.value = data[i].id; |
|
511 |
setText(opt, decodeEntities(data[i].name)); |
|
512 |
stop_name_autocomplete.appendChild(opt); |
|
513 |
} |
|
514 |
|
|
515 |
if(!stop_id) setText(refresh_text, lang.select_stop_click_go); |
|
516 |
}).fail(fail_ajax); |
|
517 |
} |
|
518 |
|
c25e91
|
519 |
function init() { |
JK |
520 |
if(!window.jQuery) { |
9e6757
|
521 |
fail(lang.jquery_not_loaded); |
c25e91
|
522 |
return; |
JK |
523 |
} |
|
524 |
|
|
525 |
$.ajaxSetup({ |
|
526 |
dataType: 'json', |
12310b
|
527 |
timeout: 10000, |
9e6757
|
528 |
}); |
JK |
529 |
|
|
530 |
lang_select.addEventListener('input', function(e) { |
|
531 |
change_language(lang_select.value); |
c25e91
|
532 |
}); |
JK |
533 |
|
|
534 |
stop_name.addEventListener('input', function(e) { |
|
535 |
if(!stop_name.value) return; |
e95a73
|
536 |
if(stop_name_autocomplete_timer) clearTimeout(stop_name_autocomplete_timer); |
c25e91
|
537 |
|
e95a73
|
538 |
stop_name_autocomplete_timer = setTimeout(stop_autocomplete, 100); |
c25e91
|
539 |
}); |
JK |
540 |
|
9e6757
|
541 |
setText(refresh_text, lang.enter_stop_name_to_begin); |
c25e91
|
542 |
|
JK |
543 |
stop_name_form.addEventListener('submit', function(e) { |
|
544 |
e.preventDefault(); |
|
545 |
if(!stop_name_autocomplete.value) return; |
|
546 |
stop_id = stop_name_autocomplete.value; |
|
547 |
loadTimes(stop_id, true); |
|
548 |
}); |
|
549 |
|
|
550 |
refresh_button.addEventListener('click', function(e) { |
|
551 |
loadTimes(stop_id); |
|
552 |
}); |
|
553 |
|
|
554 |
alert_close.addEventListener('click', function(e) { |
|
555 |
alert.style.display = 'none'; |
|
556 |
}); |
492fc5
|
557 |
|
9e6757
|
558 |
hash(); |
JK |
559 |
|
|
560 |
window.addEventListener('hashchange', hash); |
c25e91
|
561 |
} |
JK |
562 |
|
|
563 |
init(); |