Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created November 17, 2009 19:52
Show Gist options
  • Save cowboy/237212 to your computer and use it in GitHub Desktop.
Save cowboy/237212 to your computer and use it in GitHub Desktop.
// Try this in the Firebug console on:
// http://benalman.com/code/projects/jquery-bbq/examples/fragment-jquery-ui-tabs/
//
// Screenshot:
// http://benalman.com/grab/2535b7.png
(function($){
function get_route() {
var hash = $.param.fragment(),
root = hash.replace( /\?.*/, '' ),
params = $.deparam.querystring( hash );
return { root: root, params: params };
};
function set_route( root, params, merge_mode ) {
var current = $.param.fragment(),
hash;
hash = $.param.querystring( current, params, merge_mode );
if ( root !== '' ) {
hash = hash.replace( /^.*?(?=\?)/, root );
}
$.bbq.pushState( '#' + hash );
}
set_route( '/foo/bar', { a: '/test/1', b: '/other/2' } );
console.log( get_route().root, get_route().params );
set_route( '/foo/bar', { a: '/test/2' } );
console.log( get_route().root, get_route().params );
set_route( '/foo/bar/baz', { c: '/xyz/123' }, 2 );
console.log( get_route().root, get_route().params );
})(window.jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment