summaryrefslogtreecommitdiffstats
path: root/jquery.once.js
diff options
context:
space:
mode:
authorThéodore Biadala <theodore@biadala.net>2014-01-29 14:20:02 +0100
committerThéodore Biadala <theodore@biadala.net>2014-01-29 14:20:02 +0100
commit2b719c62f2a7132252008691a58787c4e44951a5 (patch)
treef4ef6170cb0733e73189ddb0ba61740be27297c9 /jquery.once.js
parentac1fd448edf1efa9c0abbc14d9c8642952498a19 (diff)
downloadjquery-once-2b719c62f2a7132252008691a58787c4e44951a5.zip
jquery-once-2b719c62f2a7132252008691a58787c4e44951a5.tar.gz
jquery-once-2b719c62f2a7132252008691a58787c4e44951a5.tar.bz2
Use data-jquery-once attribute instead of class
Diffstat (limited to 'jquery.once.js')
-rw-r--r--jquery.once.js30
1 files changed, 25 insertions, 5 deletions
diff --git a/jquery.once.js b/jquery.once.js
index 4117dbf..71e9268 100644
--- a/jquery.once.js
+++ b/jquery.once.js
@@ -59,9 +59,18 @@
}
id = 'jquery-once-' + cache[id];
}
- // Remove elements from the set that have already been processed.
- var name = id + '-processed';
- var elements = this.not('.' + name).addClass(name);
+
+ /**
+ * 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);
return $.isFunction(fn) ? elements.each(fn) : elements;
};
@@ -84,8 +93,19 @@
* @api public
*/
$.fn.removeOnce = function (id, fn) {
- var name = id + '-processed';
- var elements = this.filter('.' + name).removeClass(name);
+ /**
+ * 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);
return $.isFunction(fn) ? elements.each(fn) : elements;
};