diff options
author | Rob Loach <robloach@gmail.com> | 2014-01-29 11:44:30 -0500 |
---|---|---|
committer | Rob Loach <robloach@gmail.com> | 2014-01-29 11:44:30 -0500 |
commit | 70664bbe119c8f3e1ff3ce56ae1412df8763a8ce (patch) | |
tree | 5b47035a28290246423ea59bdd41a24044c6b89b /jquery.once.js | |
parent | 2b719c62f2a7132252008691a58787c4e44951a5 (diff) | |
download | jquery-once-70664bbe119c8f3e1ff3ce56ae1412df8763a8ce.zip jquery-once-70664bbe119c8f3e1ff3ce56ae1412df8763a8ce.tar.gz jquery-once-70664bbe119c8f3e1ff3ce56ae1412df8763a8ce.tar.bz2 |
Fix to use data attributes rather than an array
Diffstat (limited to 'jquery.once.js')
-rw-r--r-- | jquery.once.js | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/jquery.once.js b/jquery.once.js index 71e9268..322d3f7 100644 --- a/jquery.once.js +++ b/jquery.once.js @@ -57,20 +57,14 @@ if (!fn) { fn = id; } - id = 'jquery-once-' + cache[id]; + id = cache[id]; } - /** - * Adds the ID at the end of attribute value. - */ - function addID (index, value) { - return $.trim((value || '') + ' ' + id); - } - - var elements = this - // Remove elements from the set that have already been processed. - .not('[data-jquery-once~="' + id + '"]') - .attr('data-jquery-once', addID); + // 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; }; @@ -93,19 +87,11 @@ * @api public */ $.fn.removeOnce = function (id, fn) { - /** - * Removes the ID from the attribute value. - */ - function removeID (index, value) { - return $.trim(value.replace(id, '')) - // Split and join to keep the value clean. - .split(/\s+/g) - .join(' '); - } - - var elements = this - .filter('[data-jquery-once~="' + id + '"]') - .attr('data-jquery-once', removeID); + // 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; }; |