X-Git-Url: https://git.openstreetmap.org./nominatim-ui.git/blobdiff_plain/6beafb16431a1cf87ad160ab50b07db31971d873..ee9ae6193aefe2a28522a71406cbb92614844f1e:/dist/assets/js/nominatim-ui.js diff --git a/dist/assets/js/nominatim-ui.js b/dist/assets/js/nominatim-ui.js index 05019aa..87776c4 100644 --- a/dist/assets/js/nominatim-ui.js +++ b/dist/assets/js/nominatim-ui.js @@ -131,16 +131,19 @@ function hide_error() { } -$(document).ajaxError(function (event, jqXHR, ajaxSettings/* , thrownError */) { - // console.log(thrownError); - // console.log(ajaxSettings); - var url = ajaxSettings.url; - show_error('Error fetching results from ' + url + ''); -}); - - jQuery(document).ready(function () { hide_error(); + + $(document).ajaxStart(function () { + $('#loading').fadeIn('fast'); + }).ajaxComplete(function () { + $('#loading').fadeOut('fast'); + }).ajaxError(function (event, jqXHR, ajaxSettings/* , thrownError */) { + // console.log(thrownError); + // console.log(ajaxSettings); + var url = ajaxSettings.url; + show_error('Error fetching results from ' + url + ''); + }); }); // ********************************************************* // DETAILS PAGE @@ -198,8 +201,7 @@ function init_map_on_detail_page(lat, lon, geojson) { } -jQuery(document).ready(function () { - if (!$('#details-page').length) { return; } +function details_page_load() { var search_params = new URLSearchParams(window.location.search); // var place_id = search_params.get('place_id'); @@ -255,7 +257,7 @@ jQuery(document).ready(function () { alert('invalid input'); } }); -}); +} // ********************************************************* // FORWARD/REVERSE SEARCH PAGE @@ -428,20 +430,6 @@ function init_map_on_search_page(is_reverse_search, nominatim_results, request_l update_viewbox_field(); }); - $("input[name='query-selector']").click(function () { - var query_val = $("input[name='query-selector']:checked").val(); - if (query_val === 'simple') { - $('div.form-group-simple').removeClass('hidden'); - $('div.form-group-structured').addClass('hidden'); - $('.form-group-structured').find('input:text').val(''); - } else if (query_val === 'structured') { - console.log('here'); - $('div.form-group-simple').addClass('hidden'); - $('div.form-group-structured').removeClass('hidden'); - $('.form-group-simple').find('input:text').val(''); - } - }); - function get_result_element(position) { return $('.result').eq(position); } @@ -564,12 +552,9 @@ function init_map_on_search_page(is_reverse_search, nominatim_results, request_l +function search_page_load() { -jQuery(document).ready(function () { - // - if (!$('#search-page,#reverse-page').length) { return; } - - var is_reverse_search = !!($('#reverse-page').length); + var is_reverse_search = window.location.pathname.match(/reverse/); var search_params = new URLSearchParams(window.location.search); @@ -686,7 +671,7 @@ jQuery(document).ready(function () { if (aResults.length >= 10) { var aExcludePlaceIds = []; if (search_params.has('exclude_place_ids')) { - aExcludePlaceIds.search_params.get('exclude_place_ids').split(','); + aExcludePlaceIds = search_params.get('exclude_place_ids').split(','); } for (var i = 0; i < aResults.length; i += 1) { aExcludePlaceIds.push(aResults[i].place_id); @@ -724,13 +709,14 @@ jQuery(document).ready(function () { ); } } -}); +} + + // ********************************************************* // DELETABLE PAGE // ********************************************************* -jQuery(document).ready(function () { - if (!$('#deletable-page').length) { return; } +function deletable_page_load() { var api_request_params = { format: 'json' @@ -744,14 +730,13 @@ jQuery(document).ready(function () { update_data_date(); }); -}); +} // ********************************************************* // BROKEN POLYGON PAGE // ********************************************************* -jQuery(document).ready(function () { - if (!$('#polygons-page').length) { return; } - +function polygons_page_load() { + // var api_request_params = { format: 'json' }; @@ -764,4 +749,82 @@ jQuery(document).ready(function () { update_data_date(); }); +} +jQuery(document).ready(function () { + var myhistory = []; + + function parse_url_and_load_page() { + // 'search', 'reverse', 'details' + var pagename = window.location.pathname.replace('.html', '').replace(/^\//, ''); + + $('body').attr('id', pagename + '-page'); + + if (pagename === 'search' || pagename === 'reverse') { + search_page_load(); + } else if (pagename === 'details') { + details_page_load(); + } else if (pagename === 'deletable') { + deletable_page_load(); + } else if (pagename === 'polygons') { + polygons_page_load(); + } + } + + function is_relative_url(url) { + if (!url) return false; + if (url.indexOf('?') === 0) return true; + if (url.indexOf('/') === 0) return true; + if (url.indexOf('#') === 0) return false; + if (url.match(/^http/)) return false; + if (!url.match(/\.html/)) return true; + + return false; + } + + // remove any URL paramters with empty values + // '&empty=&filled=value' => 'filled=value' + function clean_up_url_parameters(url) { + var url_params = new URLSearchParams(url); + var to_delete = []; // deleting inside loop would skip iterations + url_params.forEach(function (value, key) { + if (value === '') to_delete.push(key); + }); + for (var i=0; i