new updateUrl function to store search queries and pagination changes in the url.

This makes it easier for folks to bookmark a page, share a url, etc.
This commit is contained in:
George Stephanis 2015-08-12 14:19:45 -04:00
parent 10255fcdd4
commit 4e1922e9be
1 changed files with 22 additions and 0 deletions

View File

@ -82,6 +82,24 @@
} ) );
}
},
updateUrl : function() {
if ( ! window.history.replaceState ) {
return;
}
var url = data.base_url,
search = $search_field.val();
if ( 1 < this.page ) {
url += '&p=' + encodeURIComponent( this.page );
}
if ( search.length ) {
url += '&s=' + encodeURIComponent( search );
}
window.history.replaceState( {}, '', url );
},
initialize : function() {
this.qty_pages = Math.ceil( $.map( this.model.get( 'rates' ), function(v){return [v]} ).length / this.per_page );
this.page = this.sanitizePage( data.page );
@ -90,6 +108,8 @@
// this.listenTo( this.model, 'saved:rates', this.clearUnloadConfirmation );
$tbody.on( 'change', { view : this }, this.updateModelOnChange );
$search_field.on( 'change search', this.updateUrl() );
$(window).on( 'beforeunload', { view : this }, this.unloadConfirmation );
},
setUnloadConfirmation : function() {
@ -162,10 +182,12 @@
event.preventDefault();
WCTaxTableInstance.page = WCTaxTableInstance.sanitizePage( $( event.currentTarget ).data('goto') );
WCTaxTableInstance.render();
WCTaxTableInstance.updateUrl();
} );
$pagination.on( 'change', 'input', function(event) {
WCTaxTableInstance.page = WCTaxTableInstance.sanitizePage( $( event.currentTarget ).val() );
WCTaxTableInstance.render();
WCTaxTableInstance.updateUrl();
} );
$table.find('.remove_tax_rates').click(function() {