From 2b645413fc163863d000bddde5bc27a836321422 Mon Sep 17 00:00:00 2001 From: Jacek Kowalski <Jacek@jacekk.info> Date: Sat, 13 Apr 2019 23:06:48 +0000 Subject: [PATCH] Get rid of jQuery dependency - use XHR and Promise --- index.js | 23 +++++++++-------------- 1 files changed, 9 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index a3695c9..e59ca07 100644 --- a/index.js +++ b/index.js @@ -176,6 +176,7 @@ times_timer = setTimeout(function(){ loadTimes(); loadRoute(); }, ttss_refresh); }).fail(fail_ajax).always(loading_end); + return times_xhr; } function loadRoute(tripId, vehicleInfo) { @@ -239,6 +240,7 @@ route_table.appendChild(tr); } }).fail(fail_ajax); + return route_xhr; } function startTimer(date) { @@ -282,7 +284,7 @@ var text_name; for(var i = 0; i < elements.length; i++) { text_name = elements[i].dataset.translate; - if(lang[text_name] == undefined) { + if(typeof lang[text_name] === 'undefined') { console.log('Missing translation: ' + text_name); continue; } @@ -315,13 +317,15 @@ } language = lang; + var old_script = document.getElementById('lang_script'); + var old_version = old_script.src.match(/\?v[0-9]+/)[0]; var script = document.createElement('script'); script.type = 'text/javascript'; - script.src = 'lang_' + lang + '.js'; + script.src = 'lang_' + lang + '.js' + (old_version ? old_version : ''); script.id = 'lang_script'; script.onload = translate; - document.body.removeChild(document.getElementById('lang_script')); + document.body.removeChild(old_script); document.body.appendChild(script); ignore_hashchange = true; @@ -367,25 +371,16 @@ for(var i = 0, il = data.length; i < il; i++) { var opt = document.createElement('option'); opt.value = data[i].id; - setText(opt, data[i].id.substr(0,1) == 'b' ? lang.select_stop_bus.replace('$stop', data[i].name) : lang.select_stop_tram.replace('$stop', data[i].name)); + setText(opt, lang.select_stop_type[data[i].id.substr(0,1)].replace('$stop', data[i].name)); stop_name_autocomplete.appendChild(opt); } if(!stop_id) setText(refresh_text, lang.select_stop_click_go); }).fail(fail_ajax); + return stop_name_autocomplete_xhr; } function init() { - if(!window.jQuery) { - fail(lang.jquery_not_loaded); - return; - } - - $.ajaxSetup({ - dataType: 'json', - timeout: 10000, - }); - lang_select.addEventListener('input', function(e) { change_language(lang_select.value); }); -- Gitblit v1.9.1