X-Git-Url: https://git.openstreetmap.org./nominatim-ui.git/blobdiff_plain/74cf33bfb3c4b8fe562b48b22d1668a0b75b919c..4cef4fd8107653656e83662f71c4cdaeb94708ab:/src/assets/js/controller.js?ds=sidebyside diff --git a/src/assets/js/controller.js b/src/assets/js/controller.js index 4070d09..4196151 100644 --- a/src/assets/js/controller.js +++ b/src/assets/js/controller.js @@ -3,7 +3,9 @@ jQuery(document).ready(function () { function parse_url_and_load_page() { // 'search', 'reverse', 'details' - var pagename = window.location.pathname.replace('.html', '').replace(/^\//, ''); + var pagename = window.location.pathname.replace('.html', '').replace(/.+\//, ''); + + if (pagename === '') pagename = 'search' $('body').attr('id', pagename + '-page'); @@ -22,19 +24,37 @@ jQuery(document).ready(function () { 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 < to_delete.length; i += 1) { + url_params.delete(to_delete[i]); + } + return url_params.toString(); + } + parse_url_and_load_page(); // load page after form submit $(document).on('submit', 'form', function (e) { e.preventDefault(); - window.history.pushState(myhistory, '', '?' + $(this).serialize()); + var target_url = $(this).serialize(); + target_url = clean_up_url_parameters(target_url); + + window.history.pushState(myhistory, '', '?' + target_url); parse_url_and_load_page(); });