Created
September 21, 2009 19:02
-
-
Save cowboy/190474 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
// API for jQuery BBQ: Back Button & Query Library | |
// ==== HISTORY, window.onhashchange ==== | |
// set new 'state' to location.hash (triggers hashchange event) | |
$.history.add( params, merge_mode ); | |
// get current 'state' from location.hash (wrapper for $.deparam.fragment) | |
$.history.retrieve( key, coerce ); | |
// set polling loop delay for browsers that don't support window.onhashchange natively | |
$.history.pollDelay = 100; | |
// Usage in 1.3.2: | |
$(window).bind( 'hashchange', function() { | |
var hash_str = $.param.fragment(), | |
param_obj = $.history.retrieve(), | |
param_val = $.history.retrieve( 'param_name' ); | |
... | |
}); | |
// Usage in 1.3.3+: | |
$(window).bind( 'hashchange', function(e) { | |
var hash_str = e.hash, | |
param_obj = e.retrieve(), | |
param_val = e.retrieve( 'param_name' ); | |
... | |
}); | |
// trigger bound callbacks (like on page load, to handle the state the page loaded with) | |
$(window).trigger( 'hashchange' ); | |
// ==== DEPARAM ==== | |
// (all $.deparam methods return an object) | |
$.deparam( params, coerce ) // deserialize params string, optionally coercing true, false, undefined, numbers | |
$.deparam.querystring( coerce ); // get document query string as object | |
$.deparam.fragment( coerce ); // get document hash as object | |
$.deparam.querystring( params_or_url, coerce ); // get params from url or params string as object | |
$.deparam.fragment( params_or_url, coerce ); // get params from url or params string as object | |
// ==== PARAM ==== | |
// (all $.param methods return a string) | |
$.param( params ) // serialize params string (jQuery built-in) | |
$.param.querystring(); // get document query string as urlencoded params string | |
$.param.fragment(); // get document hash as urlencoded params string (fixing ff urldecoding issues) | |
$.param.querystring( params_or_url ); // get params from url or params string as urlencoded params string | |
$.param.fragment( params_or_url ); // get params from url or params string as urlencoded params string | |
$.param.querystring( url, url_or_params, merge_mode ); // get full url string with params merged into search ? (params can be in a url) | |
$.param.fragment( url, url_or_params, merge_mode ); // get full url string with params merged into fragment # (params can be in a url) | |
// ==== COLLECTIONS ($.fn)==== | |
// merge params into pre-existing url (or empty string) stored in attribute | |
$.fn.querystring( attr, params, merge_mode ); | |
$.fn.fragment( attr, params, merge_mode ); | |
// specify default attr-per-elem for $.fn.querystring / $.fn.fragment | |
$.param.urlAttr( obj ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment