Skip to content

Instantly share code, notes, and snippets.

@sx
Forked from cowboy/jquery.ba-queuefn.js
Created September 18, 2012 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sx/3743041 to your computer and use it in GitHub Desktop.
Save sx/3743041 to your computer and use it in GitHub Desktop.
jQuery queueFn: add a $.fn method or function onto the effects queue
/*!
* jQuery queueFn - v0.5 - 06/18/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($){
'$:nomunge'; // Used by YUI compressor.
var defaults = {
queue: 'fx'
};
$.fn.queueFn = function() {
var args = Array.prototype.slice.call( arguments ),
options = $.extend( {}, defaults, typeof args[0] === 'object' && args.shift() ),
fn = args.shift();
fn = $.isFunction( fn ) ? fn : $.fn[ fn ];
return this.queue( options.queue, function(next){
fn.apply( $(this), args );
next();
});
};
})(jQuery);
// usage:
//
// $('#foo').fadeOut().queueFn( 'remove' );
//
// $('#bar').hide().addClass( 'fading' ).fadeIn().queueFn( 'removeClass', 'fading' );
//
// function remove( state ){ state && $(this).remove(); };
// $('#baz').fadeOut().queueFn( remove, some_condition );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment