From d9cfc51648223409cdd57b3e55b2faaf90630b83 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Sat, 28 Nov 2015 19:24:49 +0100 Subject: [PATCH] Issue #16: Use window.history.pushState to filter without reload --- ui/route.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/ui/route.go b/ui/route.go index b1feefab7..5209ce95a 100644 --- a/ui/route.go +++ b/ui/route.go @@ -103,22 +103,24 @@ var htmlTable = ` $(function(){ var $filter = $('#filter'); - var params={};window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(str,key,value){params[key] = value;}); - if (params.filter) { - $filter.val(params.filter); - $("td.route:not(:contains('"+params.filter+"'))").each(function() { + function doFilter(v) { + $("tr").show(); + $filter.val(v); + if (!v || v == "") return; + $("td.route:not(:contains('"+v+"'))").each(function() { $(this).parent("tr").hide(); }); } + var params={};window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(str,key,value){params[key] = value;}); + doFilter(params.filter); + $filter.focus(); $filter.keyup(function() { - var url = window.location.href.split('?')[0]; - if ($filter.val() != '') { - url += "?filter=" +$filter.val(); - } - window.location = url; - }) + var v = $filter.val(); + window.history.pushState(null, null, "?filter=" +v); + doFilter(v); + }); })