From 76f5c4d36a5b21663ead52349ad944d18f55e6d6 Mon Sep 17 00:00:00 2001 From: Jacek Kowalski <Jacek@jacekk.info> Date: Sat, 13 Apr 2019 23:06:22 +0000 Subject: [PATCH] Use mapping for transations of feature type --- index.js | 2 map.js | 47 +++++------------------ lang_en.js | 28 ++++++++------ index.html | 4 +- map.html | 4 +- lang_pl.js | 30 ++++++++------- 6 files changed, 47 insertions(+), 68 deletions(-) diff --git a/index.html b/index.html index 7eda651..4b404ec 100644 --- a/index.html +++ b/index.html @@ -134,8 +134,8 @@ </div> </div> <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT" crossorigin="anonymous"></script> - <script type="text/javascript" src="lang_pl.js?v4" id="lang_script"></script> + <script type="text/javascript" src="lang_pl.js?v7" id="lang_script"></script> <script type="text/javascript" src="common.js?v7"></script> - <script type="text/javascript" src="index.js?v4"></script> + <script type="text/javascript" src="index.js?v5"></script> </body> </html> diff --git a/index.js b/index.js index c5e50ad..3000b78 100644 --- a/index.js +++ b/index.js @@ -369,7 +369,7 @@ 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); } diff --git a/lang_en.js b/lang_en.js index 0b767ca..3ced546 100644 --- a/lang_en.js +++ b/lang_en.js @@ -12,8 +12,10 @@ jquery_not_loaded: 'Required JavaScript jQuery library failed to load. You may try refreshing the page.', enter_stop_name_to_begin: 'Enter the stop name to begin.', select_stop_click_go: 'Select the stop and click "Go".', - select_stop_tram: '$stop (tram)', - select_stop_bus: '$stop (bus)', + select_stop_type: { + 'b': '$stop (bus)', + 't': '$stop (tram)', + }, stop_name_placeholder: 'Stop name', go_button: 'Go', refresh_button: '\u27f3 Refresh', @@ -45,16 +47,18 @@ time_minutes_ago_prefix: '', time_minutes_ago_suffix: ' min ago', - type_vehicle: 'Vehicle', - type_bus: 'Bus', - type_tram: 'Tram', - type_stop: 'Stop', - type_stop_bus: 'Bus stop', - type_stop_tram: 'Tram stop', - type_stoppoint: 'Stop point', - type_stoppoint_bus: 'Bus stop point', - type_stoppoint_tram: 'Tram stop point', - type_location: 'Your location', + types: { + v: 'Vehicle', + b: 'Bus', + t: 'Tram', + s: 'Stop', + sb: 'Bus stop', + st: 'Tram stop', + p: 'Stop point', + pb: 'Bus stop point', + pt: 'Tram stop point', + l: 'Your location', + }, select_feature: 'There is more than one feature here. Select the proper one:', departures_for_stop: 'Click for stop departures (and not only this stop point).', diff --git a/lang_pl.js b/lang_pl.js index 0212619..069f80d 100644 --- a/lang_pl.js +++ b/lang_pl.js @@ -12,8 +12,10 @@ jquery_not_loaded: 'Wymagana biblioteka jQuery nie została poprawnie załadowana. Spróbuj odświeżyć stronę.', enter_stop_name_to_begin: 'Zacznij wpisywać nazwę przystanku.', select_stop_click_go: 'Wyierz przystanek i kliknij "Dalej".', - select_stop_tram: '$stop (tramwaj)', - select_stop_bus: '$stop (autobus)', + select_stop_type: { + 'b': '$stop (autobus)', + 't': '$stop (tramwaj)', + }, stop_name_placeholder: 'Nazwa przystanku', go_button: 'Dalej', refresh_button: '\u27f3 Odśwież', @@ -25,8 +27,6 @@ header_line: 'Linia', header_direction: 'Kierunek', header_vehicle: 'Pojazd', - header_bus: 'Autobus', - header_tram: 'Tramwaj', header_time: 'Odjazd', header_delay: 'Opóźn.', header_lines: 'Linie', @@ -47,16 +47,18 @@ time_minutes_ago_prefix: '', time_minutes_ago_suffix: ' min temu', - type_vehicle: 'Pojazd', - type_bus: 'Autobus', - type_tram: 'Tramwaj', - type_stop: 'Przystanek', - type_stop_bus: 'Przystanek autobusowy', - type_stop_tram: 'Przystanek tramwajowy', - type_stoppoint: 'Peron', - type_stoppoint_bus: 'Peron autobusowy', - type_stoppoint_tram: 'Peron tramwajowy', - type_location: 'Twoja lokalizacja', + types: { + 'v': 'Pojazd', + 'b': 'Autobus', + 't': 'Tramwaj', + 's': 'Przystanek', + 'sb': 'Przystanek autobusowy', + 'st': 'Przystanek tramwajowy', + 'p': 'Peron', + 'pb': 'Peron autobusowy', + 'pt': 'Peron tramwajowy', + 'l': 'Twoja lokalizacja', + }, select_feature: 'W tym miejscu znajduje się więcej niż jeden element. Wybierz właściwy z listy:', departures_for_stop: 'Kliknij, by zobaczyć odjazdy dla całego przystanku (a nie tylko peronu).', diff --git a/map.html b/map.html index b75bf55..ff339ed 100644 --- a/map.html +++ b/map.html @@ -24,8 +24,8 @@ <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT" crossorigin="anonymous"></script> <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList"></script> <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v5.3.0/build/ol.js" integrity="sha384-iQkGyyH4ioz3m+maM3s9MX1Oq67mACa4B9Z3ovUv3Sv37LJ96fx3WnZfLoiC3Wfl" crossorigin="anonymous"></script> -<script tyle="text/javascript" src="lang_pl.js?v6" id="lang_script"></script> +<script tyle="text/javascript" src="lang_pl.js?v7" id="lang_script"></script> <script tyle="text/javascript" src="common.js?v7"></script> -<script tyle="text/javascript" src="map.js?v18"></script> +<script tyle="text/javascript" src="map.js?v19"></script> </body> </html> diff --git a/map.js b/map.js index a92594a..1496bb5 100644 --- a/map.js +++ b/map.js @@ -504,19 +504,20 @@ var tabular_data = true; var type = feature.getId().substr(0, 1); + var full_type = feature.getId().match(/^[a-z]+/)[0]; + var typeName = lang.types[full_type]; + if(typeof typeName === 'undefined') { + typeName = ''; + } + // Location if(type == 'l') { tabular_data = false; + name = typeName; typeName = ''; - name = lang.type_location; } // Vehicle else if(ttss_types.indexOf(type) >= 0) { - typeName = lang.type_bus; - if(type == 't') { - typeName = lang.type_tram; - } - var span = displayVehicle(feature.get('vehicle_type')); additional = document.createElement('p'); @@ -539,12 +540,10 @@ else if(['s', 'p'].indexOf(type) >= 0) { var ttss_type = feature.getId().substr(1, 1); if(type == 's') { - typeName = lang.type_stop_tram; var second_type = lang.departures_for_buses; var mapping = stops_mapping['sb']; if(ttss_type == 'b') { - typeName = lang.type_stop_bus; second_type = lang.departures_for_trams; mapping = stops_mapping['st']; } @@ -562,11 +561,6 @@ ); } } else { - typeName = lang.type_stoppoint_tram; - - if(ttss_type == 'b') { - typeName = lang.type_stoppoint_bus; - } stopTable('stopPoint', feature.get('stopPoint'), tbody, ttss_type); @@ -656,31 +650,10 @@ featureClicked(feature); }}(feature)); - var type = feature.getId().substr(0, 1); - var typeName = ''; - if(type == 'l') { + var full_type = feature.getId().match(/^[a-z]+/)[0]; + var typeName = lang.types[full_type]; + if(typeof typeName === 'undefined') { typeName = ''; - name = lang.type_location; - } else if(ttss_types.indexOf(type) >= 0) { - typeName = lang.type_bus; - if(type == 't') { - typeName = lang.type_tram; - } - if(feature.get('vehicle_type').num) { - typeName += ' ' + feature.get('vehicle_type').num; - } - } else if(type == 's') { - typeName = lang.type_stop_tram; - if(feature.getId().startsWith('sb')) { - typeName = lang.type_stop_bus; - } - } else if (type == 'p') { - typeName = lang.type_stoppoint_tram; - if(feature.getId().startsWith('pb')) { - typeName = lang.type_stoppoint_bus; - } - } else { - continue; } addElementWithText(a, 'span', typeName).className = 'small'; -- Gitblit v1.9.1