Skip to content

Instantly share code, notes, and snippets.

// API
// all deparam methods return an object
$.deparam( params, coerce ) // deserialize params string, optionally coercing true, false, undefined, numbers
$.deparam.qs( coerce ); // get document query string as object
$.deparam.hash( coerce ); // get document hash as object
$.deparam.qs( params_or_url, coerce ); // get params from url or params string as object
// API
// history, window.onhashchange
$.history.add( params, merge_mode ); // set new 'state' (into location.hash, triggers hashchange event)
$.history.retrieve( key, coerce ); // get current 'state' (from location.hash, wrapper for $.deparam.hash)
$(window).bind( 'hashchange', function(e){
e.hash; // the current 'state' as normalized hash string
e.retrieve(); // like $.history.retrieve but for this specific state
function get_hash() {
var loc = document.location;
return loc.hash ? loc.href.replace( /^.*\#/, '' ) : '';
}
if ( 0 ) {
var esh = $.event.special.hashchange = {
setup: function(){
console.log( 'setup' );
$(this).bind( 'hashchange', esh.handler );
// 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 );
// proposed 'until' extension to jQuery.dir to support 'nextUntil' and 'prevUntil'
// suggested by LaC_OS_X
jQuery.dir = function( elem, dir, until ){
var matched = [], cur = elem[dir];
while ( cur && cur != document ) {
if ( cur.nodeType == 1 )
matched.push( cur );
if ( until && jQuery( cur ).is( until ) )
return matched;
@cowboy
cowboy / bash_prompt.sh
Created September 27, 2009 20:00
My bash prompt
#!/bin/bash
# My bash prompt - Ben Alman
# Source: http://gist.github.com/194971
# Screenshot: http://www.flickr.com/photos/rj3/3959554047/sizes/o/
#
# In my home folder, [user@host:directory] on the 1st line, [HH:MM] on the 2nd line:
#
# [cowboy@benalman:~]
# [19:55:20] $
// This has moved! Get it here:
// http://github.com/cowboy/jquery-misc/blob/master/jquery.ba-nextUntil.js
jQuery.fn.nextUntil = function( expr ) {
var elems = [];
this.nextAll().each(function(){
return jQuery(this).is( expr )
? false
: elems.push( this );
@cowboy
cowboy / gyazo.php
Created October 6, 2009 21:30
PHP upload for Gyazo
<?PHP
/*
* PHP upload for Gyazo - v1.2.1 - 3/13/2011
* http://benalman.com/news/2009/10/gyazo-on-your-own-server/
*
* Copyright (c) 2011 "Cowboy" Ben Alman
* Licensed under the MIT license
* http://benalman.com/about/license/
*/
// Potentially part of the jQuery urlInternal plugin
(function($){
// Method: jQuery.isUrlFragment
//
// Test whether or not a URL is a fragment. The URL can either begin with #
// or be a partial URL or full URI, that when navigated to, only changes the
// document.location.hash.
//
@cowboy
cowboy / jquery-param.js
Created October 9, 2009 19:57
jQuery.param, pulled out of 1.4.2, for use with 1.3.2 or earlier.
// jQuery.param, pulled out of 1.4.2
(function($){
var r20 = /%20/g;
// Serialize an array of form elements or a set of
// key/values into a query string
$.param = function( a, traditional ) {
var s = [];