diff options
author | Rob Loach <robloach@gmail.com> | 2014-10-07 15:41:55 -0400 |
---|---|---|
committer | Rob Loach <robloach@gmail.com> | 2014-10-07 15:41:55 -0400 |
commit | 8488a8c2c1f2cedfd213b20ad46e1044e391c9d3 (patch) | |
tree | 7acd00cb9f6d6205cc8848f34a6be500d378ccce | |
parent | 1984238124a32c2b979105e586a6e510c15bd8a9 (diff) | |
download | jquery-once-8488a8c2c1f2cedfd213b20ad46e1044e391c9d3.zip jquery-once-8488a8c2c1f2cedfd213b20ad46e1044e391c9d3.tar.gz jquery-once-8488a8c2c1f2cedfd213b20ad46e1044e391c9d3.tar.bz2 |
Remove cache variable
-rw-r--r-- | jquery.once.js | 10 | ||||
-rw-r--r-- | jquery.once.litcoffee | 11 |
2 files changed, 7 insertions, 14 deletions
diff --git a/jquery.once.js b/jquery.once.js index dd825f4..affaaed 100644 --- a/jquery.once.js +++ b/jquery.once.js @@ -9,16 +9,12 @@ factory(jQuery); } })(function($) { - var cache, uuid; - cache = {}; + var uuid; uuid = 0; $.fn.once = function(id) { var name; - if (typeof id !== "string") { - if (!(id in cache)) { - cache[id] = ++uuid; - } - id = cache[id]; + if (!id) { + id = ++uuid; } name = "jquery-once-" + id; return this.filter(function() { diff --git a/jquery.once.litcoffee b/jquery.once.litcoffee index 2f8fedc..0f0f237 100644 --- a/jquery.once.litcoffee +++ b/jquery.once.litcoffee @@ -20,7 +20,6 @@ and jQuery Once, in a number of different ways. factory jQuery return ) ($) -> - cache = {} uuid = 0 @@ -50,15 +49,13 @@ $('p').once('changecolor').css('color', 'green'); #### Source $.fn.once = (id) -> - if typeof id isnt "string" - # Generate a numeric ID if the id passed is not a string. - cache[id] = ++uuid unless id of cache - id = cache[id] + # Generate a numeric id if the id doesn't exist. + id = ++uuid if !id # Filter the elements by which do not have the data yet. name = "jquery-once-" + id - @filter(-> + @filter -> $(this).data(name) isnt true - ).data name, true + .data name, true ### `.removeOnce()` |