From e8f60c7648e2ab5b61828faee9491fba4de3e79f Mon Sep 17 00:00:00 2001 From: Jordan Grossman Date: Sun, 24 Aug 2014 16:43:13 -0400 Subject: [PATCH 1/2] removed global timer to handle multiple uses calls using this for multiple events at once was causing one call to kill the timer for the other one. attaching the timer to "this" seems to solve that problem --- jquery.unevent.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jquery.unevent.js b/jquery.unevent.js index 865bb5d..e214d47 100644 --- a/jquery.unevent.js +++ b/jquery.unevent.js @@ -7,7 +7,7 @@ * 2013/07/26 **/ ;(function ($) { - var on = $.fn.on, timer; + var on = $.fn.on; $.fn.on = function () { var args = Array.apply(null, arguments); var last = args[args.length - 1]; @@ -19,12 +19,12 @@ args.push(function () { var self = this, params = arguments; - clearTimeout(timer); - timer = setTimeout(function () { + clearTimeout(this.timer); + this.timer = setTimeout(function () { fn.apply(self, params); }, delay); }); return on.apply(this, args); }; -}(this.jQuery || this.Zepto)); \ No newline at end of file +}(this.jQuery || this.Zepto)); From fe9779a6812f0243a70bfabb0f54f9cb2bc4d6a4 Mon Sep 17 00:00:00 2001 From: Jordan Grossman Date: Sun, 24 Aug 2014 16:47:18 -0400 Subject: [PATCH 2/2] Changed plugin name to $.afterEvent so it's clearer --- jquery.unevent.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/jquery.unevent.js b/jquery.unevent.js index e214d47..3037627 100644 --- a/jquery.unevent.js +++ b/jquery.unevent.js @@ -7,8 +7,7 @@ * 2013/07/26 **/ ;(function ($) { - var on = $.fn.on; - $.fn.on = function () { + $.fn.afterEvent = function () { var args = Array.apply(null, arguments); var last = args[args.length - 1]; @@ -25,6 +24,6 @@ }, delay); }); - return on.apply(this, args); + return $.fn.on.apply(this, args); }; }(this.jQuery || this.Zepto));