From: marc tobias Date: Sat, 30 Nov 2019 15:56:00 +0000 (+0100) Subject: eslint linter, but still many failures X-Git-Url: https://git.openstreetmap.org./nominatim-ui.git/commitdiff_plain/65a67281bcf5f1258512b96136920aceb64a8b23 eslint linter, but still many failures --- diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..7f85a89 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,28 @@ +{ + "env": { + "browser": true, + // "es6": true, + "jquery": true + }, + "extends": [ + "airbnb-base" + ], + "globals": { + "jQuery": true, + "Handlebars": true, + "L": true // Leaflet + }, + "parserOptions": { + "ecmaVersion": 2018 + }, + "rules": { + "camelcase": "off", // abd_def is fine + "vars-on-top": "off", + "comma-dangle": "off", // no comman after last item in list needed + "func-names": "off", // anonymous 'function()' is fine + "object-shorthand": "off", + "prefer-arrow-callback": "off", + "prefer-template": "off", // don't require emplates + "no-var": "off" // don't require let/const + } +} \ No newline at end of file diff --git a/package.json b/package.json index 9c4ac69..f9a3f6f 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,14 @@ "@ungap/url-search-params": "0.1.4", "bootstrap": "3.4.1", "bower": "^1.8", + "eslint": "^6.7.1", + "eslint-config-airbnb-base": "^14.0.0", + "eslint-plugin-import": "^2.18.2", "grunt": "^1.0.2", "handlebars": "4.5.3", "jquery": "3.4.1", "leaflet": "1.6.0", "leaflet-minimap": "3.6.1" - } + }, + "dependencies": {} } diff --git a/src/assets/js/base.js b/src/assets/js/base.js index 8c7696d..a56f40d 100644 --- a/src/assets/js/base.js +++ b/src/assets/js/base.js @@ -2,22 +2,22 @@ var map; var last_click_latlng; -/********************************************************* -* HELPERS -*********************************************************/ +// ********************************************************* +// HELPERS +// ********************************************************* function get_config_value(str, default_val) { - return (typeof Nominatim_Config[str] !== 'undefined' ? Nominatim_Config[str] : default_val); + return (typeof Nominatim_Config[str] !== 'undefined' ? Nominatim_Config[str] : default_val); } -function parse_and_normalize_geojson_string(part){ +function parse_and_normalize_geojson_string(part) { // normalize places the geometry into a featurecollection, similar to // https://github.com/mapbox/geojson-normalize var parsed_geojson = { - type: "FeatureCollection", + type: 'FeatureCollection', features: [ { - type: "Feature", + type: 'Feature', geometry: part, properties: {} } @@ -26,8 +26,8 @@ function parse_and_normalize_geojson_string(part){ return parsed_geojson; } -function map_link_to_osm(){ - return "https://openstreetmap.org/#map=" + map.getZoom() + "/" + map.getCenter().lat + "/" + map.getCenter().lng; +function map_link_to_osm() { + return 'https://openstreetmap.org/#map=' + map.getZoom() + '/' + map.getCenter().lat + '/' + map.getCenter().lng; } function map_viewbox_as_string() { @@ -36,8 +36,8 @@ function map_viewbox_as_string() { var east = bounds.getEast(); if ((east - west) >= 360) { // covers more than whole planet - west = map.getCenter().lng-179.999; - east = map.getCenter().lng+179.999; + west = map.getCenter().lng - 179.999; + east = map.getCenter().lng + 179.999; } east = L.latLng(77, east).wrap().lng; west = L.latLng(77, west).wrap().lng; @@ -51,28 +51,27 @@ function map_viewbox_as_string() { } -/********************************************************* -* PAGE HELPERS -*********************************************************/ +// ********************************************************* +// PAGE HELPERS +// ********************************************************* function fetch_from_api(endpoint_name, params, callback) { - // `&a=&b=&c=1` => '&c=' - for(var k in params) { - if (typeof(params[k]) === 'undefined' || params[k] === '' || params[k] === null ) delete params[k]; + for (var k in params) { + if (typeof (params[k]) === 'undefined' || params[k] === '' || params[k] === null) delete params[k]; } var api_url = get_config_value('Nominatim_API_Endpoint') + endpoint_name + '.php?' + $.param(params); if (endpoint_name !== 'status') { $('#api-request-link').attr('href', api_url); } - $.get(api_url, function(data){ + $.get(api_url, function (data) { callback(data); }); } function update_data_date() { - fetch_from_api('status', {format: 'json'}, function(data){ + fetch_from_api('status', { format: 'json' }, function (data) { $('#data-date').text(data.data_updated); }); } @@ -80,27 +79,26 @@ function update_data_date() { function render_template(el, template_name, page_context) { var template_source = $('#' + template_name).text(); var template = Handlebars.compile(template_source); - var html = template(page_context); + var html = template(page_context); el.html(html); } function show_error(html) { - $('#error-overlay').html(html).show(); + $('#error-overlay').html(html).show(); } function hide_error() { - $('#error-overlay').empty().hide(); + $('#error-overlay').empty().hide(); } -$(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError) { +$(document).ajaxError(function (event, jqXHR, ajaxSettings, thrownError) { // console.log(thrownError); // console.log(ajaxSettings); show_error('Error fetching results from ' + ajaxSettings.url + ''); }); -jQuery(document).ready(function(){ +jQuery(document).ready(function () { hide_error(); }); - diff --git a/src/assets/js/detailpage.js b/src/assets/js/detailpage.js index d180345..9ef2d97 100644 --- a/src/assets/js/detailpage.js +++ b/src/assets/js/detailpage.js @@ -1,7 +1,6 @@ -/********************************************************* -* DETAILS PAGE -*********************************************************/ - +// ********************************************************* +// DETAILS PAGE +// ********************************************************* function init_map_on_detail_page(lat, lon, geojson) { @@ -9,18 +8,20 @@ function init_map_on_detail_page(lat, lon, geojson) { // center: [nominatim_map_init.lat, nominatim_map_init.lon], // zoom: nominatim_map_init.zoom, attributionControl: (get_config_value('Map_Tile_Attribution') && get_config_value('Map_Tile_Attribution').length), - scrollWheelZoom: true, // !L.Browser.touch, - touchZoom: false, + scrollWheelZoom: true, // !L.Browser.touch, + touchZoom: false, }); L.tileLayer(get_config_value('Map_Tile_URL'), { // moved to footer - attribution: (get_config_value('Map_Tile_Attribution') || null ) //'© OpenStreetMap contributors' + attribution: (get_config_value('Map_Tile_Attribution') || null) // '© OpenStreetMap contributors' }).addTo(map); var layerGroup = new L.layerGroup().addTo(map); - var circle = L.circleMarker([lat,lon], { radius: 10, weight: 2, fillColor: '#ff7800', color: 'blue', opacity: 0.75}); + var circle = L.circleMarker([lat, lon], { + radius: 10, weight: 2, fillColor: '#ff7800', color: 'blue', opacity: 0.75 + }); map.addLayer(circle); if (geojson) { @@ -28,26 +29,24 @@ function init_map_on_detail_page(lat, lon, geojson) { // https://leafletjs.com/reference-1.0.3.html#path-option parse_and_normalize_geojson_string(geojson), { - style: function(feature) { - return { interactive: false, color: 'blue' }; + style: function (feature) { + return { interactive: false, color: 'blue' }; } } ); map.addLayer(geojson_layer); map.fitBounds(geojson_layer.getBounds()); } else { - map.setView([lat,lon],10); + map.setView([lat, lon], 10); } - var osm2 = new L.TileLayer(get_config_value('Map_Tile_URL'), {minZoom: 0, maxZoom: 13, attribution: (get_config_value('Map_Tile_Attribution') || null )}); - var miniMap = new L.Control.MiniMap(osm2, {toggleDisplay: true}).addTo(map); + var osm2 = new L.TileLayer(get_config_value('Map_Tile_URL'), { minZoom: 0, maxZoom: 13, attribution: (get_config_value('Map_Tile_Attribution') || null) }); + var miniMap = new L.Control.MiniMap(osm2, { toggleDisplay: true }).addTo(map); } - -jQuery(document).ready(function(){ - - if ( !$('#details-page').length ){ return; } +jQuery(document).ready(function () { + if (!$('#details-page').length) { return; } var search_params = new URLSearchParams(location.search); // var place_id = search_params.get('place_id'); @@ -64,9 +63,8 @@ jQuery(document).ready(function(){ format: 'json' }; - if (api_request_params.place_id || (api_request_params.osmtype && api_request_params.osmid )){ - fetch_from_api('details', api_request_params, function(aFeature){ - + if (api_request_params.place_id || (api_request_params.osmtype && api_request_params.osmid)) { + fetch_from_api('details', api_request_params, function (aFeature) { var context = { aPlace: aFeature }; render_template($('main'), 'detailspage-template', context); @@ -81,7 +79,7 @@ jQuery(document).ready(function(){ render_template($('main'), 'detailspage-index-template'); } - $('#form-by-type-and-id,#form-by-osm-url').on('submit', function(e){ + $('#form-by-type-and-id,#form-by-osm-url').on('submit', function (e) { e.preventDefault(); var val = $(this).find('input[type=edit]').val(); @@ -99,5 +97,4 @@ jQuery(document).ready(function(){ alert('invalid input'); } }); - -}); \ No newline at end of file +}); diff --git a/src/assets/js/searchpage.js b/src/assets/js/searchpage.js index 0b2ad41..c8605ec 100755 --- a/src/assets/js/searchpage.js +++ b/src/assets/js/searchpage.js @@ -1,28 +1,27 @@ -/********************************************************* -* FORWARD/REVERSE SEARCH PAGE -*********************************************************/ +// ********************************************************* +// FORWARD/REVERSE SEARCH PAGE +// ********************************************************* -function display_map_position(mouse_lat_lng){ - +function display_map_position(mouse_lat_lng) { + // if (mouse_lat_lng) { mouse_lat_lng = map.wrapLatLng(mouse_lat_lng); } - html_mouse = "mouse position " + (mouse_lat_lng ? [mouse_lat_lng.lat.toFixed(5), mouse_lat_lng.lng.toFixed(5)].join(',') : '-'); - html_click = "last click: " + (last_click_latlng ? [last_click_latlng.lat.toFixed(5),last_click_latlng.lng.toFixed(5)].join(',') : '-'); + html_mouse = 'mouse position ' + (mouse_lat_lng ? [mouse_lat_lng.lat.toFixed(5), mouse_lat_lng.lng.toFixed(5)].join(',') : '-'); + html_click = 'last click: ' + (last_click_latlng ? [last_click_latlng.lat.toFixed(5), last_click_latlng.lng.toFixed(5)].join(',') : '-'); - html_center = - "map center: " + - map.getCenter().lat.toFixed(5) + ',' + map.getCenter().lng.toFixed(5) + - " view on osm.org"; + html_center = 'map center: ' + + map.getCenter().lat.toFixed(5) + ',' + map.getCenter().lng.toFixed(5) + + ' view on osm.org'; - html_zoom = "map zoom: " + map.getZoom(); + html_zoom = 'map zoom: ' + map.getZoom(); - html_viewbox = "viewbox: " + map_viewbox_as_string(); + html_viewbox = 'viewbox: ' + map_viewbox_as_string(); - $('#map-position-inner').html([html_center,html_zoom,html_viewbox,html_click,html_mouse].join('
')); + $('#map-position-inner').html([html_center, html_zoom, html_viewbox, html_click, html_mouse].join('
')); var center_lat_lng = map.wrapLatLng(map.getCenter()); var reverse_params = { @@ -30,41 +29,48 @@ function display_map_position(mouse_lat_lng){ lon: center_lat_lng.lng.toFixed(5) // zoom: 2, // format: 'html' - } + }; $('#switch-to-reverse').attr('href', 'reverse.html?' + $.param(reverse_params)); $('input#use_viewbox').trigger('change'); } - - - function init_map_on_search_page(is_reverse_search, nominatim_results, request_lat, request_lon, init_zoom) { - + // map = new L.map('map', { // center: [nominatim_map_init.lat, nominatim_map_init.lon], // zoom: nominatim_map_init.zoom, attributionControl: (get_config_value('Map_Tile_Attribution') && get_config_value('Map_Tile_Attribution').length), - scrollWheelZoom: true, // !L.Browser.touch, - touchZoom: false, + scrollWheelZoom: true, // !L.Browser.touch, + touchZoom: false, }); L.tileLayer(get_config_value('Map_Tile_URL'), { // moved to footer - attribution: (get_config_value('Map_Tile_Attribution') || null ) //'© OpenStreetMap contributors' + attribution: (get_config_value('Map_Tile_Attribution') || null ) // '© OpenStreetMap contributors' }).addTo(map); // console.log(Nominatim_Config); map.setView([request_lat, request_lon], init_zoom); - var osm2 = new L.TileLayer(get_config_value('Map_Tile_URL'), {minZoom: 0, maxZoom: 13, attribution: (get_config_value('Map_Tile_Attribution') || null )}); - var miniMap = new L.Control.MiniMap(osm2, {toggleDisplay: true}).addTo(map); + var osm2 = new L.TileLayer(get_config_value('Map_Tile_URL'), { minZoom: 0, maxZoom: 13, attribution: (get_config_value('Map_Tile_Attribution') || null ) }); + new L.Control.MiniMap(osm2, { toggleDisplay: true }).addTo(map); if (is_reverse_search) { // We don't need a marker, but an L.circle instance changes radius once you zoom in/out - var cm = L.circleMarker([request_lat, request_lon], { radius: 5, weight: 2, fillColor: '#ff7800', color: 'red', opacity: 0.75, clickable: false}); + var cm = L.circleMarker( + [request_lat, request_lon], + { + radius: 5, + weight: 2, + fillColor: '#ff7800', + color: 'red', + opacity: 0.75, + clickable: false + } + ); cm.addTo(map); } @@ -72,16 +78,16 @@ function init_map_on_search_page(is_reverse_search, nominatim_results, request_l options: { position: 'topright' }, - onAdd: function (map) { + onAdd: function (/* map */) { var container = L.DomUtil.create('div', 'my-custom-control'); - $(container).text('show map bounds').addClass('leaflet-bar btn btn-sm btn-default').on('click', function(e){ + $(container).text('show map bounds').addClass('leaflet-bar btn btn-sm btn-default').on('click', function (e) { e.preventDefault(); e.stopPropagation(); $('#map-position').show(); $(container).hide(); }); - $('#map-position-close a').on('click', function(e){ + $('#map-position-close a').on('click', function (e) { e.preventDefault(); e.stopPropagation(); $('#map-position').hide(); @@ -98,51 +104,59 @@ function init_map_on_search_page(is_reverse_search, nominatim_results, request_l - function update_viewbox_field(){ + function update_viewbox_field() { // hidden HTML field - $('input[name=viewbox]').val( $('input#use_viewbox').prop('checked') ? map_viewbox_as_string() : ''); + $('input[name=viewbox]').val($('input#use_viewbox').prop('checked') ? map_viewbox_as_string() : ''); } - map.on('move', function(e) { + map.on('move', function () { display_map_position(); update_viewbox_field(); }); - map.on('mousemove', function(e) { + map.on('mousemove', function (e) { display_map_position(e.latlng); }); - map.on('click', function(e) { + map.on('click', function (e) { last_click_latlng = e.latlng; display_map_position(); }); - map.on('load', function(e){ + map.on('load', function () { display_map_position(); }); - - $('input#use_viewbox').on('change', function(){ + $('input#use_viewbox').on('change', function () { update_viewbox_field(); }); - function get_result_element(position){ + function get_result_element(position) { return $('.result').eq(position); } - function marker_for_result(result){ - return L.marker([result.lat,result.lon], {riseOnHover:true,title:result.name }); + function marker_for_result(result) { + return L.marker([result.lat, result.lon], { riseOnHover: true, title: result.name }); } - function circle_for_result(result){ - return L.circleMarker([result.lat,result.lon], { radius: 10, weight: 2, fillColor: '#ff7800', color: 'blue', opacity: 0.75, clickable: !is_reverse_search}); + function circle_for_result(result) { + var cm_style = { + radius: 10, + weight: 2, + fillColor: '#ff7800', + color: 'blue', + opacity: 0.75, + clickable: !is_reverse_search + }; + return L.circleMarker([result.lat, result.lon], cm_style); } var layerGroup = new L.layerGroup().addTo(map); - function highlight_result(position, bool_focus){ + + function highlight_result(position, bool_focus) { var result = nominatim_results[position]; - if (!result){ return } + if (!result) { return; } var result_el = get_result_element(position); $('.result').removeClass('highlight'); @@ -150,26 +164,29 @@ function init_map_on_search_page(is_reverse_search, nominatim_results, request_l layerGroup.clearLayers(); - if (result.lat){ + if (result.lat) { var circle = circle_for_result(result); - circle.on('click', function(){ + circle.on('click', function () { highlight_result(position); }); - layerGroup.addLayer(circle); + layerGroup.addLayer(circle); } - if (result.boundingbox){ - var bounds = [[result.boundingbox[0]*1,result.boundingbox[2]*1], [result.boundingbox[1]*1,result.boundingbox[3]*1]]; + if (result.boundingbox) { + var bounds = [ + [result.boundingbox[0] * 1, result.boundingbox[2] * 1], + [result.boundingbox[1] * 1, result.boundingbox[3] * 1] + ]; map.fitBounds(bounds); - if (result.geojson && result.geojson.type.match(/(Polygon)|(Line)/) ){ - + if (result.geojson && result.geojson.type.match(/(Polygon)|(Line)/)) { + // var geojson_layer = L.geoJson( parse_and_normalize_geojson_string(result.geojson), { // https://leafletjs.com/reference-1.0.3.html#path-option - style: function(feature) { - return { interactive: false, color: 'blue' }; + style: function (feature) { + return { interactive: false, color: 'blue' }; } } ); @@ -179,41 +196,42 @@ function init_map_on_search_page(is_reverse_search, nominatim_results, request_l // var layer = L.rectangle(bounds, {color: "#ff7800", weight: 1} ); // layerGroup.addLayer(layer); // } - } - else { + } else { var result_coord = L.latLng(result.lat, result.lon); - if ( result_coord ){ - if ( is_reverse_search ){ + if (result_coord) { + if (is_reverse_search) { // console.dir([result_coord, [request_lat, request_lon]]); // make sure the search coordinates are in the map view as well - map.fitBounds([result_coord, [request_lat, request_lon]], {padding: [50,50], maxZoom: map.getZoom()}); - - // better, but causes a leaflet warning - // map.panInsideBounds([[result.lat,result.lon], [nominatim_map_init.lat,nominatim_map_init.lon]], {animate: false}); - } - else { + map.fitBounds( + [result_coord, [request_lat, request_lon]], + { + padding: [50, 50], + maxZoom: map.getZoom() + } + ); + } else { map.panTo(result_coord, result.zoom || get_config_value('Map_Default_Zoom')); } } } - if (bool_focus){ + if (bool_focus) { $('#map').focus(); } } - $('.result').on('click', function(e){ + $('.result').on('click', function () { highlight_result($(this).data('position'), true); }); - if ( is_reverse_search ){ - map.on('click', function(e){ - $('form input[name=lat]').val( e.latlng.lat); - $('form input[name=lon]').val( e.latlng.wrap().lng); + if (is_reverse_search) { + map.on('click', function (e) { + $('form input[name=lat]').val(e.latlng.lat); + $('form input[name=lon]').val(e.latlng.wrap().lng); $('form').submit(); }); - $('#switch-coords').on('click', function(e){ + $('#switch-coords').on('click', function (e) { e.preventDefault(); e.stopPropagation(); var lat = $('form input[name=lat]').val(); @@ -227,14 +245,14 @@ function init_map_on_search_page(is_reverse_search, nominatim_results, request_l highlight_result(0, false); // common mistake is to copy&paste latitude and longitude into the 'lat' search box - $('form input[name=lat]').on('change', function(){ + $('form input[name=lat]').on('change', function () { var coords = $(this).val().split(','); - if (coords.length == 2) { + if (coords.length === 2) { $(this).val(L.Util.trim(coords[0])); $(this).siblings('input[name=lon]').val(L.Util.trim(coords[1])); } }); -}; +} @@ -242,11 +260,11 @@ function init_map_on_search_page(is_reverse_search, nominatim_results, request_l -jQuery(document).ready(function(){ +jQuery(document).ready(function () { + // + if (!$('#search-page,#reverse-page').length) { return; } - if ( !$('#search-page,#reverse-page').length ){ return; } - - var is_reverse_search = !!( $('#reverse-page').length ); + var is_reverse_search = !!($('#reverse-page').length); var endpoint = is_reverse_search ? 'reverse' : 'search'; @@ -265,13 +283,11 @@ jQuery(document).ready(function(){ if (is_reverse_search) { var api_request_params = { - // lat: typeof(search_params.get('lat') !== 'undefined') ? search_params.get('lat') : get_config_value('Map_Default_Lat'), - // lon: typeof(search_params.get('lon') !== 'undefined') ? search_params.get('lon') : get_config_value('Map_Default_Lon'), lat: search_params.get('lat'), lon: search_params.get('lon'), zoom: (search_params.get('zoom') !== null ? search_params.get('zoom') : get_config_value('Reverse_Default_Search_Zoom')), format: 'jsonv2' - } + }; var context = { // aPlace: aPlace, @@ -283,7 +299,7 @@ jQuery(document).ready(function(){ if (api_request_params.lat && api_request_params.lon) { - fetch_from_api('reverse', api_request_params, function(aPlace){ + fetch_from_api('reverse', api_request_params, function (aPlace) { if (aPlace.error) { aPlace = null; @@ -293,14 +309,26 @@ jQuery(document).ready(function(){ render_template($('main'), 'reversepage-template', context); - init_map_on_search_page(is_reverse_search, [aPlace], api_request_params.lat, api_request_params.lon, api_request_params.zoom); + init_map_on_search_page( + is_reverse_search, + [aPlace], + api_request_params.lat, + api_request_params.lon, + api_request_params.zoom + ); update_data_date(); }); } else { render_template($('main'), 'reversepage-template', context); - init_map_on_search_page(is_reverse_search, [], get_config_value('Map_Default_Lat'), get_config_value('Map_Default_Lon'), get_config_value('Map_Default_Zoom')); + init_map_on_search_page( + is_reverse_search, + [], + get_config_value('Map_Default_Lat'), + get_config_value('Map_Default_Lon'), + get_config_value('Map_Default_Zoom') + ); } } else { @@ -321,7 +349,7 @@ jQuery(document).ready(function(){ if (api_request_params.q) { - fetch_from_api('search', api_request_params, function(aResults){ + fetch_from_api('search', api_request_params, function (aResults) { context.aSearchResults = aResults; @@ -338,11 +366,5 @@ jQuery(document).ready(function(){ init_map_on_search_page(is_reverse_search, [], get_config_value('Map_Default_Lat'), get_config_value('Map_Default_Lon'), get_config_value('Map_Default_Zoom')); } - - } }); - - - - diff --git a/src/handlebar_helpers.js b/src/handlebar_helpers.js index 7b69d63..6443d37 100644 --- a/src/handlebar_helpers.js +++ b/src/handlebar_helpers.js @@ -1,24 +1,23 @@ -function formatOSMType(sType, bExcludeExternal) -{ - if (sType == 'N') return 'node'; - if (sType == 'W') return 'way'; - if (sType == 'R') return 'relation'; +function formatOSMType(sType, bExcludeExternal) { + if (sType === 'N') return 'node'; + if (sType === 'W') return 'way'; + if (sType === 'R') return 'relation'; if (!bExcludeExternal) return ''; - if (sType == 'T') return 'way'; - if (sType == 'I') return 'way'; + if (sType === 'T') return 'way'; + if (sType === 'I') return 'way'; return ''; } Handlebars.registerHelper({ - isaddresses_unused: function(aAddressLine) { - return ((aAddressLine.isaddress && aAddressLine.isaddress == 'f') ? 'notused' : ''); + isaddresses_unused: function (aAddressLine) { + return ((aAddressLine.isaddress && aAddressLine.isaddress === 'f') ? 'notused' : ''); }, // { osm_type: 'R', osm_id: 12345 } // relation 12345 https://en.wikipedia.org/wiki/London_Borough_of_Redbridge */ - wikipediaLink: function(aPlace) { - if (! aPlace.calculated_wikipedia) return ''; + wikipediaLink: function (aPlace) { + if (!aPlace.calculated_wikipedia) return ''; var parts = aPlace.calculated_wikipedia.split(':', 2); - var sTitle = Handlebars.escapeExpression(aPlace.calculated_wikipedia), - sLanguage = Handlebars.escapeExpression(parts[0]), - sArticle = Handlebars.escapeExpression(parts[1]); + var sTitle = Handlebars.escapeExpression(aPlace.calculated_wikipedia); + var sLanguage = Handlebars.escapeExpression(parts[0]); + var sArticle = Handlebars.escapeExpression(parts[1]); return new Handlebars.SafeString( '' + sTitle + '' @@ -43,54 +42,54 @@ Handlebars.registerHelper({ }, // { osm_type: 'R', osm_id: 12345 } // details - detailsLink: function(aFeature, sTitle) { + detailsLink: function (aFeature, sTitle) { if (!aFeature) return ''; if (!aFeature.place_id) return ''; - sTitle = Handlebars.escapeExpression(sTitle || 'details >'); + var sTitleEscaped = Handlebars.escapeExpression(sTitle || 'details >'); return new Handlebars.SafeString( - '' + sTitle + '' + '' + sTitleEscaped + '' ); }, - detailsPermaLink: function(aFeature, sTitle) { + detailsPermaLink: function (aFeature, sTitle) { if (!aFeature) return ''; var sOSMType = formatOSMType(aFeature.osm_type, false); if (!sOSMType) return ''; - sTitle = Handlebars.escapeExpression(sTitle || sOSMType + ' ' + aFeature.osm_id); + var sTitleEscaped = Handlebars.escapeExpression(sTitle || sOSMType + ' ' + aFeature.osm_id); return new Handlebars.SafeString( - '' + sTitle + '' + '' + sTitleEscaped + '' ); }, - coverageType: function(aPlace) { + coverageType: function (aPlace) { return (aPlace.isarea ? 'Polygon' : 'Point'); }, // fDistance is in meters - formatDistance: function(fDistanceMeters) { + formatDistance: function (fDistanceMeters) { if (fDistanceMeters < 1) return '0'; - var formatted = (fDistanceMeters >= 1000) ? - Math.round(fDistanceMeters/1000, 1) + ' km' : - Math.round(fDistanceMeters, 0) + ' m'; + var formatted = (fDistanceMeters >= 1000) + ? Math.round(fDistanceMeters / 1000, 1) + ' km' + : Math.round(fDistanceMeters, 0) + ' m'; return new Handlebars.SafeString( '~' + formatted + '' ); }, // mark partial tokens (those starting with a space) with a star for readability - formatKeywordToken: function(sToken) { - return (sToken[0] == ' ' ? '*' : '') + Handlebars.escapeExpression(sToken); + formatKeywordToken: function (sToken) { + return (sToken[0] === ' ' ? '*' : '') + Handlebars.escapeExpression(sToken); }, // Any over 15 are invalid data in OSM anyway - formatAdminLevel: function(iLevel) { + formatAdminLevel: function (iLevel) { return (iLevel < 15 ? iLevel : ''); }, - formatMapIcon: function(sIcon) { + formatMapIcon: function (sIcon) { if (!sIcon) return; - + var url = sIcon; if (!url.match(/^http/)) url = get_config_value('Images_Base_Url') + url; @@ -98,67 +97,47 @@ Handlebars.registerHelper({ '' + sIcon + '' ); }, - formatLabel: function(aPlace) { + formatLabel: function (aPlace) { if (aPlace.label) return aPlace.label; - function capitalize(s) - { + function capitalize(s) { return s && s[0].toUpperCase() + s.slice(1); } if (aPlace.type && aPlace.type === 'yes') { return capitalize(aPlace.class.replace(/_/g, ' ')); - } else { - return capitalize(aPlace.type.replace(/_/g, ' ')); } + return capitalize(aPlace.type.replace(/_/g, ' ')); }, - formatSearchRank: function(iRank) { + formatSearchRank: function (iRank) { // same as // https://github.com/openstreetmap/Nominatim/blob/master/sql/functions.sql // get_searchrank_label() - if (iRank < 2) { - return 'continent'; - } else if (iRank < 4) { - return 'sea'; - } else if (iRank < 8) { - return 'country'; - } else if (iRank < 12) { - return 'state'; - } else if (iRank < 16) { - return 'county'; - } else if (iRank == 16) { - return 'city'; - } else if (iRank == 17) { - return 'town / island'; - } else if (iRank == 18) { - return 'village / hamlet'; - } else if (iRank == 20) { - return 'suburb'; - } else if (iRank == 21) { - return 'postcode area'; - } else if (iRank == 22) { - return 'croft / farm / locality / islet'; - } else if (iRank == 23) { - return 'postcode area'; - } else if (iRank == 25) { - return 'postcode point'; - } else if (iRank == 26) { - return 'street / major landmark'; - } else if (iRank == 27) { - return 'minory street / path'; - } else if (iRank == 28) { - return 'house / building'; - } else { - return 'other: ' + iRank; - } + if (iRank < 2) return 'continent'; + if (iRank < 4) return 'sea'; + if (iRank < 8) return 'country'; + if (iRank < 12) return 'state'; + if (iRank < 16) return 'county'; + if (iRank === 16) return 'city'; + if (iRank === 17) return 'town / island'; + if (iRank === 18) return 'village / hamlet'; + if (iRank === 20) return 'suburb'; + if (iRank === 21) return 'postcode area'; + if (iRank === 22) return 'croft / farm / locality / islet'; + if (iRank === 23) return 'postcode area'; + if (iRank === 25) return 'postcode point'; + if (iRank === 26) return 'street / major landmark'; + if (iRank === 27) return 'minory street / path'; + if (iRank === 28) return 'house / building'; + return 'other: ' + iRank; }, - tooManyHierarchyLinesWarning: function(aPlace) { + tooManyHierarchyLinesWarning: function (aPlace) { if (!aPlace.hierarchy) return; var c = 0; for (var type in aPlace.hierarchy) { - c = c + type.length+1; + c = c + type.length + 1; } if (c < 500) return; @@ -166,7 +145,7 @@ Handlebars.registerHelper({ '

There are more child objects which are not shown.

' ); }, - zoomLevels: function(iSelectedZoom) { + zoomLevels: function (iSelectedZoom) { var aZoomLevels = [ /* 0 */ 'Continent / Sea', /* 1 */ '', @@ -193,13 +172,13 @@ Handlebars.registerHelper({ ]; var select = $('