diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-10-14 17:03:50 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-10-14 17:03:50 +0100 |
commit | 4760a1306737536070c2efb97918530af750f4e9 (patch) | |
tree | 0e40228ca5201f8246e2844efadee1f614c3e935 /web/js/map-OpenLayers.js | |
parent | 728b9aa49ca62bf3045bdd904e57ec47359e716a (diff) |
Improve history API URL when query string empty.
Diffstat (limited to 'web/js/map-OpenLayers.js')
-rw-r--r-- | web/js/map-OpenLayers.js | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 7d264860f..353d75707 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -272,6 +272,9 @@ var fixmystreet = fixmystreet || {}; function parse_query_string() { var qs = {}; + if (!location.search) { + return qs; + } location.search.substring(1).split('&').forEach(function(i) { var s = i.split('='), k = s[0], @@ -294,7 +297,14 @@ var fixmystreet = fixmystreet || {}; var qs = parse_query_string(); var filter_categories = replace_query_parameter(qs, 'filter_categories', 'filter_category'); var filter_statuses = replace_query_parameter(qs, 'statuses', 'status'); - var new_url = location.href.replace(location.search, '?' + $.param(qs)); + var new_url; + if ($.isEmptyObject(qs)) { + new_url = location.href.replace(location.search, ""); + } else if (location.search) { + new_url = location.href.replace(location.search, '?' + $.param(qs)); + } else { + new_url = location.href + '?' + $.param(qs); + } history.pushState({ filter_change: { 'filter_categories': filter_categories, 'statuses': filter_statuses } }, null, new_url); |