Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created December 3, 2009 20:50
Show Gist options
  • Save cowboy/248507 to your computer and use it in GitHub Desktop.
Save cowboy/248507 to your computer and use it in GitHub Desktop.
$.bbq.removeState .. until I can add it into the full release
// Going into jQuery BBQ soon!
// http://github.com/cowboy/jquery-bbq
(function($){
// Method: jQuery.bbq.removeState
//
// Remove one or more keys from the current browser history 'state', creating
// a new state, setting location.hash and triggering any bound
// <window.onhashchange> event callbacks (provided the new state is different
// than the previous state).
//
// If no arguments are passed, an empty state is created, which is just a
// shortcut for jQuery.bbq.pushState( {}, 2 ).
//
// Usage:
//
// > jQuery.bbq.removeState( [ key [, key ... ] ] );
//
// Arguments:
//
// key - (String) One or more key values to remove from the current state,
// passed as individual arguments.
// key - (Array) A single array argument that contains a list of key values
// to remove from the current state.
//
// Returns:
//
// Nothing.
//
// Additional Notes:
//
// * Setting an empty state may cause the browser to scroll.
$.bbq.removeState = function( arr ) {
var state = {};
// If one or more arguments is passed..
if ( arr !== undefined ) {
// Get the current state.
state = $.bbq.getState();
// For each passed key, delete the corresponding property from the current
// state.
$.each( $.isArray( arr ) ? arr : arguments, function(i,v){
delete state[ v ];
});
}
// Set the state, completely overriding any existing state.
$.bbq.pushState( state, 2 );
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment