From 7b80dc4ccae5e77fd148e5bd114d9a012db67faf Mon Sep 17 00:00:00 2001 From: temp01 Date: Sun, 5 Sep 2010 05:23:26 -0700 Subject: [PATCH] Added .queueFn( [ once, ] fn [, arg... ] ) signature, if once (Boolean) is true, callback executes just once (not once for each selected element) --- jquery.ba-queuefn.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/jquery.ba-queuefn.js b/jquery.ba-queuefn.js index e85a6e2..8c45686 100644 --- a/jquery.ba-queuefn.js +++ b/jquery.ba-queuefn.js @@ -1,5 +1,5 @@ /*! - * jQuery queueFn - v0.6 - 06/21/2010 + * jQuery queueFn - v0.7 - 9/05/2010 * http://benalman.com/projects/jquery-misc-plugins/ * * Copyright (c) 2010 "Cowboy" Ben Alman @@ -11,12 +11,22 @@ '$:nomunge'; // Used by YUI compressor. $.fn.queueFn = function( fn ) { - var args = Array.prototype.slice.call( arguments, 1 ); + var i, + that, + args = Array.prototype.slice.call( arguments, 1 ); + + if ( typeof fn === 'boolean' ) { + if ( fn ) { + that = this; + i = this.length; + } + fn = args.shift(); + } fn = $.isFunction( fn ) ? fn : $.fn[ fn ]; return this.queue(function(){ - fn.apply( $(this), args ); + !--i && fn.apply( that || this, args ); $.dequeue( this ); }); };