Skip to content

Commit

Permalink
Preserve search JS results when Back browser button is used
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Nov 14, 2015
1 parent 9cd8b94 commit d7d2ad9
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions mojo-app/public/js/main.js
@@ -1,9 +1,12 @@
var table_plugin;

$(function(){
setup_table();
setup_search_query_save();
});

function setup_table() {
var el = $('#dists'), filter_container, filter, table_plugin, sort_order;
var el = $('#dists'), filter_container, filter, sort_order;

table_plugin = el.DataTable({
paging: false,
Expand Down Expand Up @@ -47,13 +50,26 @@ function setup_table() {
filter.focus();
}

function setup_search_query_save() {
var el = $('#dists_filter').find('[type=search]'),
q = hash_store('q');

if ( typeof(q) !== 'undefined' ) {
el.val( q );
table_plugin.search( q ).draw();
}
el.change(function(){
hash_store('q', $(this).val())
});
}

function hash_store (key, value){
var obj;

try { obj = jQuery.deparam(window.location.hash.replace(/^#/,'')) }
catch (e) { obj = {} }

if ( value ) {
if ( typeof(value) !== 'undefined' ) {
obj[key] = value;
window.location.hash = jQuery.param( obj, true );
}
Expand Down

0 comments on commit d7d2ad9

Please sign in to comment.