diff --git a/app/views/shared/_filter.html.erb b/app/views/shared/_filter.html.erb index 7359b80..85c6d97 100644 --- a/app/views/shared/_filter.html.erb +++ b/app/views/shared/_filter.html.erb @@ -46,6 +46,7 @@ var datas = window.location.search ? window.location.search.replace('?','').split('&') : [] datas.map(function(data){ tmp = data.split("="); + tmp[1] = decodeURIComponent(tmp[1]); if(key){ if(tmp[0]==key){ if(tmp[0].indexOf('[]')>=0){ @@ -80,14 +81,15 @@ searchLock = true; if(interval==0){ url = document.URL; + url = url.replace('#',''); if(url.indexOf("keywords=")>=0){ - console.log("keywords="+params("keywords")); - url = url.replace("keywords="+params("keywords"),"keywords="+keyword) + url = url.replace("keywords="+encodeURIComponent(params("keywords")),"keywords="+keyword) }else{ - url = (url.indexOf("?")>=0) ? url+'&'+"&keywords="+keyword : url+"?keywords="+keyword + url = (url.indexOf("?")>=0) ? url+"&keywords="+keyword : url+"?keywords="+keyword } + url = url.replace("page="+params("page"),"page=1"); - history.replaceState(null, null, decodeURIComponent(url)); + history.pushState(null, null, url); $.get(url,function(data){ searchLock = false; $("#<%= search_dom_id %>").html(data); @@ -103,7 +105,7 @@ var bindPagination = function(){ $(".pagination a").click(function(){ - filter.updateTable($(this).attr('href')); + filter.updateTable($(this).attr('href'),false,true); return false; }); } @@ -117,7 +119,7 @@ var filters = makeFilters(), dom = $(dom), mainUrl = window.location.pathname; - this.updateTable = function(url, goback){ + this.updateTable = function(url, goback, is_pagination){ update = true; xurl = (url == null ? ( filters.length ? mainUrl + "?" + filters.join('&') : mainUrl ) : url); $.ajax({ @@ -125,13 +127,15 @@ type : "get", dataType : "html" }).done(function(data){ - if(!goback){ - history.replaceState(null, null, decodeURIComponent(xurl)); + if(is_pagination){ + history.pushState(null, null, decodeURIComponent(xurl)); + }else{ + if(!goback) history.replaceState(null, null, decodeURIComponent(xurl)); } - filters = makeFilters(); dom.html(data); bindPagination(); + update = false; }) } this.addFilter = function(filter){ @@ -160,9 +164,11 @@ window.onpopstate = function(event){ if(!update){ - self.updateTable(document.location.href, true); + $("#filter-input").val( $.isEmptyObject(params('keywords')) ? "" : params('keywords') ); + self.updateTable(document.location, true); $(".filter-group .btn-small").removeClass('active'); $.each(document.location.search.split('&'),function(key,filter){ + if(filter.split('=')[0].indexOf("keywords")>=0) return true; $('#filter_'+filter.split('=')[1]).addClass('active'); }); }