From 937caab6475e53a7ea0206e992f8a52449232e78 Mon Sep 17 00:00:00 2001 From: Matias Niemelä Date: Thu, 28 Nov 2013 01:10:28 -0500 Subject: feat(jqLite): provide support for element.one() --- src/jqLite.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index c1b5b36e..e5980514 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -54,6 +54,7 @@ * - [`next()`](http://api.jquery.com/next/) - Does not support selectors * - [`on()`](http://api.jquery.com/on/) - Does not support namespaces, selectors or eventData * - [`off()`](http://api.jquery.com/off/) - Does not support namespaces or selectors + * - [`one()`](http://api.jquery.com/one/) - Does not support namespaces or selectors * - [`parent()`](http://api.jquery.com/parent/) - Does not support selectors * - [`prepend()`](http://api.jquery.com/prepend/) * - [`prop()`](http://api.jquery.com/prop/) @@ -744,6 +745,19 @@ forEach({ off: jqLiteOff, + one: function(element, type, fn) { + element = jqLite(element); + + //add the listener twice so that when it is called + //you can remove the original function and still be + //able to call element.off(ev, fn) normally + element.on(type, function onFn() { + element.off(type, fn); + element.off(type, onFn); + }); + element.on(type, fn); + }, + replaceWith: function(element, replaceNode) { var index, parent = element.parentNode; jqLiteDealoc(element); -- cgit v1.2.3