Created
March 30, 2011 18:27
-
-
Save cowboy/894952 to your computer and use it in GitHub Desktop.
Like jQuery's .one but runs only once, across multiple elements and/or event types.
This file contains 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
/*! | |
* jQuery oneOnly - v0.1pre - 03/30/2011 | |
* http://benalman.com/ | |
* | |
* Copyright (c) 2011 "Cowboy" Ben Alman | |
* Dual licensed under the MIT and GPL licenses. | |
* http://benalman.com/about/license/ | |
*/ | |
(function($){ | |
$.fn.oneOnly = function( types ) { | |
var elems = this, | |
args = Array.prototype.slice.call(arguments), | |
fn = args.pop(); | |
function handler() { | |
elems.unbind(types, handler); | |
return fn.apply(this, arguments); | |
} | |
return this.bind.apply(this, args.concat(handler)); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: http://jsfiddle.net/cowboy/BfDej/