diff options
author | Rob Loach <robloach@gmail.com> | 2014-09-26 15:02:14 -0700 |
---|---|---|
committer | Rob Loach <robloach@gmail.com> | 2014-09-26 15:02:14 -0700 |
commit | 6309f1bebeac39bf8536c7c5f41b7207b9b9c003 (patch) | |
tree | f2cf2173fe9d2c94b4968a73ca350f9ebbfe1dab /jquery.once.js | |
parent | 43d9dafe8bebb6e449f31db207b1fdb131ce82b1 (diff) | |
parent | 9279130917769cbade87c8d0e022bbea3f028194 (diff) | |
download | jquery-once-6309f1bebeac39bf8536c7c5f41b7207b9b9c003.zip jquery-once-6309f1bebeac39bf8536c7c5f41b7207b9b9c003.tar.gz jquery-once-6309f1bebeac39bf8536c7c5f41b7207b9b9c003.tar.bz2 |
Merge pull request #9 from RobLoach/remove-array
Move to data modal for 2.x
Diffstat (limited to 'jquery.once.js')
-rw-r--r-- | jquery.once.js | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/jquery.once.js b/jquery.once.js index b337c61..5784746 100644 --- a/jquery.once.js +++ b/jquery.once.js @@ -57,11 +57,14 @@ if (!fn) { fn = id; } - id = 'jquery-once-' + cache[id]; + id = cache[id]; } - // Remove elements from the set that have already been processed. - var name = id + '-processed'; - var elements = this.not('.' + name).addClass(name); + + // Filter the elements by which do not have the data yet. + var name = 'jquery-once-' + id; + var elements = this.filter(function() { + return $(this).data(name) !== true; + }).data(name, true); return $.isFunction(fn) ? elements.each(fn) : elements; }; @@ -84,8 +87,11 @@ * @api public */ $.fn.removeOnce = function (id, fn) { - var name = id + '-processed'; - var elements = this.filter('.' + name).removeClass(name); + // Filter the elements by which do have the data. + var name = 'jquery-once-' + id; + var elements = this.filter(function() { + return $(this).data(name) === true; + }).removeData(name); return $.isFunction(fn) ? elements.each(fn) : elements; }; |