summaryrefslogtreecommitdiffstats
path: root/jquery.once.js
diff options
context:
space:
mode:
authorRob Loach <robloach@gmail.com>2014-09-26 15:18:02 -0700
committerRob Loach <robloach@gmail.com>2014-09-26 15:18:02 -0700
commit8f09cc05ab25ac12b66088e4c84bb368884f0d52 (patch)
tree63c1ad55bd866de96337c43941c4e8a67fca22ec /jquery.once.js
parentac1fd448edf1efa9c0abbc14d9c8642952498a19 (diff)
parentc696fcfaffb0bbc02ad1407ff5baa6086f8ba510 (diff)
downloadjquery-once-8f09cc05ab25ac12b66088e4c84bb368884f0d52.zip
jquery-once-8f09cc05ab25ac12b66088e4c84bb368884f0d52.tar.gz
jquery-once-8f09cc05ab25ac12b66088e4c84bb368884f0d52.tar.bz2
Merge pull request #10 from RobLoach/next
Update to 2.0.0-alpha.1
Diffstat (limited to 'jquery.once.js')
-rw-r--r--jquery.once.js34
1 files changed, 18 insertions, 16 deletions
diff --git a/jquery.once.js b/jquery.once.js
index 4117dbf..5faa4c0 100644
--- a/jquery.once.js
+++ b/jquery.once.js
@@ -1,5 +1,5 @@
/**
- * jQuery Once Plugin 1.2.6
+ * jQuery Once Plugin 2.0.0-alpha.1
* http://github.com/robloach/jquery-once
*
* Dual licensed under the MIT and GPL licenses:
@@ -24,20 +24,16 @@
* Filters elements by whether they have not yet been processed.
*
* @param id
- * (Optional) If this is a string, then it will be used as the CSS class
- * name that is applied to the elements for determining whether it has
- * already been processed. The elements will get a class in the form of
- * "id-processed".
+ * (Optional) If this is a string, then it will be the data ID used
+ * to determine whether it has already been processed or not.
*
* If the id parameter is a function, it will be passed off to the fn
* parameter and the id will become a unique identifier, represented as a
* number.
*
* When the id is neither a string or a function, it becomes a unique
- * identifier, depicted as a number. The element's class will then be
- * represented in the form of "jquery-once-#-processed".
- *
- * Take note that the id must be valid for usage as an element's class name.
+ * identifier, depicted as a number. The element's data ID will then be
+ * represented in the form of "jquery-once-#".
* @param fn
* (Optional) If given, this function will be called for each element that
* has not yet been processed. The function's return value follows the same
@@ -57,11 +53,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;
};
@@ -70,7 +69,7 @@
* Filters elements that have been processed once already.
*
* @param id
- * A required string representing the name of the class which should be used
+ * A required string representing the name of the data id which should be used
* when filtering the elements. This only filters elements that have already
* been processed by the once function. The id should be the same id that
* was originally passed to the once() function.
@@ -84,8 +83,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;
};