Created
November 17, 2009 19:52
-
-
Save cowboy/237212 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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