Add Codacy badge and fix some errors reported by the checker
| | |
| | | Contact and suggestions: mpk_AT_jacekk.info |
| | | |
| | | [![Build Status](https://travis-ci.org/jacekkow/mpk-ttss.svg?branch=master)](https://travis-ci.org/jacekkow/mpk-ttss) |
| | | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/530c81cbab3449a9b24327591361bec8)](https://www.codacy.com/app/jacekkow/mpk-ttss) |
| | | |
| | | ## Differences |
| | | |
| | |
| | | "use strict"; |
| | | 'use strict'; |
| | | |
| | | var ttss_urls = { |
| | | t: 'proxy_tram.php', |
| | |
| | | promise: promise, |
| | | request: request, |
| | | abort: function() { |
| | | request.abort.bind(request) |
| | | request.abort.bind(request); |
| | | return Deferred(promise, request); |
| | | }, |
| | | done: function(func) { |
| | |
| | | } |
| | | } |
| | | }; |
| | | request.open("GET", url, true); |
| | | request.open('GET', url, true); |
| | | request.send(); |
| | | }); |
| | | return Deferred(promise, request); |
| | |
| | | function checkVersionInit() { |
| | | checkVersion(); |
| | | setInterval(checkVersion, 3600000); |
| | | } |
| | | |
| | | |
| | | /******* |
| | | * DOM * |
| | | *******/ |
| | | |
| | | function deleteChildren(element) { |
| | | while(element.lastChild) element.removeChild(element.lastChild); |
| | | } |
| | | |
| | | function addElementWithText(parent, element, text) { |
| | | var elem = document.createElement(element); |
| | | elem.appendChild(document.createTextNode(text)); |
| | | parent.appendChild(elem); |
| | | return elem; |
| | | } |
| | | |
| | | function addCellWithText(parent, text) { |
| | | return addElementWithText(parent, 'td', text); |
| | | } |
| | | |
| | | function addParaWithText(parent, text) { |
| | | return addElementWithText(parent, 'p', text); |
| | | } |
| | | |
| | | function setText(element, text) { |
| | | deleteChildren(element); |
| | | element.appendChild(document.createTextNode(text)); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | function depotIdToVehicleId(depotId, typeHelper) { |
| | | var prop; |
| | | if(typeHelper) { |
| | | for(var prop in vehicles_info) { |
| | | for(prop in vehicles_info) { |
| | | if(prop.substr(0,1) == typeHelper && vehicles_info[prop]['num'].substr(2) == depotId) { |
| | | return prop; |
| | | } |
| | | } |
| | | } else { |
| | | for(var prop in vehicles_info) { |
| | | for(prop in vehicles_info) { |
| | | if(vehicles_info[prop]['num'] == depotId) { |
| | | return prop; |
| | | } |
| | |
| | | .replace('$floor', floor_type); |
| | | |
| | | return span; |
| | | } |
| | | |
| | | |
| | | /******* |
| | | * DOM * |
| | | *******/ |
| | | |
| | | function deleteChildren(element) { |
| | | while(element.lastChild) element.removeChild(element.lastChild); |
| | | } |
| | | |
| | | function addElementWithText(parent, element, text) { |
| | | var elem = document.createElement(element); |
| | | elem.appendChild(document.createTextNode(text)); |
| | | parent.appendChild(elem); |
| | | return elem; |
| | | } |
| | | |
| | | function addCellWithText(parent, text) { |
| | | return addElementWithText(parent, 'td', text); |
| | | } |
| | | |
| | | function addParaWithText(parent, text) { |
| | | return addElementWithText(parent, 'p', text); |
| | | } |
| | | |
| | | function setText(element, text) { |
| | | deleteChildren(element); |
| | | element.appendChild(document.createTextNode(text)); |
| | | } |
| | |
| | | /* Loading animation */ |
| | | nav.loading { |
| | | background-image: -webkit-linear-gradient(45deg,rgba(0,0,0,.1) 25%,transparent 25%,transparent 50%,rgba(0,0,0,.1) 50%,rgba(0,0,0,.1) 75%,transparent 75%,transparent); |
| | | background-image: -moz-linear-gradient(45deg,rgba(0,0,0,.1) 25%,transparent 25%,transparent 50%,rgba(0,0,0,.1) 50%,rgba(0,0,0,.1) 75%,transparent 75%,transparent); |
| | | background-image: -ms-linear-gradient(45deg,rgba(0,0,0,.1) 25%,transparent 25%,transparent 50%,rgba(0,0,0,.1) 50%,rgba(0,0,0,.1) 75%,transparent 75%,transparent); |
| | | background-image: -o-linear-gradient(45deg,rgba(0,0,0,.1) 25%,transparent 25%,transparent 50%,rgba(0,0,0,.1) 50%,rgba(0,0,0,.1) 75%,transparent 75%,transparent); |
| | | background-image: linear-gradient(45deg,rgba(0,0,0,.1) 25%,transparent 25%,transparent 50%,rgba(0,0,0,.1) 50%,rgba(0,0,0,.1) 75%,transparent 75%,transparent); |
| | | -webkit-background-size: 40px 40px; |
| | |
| | | "use strict"; |
| | | 'use strict'; |
| | | |
| | | var ttss_refresh = 20000; // 20 seconds |
| | | |
| | |
| | | |
| | | function loading_end() { |
| | | nav.className = nav.className.replace(' loading', ''); |
| | | } |
| | | |
| | | function startTimer(date) { |
| | | if(date) { |
| | | setText(refresh_text, lang.last_refreshed.replace('$time', lang.time_now)); |
| | | refresh_time = date; |
| | | } |
| | | if(!refresh_time) return; |
| | | if(refresh_timer) clearInterval(refresh_timer); |
| | | |
| | | var now = new Date(); |
| | | var ms = now.getTime() - refresh_time.getTime(); |
| | | |
| | | var interval = 1000; |
| | | if(ms >= 120000) interval = 60000; |
| | | |
| | | refresh_timer = setInterval(function() { |
| | | var now = new Date(); |
| | | var ms = now.getTime() - refresh_time.getTime(); |
| | | |
| | | if(ms >= 120000) { |
| | | setText(refresh_text, lang.last_refreshed.replace( |
| | | '$time', |
| | | lang.time_minutes_ago_prefix + Math.floor(ms / 60000) |
| | | + lang.time_minutes_ago_suffix |
| | | )); |
| | | startTimer(); |
| | | } else { |
| | | setText(refresh_text, lang.last_refreshed.replace( |
| | | '$time', |
| | | lang.time_seconds_ago_prefix + Math.floor(ms / 1000) |
| | | + lang.time_seconds_ago_suffix |
| | | )); |
| | | } |
| | | }, interval); |
| | | } |
| | | |
| | | function loadRoute(tripId, vehicleInfo) { |
| | | if(!tripId) tripId = route_id; |
| | | if(!tripId) return; |
| | | |
| | | if(vehicleInfo === undefined) vehicleInfo = route_vehicle_info; |
| | | |
| | | console.log('loadRoute(' + tripId + ')'); |
| | | |
| | | var prefix = tripId.substr(0, 1); |
| | | var trip = tripId.substr(1); |
| | | |
| | | route_id = tripId; |
| | | route_vehicle_info = vehicleInfo; |
| | | |
| | | if(route_xhr) route_xhr.abort(); |
| | | route_xhr = $.get( |
| | | ttss_urls[prefix] + '/services/tripInfo/tripPassages' |
| | | + '?tripId=' + encodeURIComponent(trip) |
| | | + '&mode=departure' |
| | | ).done(function(data) { |
| | | if(!data.routeName || !data.directionText || data.old.length + data.actual.length == 0) { |
| | | route_id = null; |
| | | return; |
| | | } |
| | | |
| | | setText(route_line, data.routeName + ' ' + data.directionText); |
| | | |
| | | deleteChildren(route_vehicle); |
| | | if(vehicleInfo) { |
| | | var span = displayVehicle(vehicleInfo); |
| | | if(span) { |
| | | setText(route_vehicle, span.title); |
| | | } |
| | | route_vehicle.insertBefore(span, route_vehicle.firstChild); |
| | | } |
| | | |
| | | deleteChildren(route_table); |
| | | |
| | | var all_departures = data.old.concat(data.actual); |
| | | var tr; |
| | | for(var i = 0, il = all_departures.length; i < il; i++) { |
| | | tr = document.createElement('tr'); |
| | | addCellWithText(tr, all_departures[i].actualTime || all_departures[i].plannedTime); |
| | | addCellWithText(tr, all_departures[i].stop_seq_num + '. ' + all_departures[i].stop.name); |
| | | |
| | | if(i < data.old.length) { |
| | | tr.className = 'active'; |
| | | } else if(all_departures[i].status === 'STOPPING') { |
| | | tr.className = 'success'; |
| | | } |
| | | tr.addEventListener('click', function(stopId){ return function(){ loadTimes(stopId); } }(prefix + all_departures[i].stop.shortName) ); |
| | | route_table.appendChild(tr); |
| | | } |
| | | }).fail(fail_ajax); |
| | | return route_xhr; |
| | | } |
| | | |
| | | function loadTimes(stopId) { |
| | |
| | | return times_xhr; |
| | | } |
| | | |
| | | function loadRoute(tripId, vehicleInfo) { |
| | | if(!tripId) tripId = route_id; |
| | | if(!tripId) return; |
| | | |
| | | if(vehicleInfo === undefined) vehicleInfo = route_vehicle_info; |
| | | |
| | | console.log('loadRoute(' + tripId + ')'); |
| | | |
| | | var prefix = tripId.substr(0, 1); |
| | | var trip = tripId.substr(1); |
| | | |
| | | route_id = tripId; |
| | | route_vehicle_info = vehicleInfo; |
| | | |
| | | if(route_xhr) route_xhr.abort(); |
| | | route_xhr = $.get( |
| | | ttss_urls[prefix] + '/services/tripInfo/tripPassages' |
| | | + '?tripId=' + encodeURIComponent(trip) |
| | | + '&mode=departure' |
| | | ).done(function(data) { |
| | | if(!data.routeName || !data.directionText || data.old.length + data.actual.length == 0) { |
| | | route_id = null; |
| | | return; |
| | | } |
| | | |
| | | setText(route_line, data.routeName + ' ' + data.directionText); |
| | | |
| | | deleteChildren(route_vehicle); |
| | | if(vehicleInfo) { |
| | | var span = displayVehicle(vehicleInfo); |
| | | if(span) { |
| | | setText(route_vehicle, span.title); |
| | | } |
| | | route_vehicle.insertBefore(span, route_vehicle.firstChild); |
| | | } |
| | | |
| | | deleteChildren(route_table); |
| | | |
| | | var all_departures = data.old.concat(data.actual); |
| | | var tr; |
| | | for(var i = 0, il = all_departures.length; i < il; i++) { |
| | | tr = document.createElement('tr'); |
| | | addCellWithText(tr, all_departures[i].actualTime || all_departures[i].plannedTime); |
| | | addCellWithText(tr, all_departures[i].stop_seq_num + '. ' + all_departures[i].stop.name); |
| | | |
| | | if(i < data.old.length) { |
| | | tr.className = 'active'; |
| | | } else if(all_departures[i].status === 'STOPPING') { |
| | | tr.className = 'success'; |
| | | } |
| | | tr.addEventListener('click', function(stopId){ return function(){ loadTimes(stopId); } }(prefix + all_departures[i].stop.shortName) ); |
| | | route_table.appendChild(tr); |
| | | } |
| | | }).fail(fail_ajax); |
| | | return route_xhr; |
| | | } |
| | | |
| | | function startTimer(date) { |
| | | if(date) { |
| | | setText(refresh_text, lang.last_refreshed.replace('$time', lang.time_now)); |
| | | refresh_time = date; |
| | | } |
| | | if(!refresh_time) return; |
| | | if(refresh_timer) clearInterval(refresh_timer); |
| | | |
| | | var now = new Date(); |
| | | var ms = now.getTime() - refresh_time.getTime(); |
| | | |
| | | var interval = 1000; |
| | | if(ms >= 120000) interval = 60000; |
| | | |
| | | refresh_timer = setInterval(function() { |
| | | var now = new Date(); |
| | | var ms = now.getTime() - refresh_time.getTime(); |
| | | |
| | | if(ms >= 120000) { |
| | | setText(refresh_text, lang.last_refreshed.replace( |
| | | '$time', |
| | | lang.time_minutes_ago_prefix + Math.floor(ms / 60000) |
| | | + lang.time_minutes_ago_suffix |
| | | )); |
| | | startTimer(); |
| | | } else { |
| | | setText(refresh_text, lang.last_refreshed.replace( |
| | | '$time', |
| | | lang.time_seconds_ago_prefix + Math.floor(ms / 1000) |
| | | + lang.time_seconds_ago_suffix |
| | | )); |
| | | } |
| | | }, interval); |
| | | } |
| | | |
| | | function translate() { |
| | | var elements = document.querySelectorAll('*[data-translate]'); |
| | | |
| | |
| | | return; |
| | | } |
| | | |
| | | var stop; |
| | | if(window.location.hash.match(/^#![0-9]+$/)) { |
| | | loadTimes('t' + window.location.hash.substr(2)); |
| | | } else if(window.location.hash.match(/^#![bt][0-9]+$/)) { |
| | | loadTimes(window.location.hash.substr(2)); |
| | | } else if(window.location.hash.match(/^#![a-z]{2}[0-9]*$/)) { |
| | | var stop = 't' + window.location.hash.substr(4); |
| | | if(stop) stop_id = stop; |
| | | stop = window.location.hash.substr(4); |
| | | if(stop) stop_id = 't' + stop; |
| | | |
| | | if(!change_language(window.location.hash.substr(2, 2))) { |
| | | loadTimes(stop); |
| | | loadTimes(); |
| | | } |
| | | } else if(window.location.hash.match(/^#![a-z]{2}[bt][0-9]*$/)) { |
| | | var stop = window.location.hash.substr(4); |
| | | stop = window.location.hash.substr(4); |
| | | if(stop) stop_id = stop; |
| | | |
| | | if(!change_language(window.location.hash.substr(2, 2))) { |
| | | loadTimes(stop); |
| | | loadTimes(); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | function init() { |
| | | lang_select.addEventListener('input', function(e) { |
| | | lang_select.addEventListener('input', function() { |
| | | change_language(lang_select.value); |
| | | }); |
| | | |
| | | stop_name.addEventListener('input', function(e) { |
| | | stop_name.addEventListener('input', function() { |
| | | if(!stop_name.value) return; |
| | | if(stop_name_autocomplete_timer) clearTimeout(stop_name_autocomplete_timer); |
| | | |
| | |
| | | "use strict"; |
| | | 'use strict'; |
| | | |
| | | var ttss_refresh = 10000; // 10 seconds |
| | | var ttss_position_type = 'RAW'; |
| | |
| | | |
| | | var feature, prefix; |
| | | for(var i = 0; i < stops.length; i++) { |
| | | feature = null; |
| | | if(stops[i].getId) { |
| | | feature = stops[i]; |
| | | } else { |
| | |
| | | function updateStopSource(stops, prefix) { |
| | | var source = stops_source[prefix]; |
| | | var mapping = stops_mapping[prefix]; |
| | | var stop; |
| | | for(var i = 0; i < stops.length; i++) { |
| | | var stop = stops[i]; |
| | | stop = stops[i]; |
| | | |
| | | if(stop.category == 'other') continue; |
| | | if(stops_ignored.includes(stop.shortName)) continue; |
| | |
| | | }).fail(fail_ajax); |
| | | } |
| | | |
| | | function vehiclePath(feature, tripId) { |
| | | function vehiclePath(feature) { |
| | | if(path_xhr) path_xhr.abort(); |
| | | |
| | | var featureId = feature.getId(); |
| | |
| | | return; |
| | | } |
| | | |
| | | var coordinates = feature.getGeometry().getCoordinates(); |
| | | |
| | | var div = document.createElement('div'); |
| | | |
| | | var typeName; |
| | | var name = normalizeName(feature.get('name')); |
| | | var additional; |
| | | var table = document.createElement('table'); |
| | |
| | | if(feature.getId()) features.push(feature); |
| | | }); |
| | | |
| | | var feature = features[0]; |
| | | |
| | | if(features.length > 1) { |
| | | featureClicked(); |
| | | |
| | |
| | | |
| | | addParaWithText(div, lang.select_feature); |
| | | |
| | | var feature, p, a, full_type, typeName; |
| | | var p, a, full_type, typeName; |
| | | for(var i = 0; i < features.length; i++) { |
| | | feature = features[i]; |
| | | |
| | |
| | | return; |
| | | } |
| | | |
| | | var feature = features[0]; |
| | | if(!feature) { |
| | | stops_type.forEach(function(type) { |
| | | if(stops_layer[type].getVisible()) { |
| | |
| | | }); |
| | | |
| | | // Change layer visibility on zoom |
| | | var change_resolution = function(e) { |
| | | var change_resolution = function() { |
| | | stops_type.forEach(function(type) { |
| | | if(type.startsWith('p')) { |
| | | stops_layer[type].setVisible(map.getView().getZoom() >= 16); |