summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Loach <robloach@gmail.com>2014-10-07 15:04:46 -0400
committerRob Loach <robloach@gmail.com>2014-10-07 15:04:46 -0400
commitefd469b968b6ecf7c3782728aee892e8bb8024d4 (patch)
tree21cc9ad43d3334edbecfd4246715fa3416ed93c2
parent4c862ae108fc69e17495f4169400ba9f41439228 (diff)
downloadjquery-once-efd469b968b6ecf7c3782728aee892e8bb8024d4.zip
jquery-once-efd469b968b6ecf7c3782728aee892e8bb8024d4.tar.gz
jquery-once-efd469b968b6ecf7c3782728aee892e8bb8024d4.tar.bz2
Switch to Literate CoffeeScript
-rw-r--r--.editorconfig7
-rw-r--r--jquery.once.js157
-rw-r--r--jquery.once.litcoffee97
3 files changed, 139 insertions, 122 deletions
diff --git a/.editorconfig b/.editorconfig
index 6818143..0334399 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -5,9 +5,10 @@ root = true
[*]
end_of_line = lf
charset = utf-8
-trim_trailing_whitespace = false
-insert_final_newline = false
-indent_style = tab
+trim_trailing_whitespace = true
+insert_final_newline = true
+indent_style = space
+indent_size = 2
[*.json]
indent_style = space
diff --git a/jquery.once.js b/jquery.once.js
index 054ceb4..dd825f4 100644
--- a/jquery.once.js
+++ b/jquery.once.js
@@ -1,121 +1,40 @@
-/*!
- * @file jQuery Once
- * @description Act on jQuery elements only once.
- * @version 2.0.0-alpha.6
- * @link http://github.com/robloach/jquery-once
- * @author Rob Loach (http://robloach.net)
- * @license MIT, GPL-2.0
- */
-
-(function (factory) {
- "use strict";
- if (typeof exports === 'object') {
- factory(require('jquery'));
- } else if (typeof define === 'function' && define.amd) {
- define(['jquery'], factory);
- } else {
- factory(jQuery);
- }
-}(function ($) {
- "use strict";
- var cache = {}, uuid = 0;
-
- /**
- * Filter elements by whether they have not yet been processed.
- *
- * @param {string} [id]
- * (Optional) The data id used to determine whether the given elements have
- * already been processed or not.
- *
- * When id is not provided, it becomes a unique identifier, depicted as a
- * number. The element's data id will then be represented in the form of
- * "jquery-once-#".
- * @returns jQuery element collection of elements that have now run once by
- * the given id.
- *
- * @example
- * // Change the color to green only once.
- * $('p').once('changecolor').css('color', 'green');
- *
- * @see removeOnce
- * @see findOnce
- *
- * @public
- * @global
- */
- $.fn.once = function (id) {
- if (typeof id !== 'string') {
- // Generate a numeric ID if the id passed is not a string.
- if (!(id in cache)) {
- cache[id] = ++uuid;
- }
- id = cache[id];
+// Generated by CoffeeScript 1.8.0
+(function() {
+ (function(factory) {
+ if (typeof exports === "object") {
+ factory(require("jquery"));
+ } else if (typeof define === "function" && define.amd) {
+ define(["jquery"], factory);
+ } else {
+ factory(jQuery);
}
+ })(function($) {
+ var cache, uuid;
+ cache = {};
+ uuid = 0;
+ $.fn.once = function(id) {
+ var name;
+ if (typeof id !== "string") {
+ if (!(id in cache)) {
+ cache[id] = ++uuid;
+ }
+ id = cache[id];
+ }
+ name = "jquery-once-" + id;
+ return this.filter(function() {
+ return $(this).data(name) !== true;
+ }).data(name, true);
+ };
+ $.fn.removeOnce = function(id) {
+ return this.findOnce(id).removeData("jquery-once-" + id);
+ };
+ $.fn.findOnce = function(id) {
+ var name;
+ name = "jquery-once-" + id;
+ return this.filter(function() {
+ return $(this).data(name) === true;
+ });
+ };
+ });
- // Filter the elements by which do not have the data yet.
- var name = 'jquery-once-' + id;
-
- return this.filter(function() {
- return $(this).data(name) !== true;
- }).data(name, true);
- };
-
- /**
- * Removes the once data from the given elements, based on the given ID.
- *
- * @param {string} id
- * 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.
- *
- * @returns jQuery element collection of elements that now have their once
- * data removed.
- *
- * @example
- * // Remove once data with the "changecolor" ID.
- * $('p').removeOnce('changecolor').each(function() {
- * // This function is called for all elements that had their once removed.
- * });
- *
- * @see once
- *
- * @public
- * @global
- */
- $.fn.removeOnce = function (id) {
- // Filter through the elements to find the once'd elements.
- return this.findOnce(id).removeData('jquery-once-' + id);
- };
-
- /**
- * Filters elements that have already been processed once.
- *
- * @param {string} id
- * 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.
- *
- * @returns jQuery element collection of elements that have been run once.
- *
- * @example
- * // Find all elements that have the changecolor'ed once.
- * $('p').findOnce('changecolor').each(function() {
- * // This function is called for all elements that has already once'd.
- * });
- *
- * @see once
- *
- * @public
- * @global
- */
- $.fn.findOnce = function (id) {
- // Filter the elements by which do have the data.
- var name = 'jquery-once-' + id;
-
- return this.filter(function() {
- return $(this).data(name) === true;
- });
- };
-}));
+}).call(this);
diff --git a/jquery.once.litcoffee b/jquery.once.litcoffee
new file mode 100644
index 0000000..27f4928
--- /dev/null
+++ b/jquery.once.litcoffee
@@ -0,0 +1,97 @@
+# [jQuery Once](http://github.com/robloach/jquery-once) `2.0.0-alpha.6`
+
+Act on jQuery elements only once.
+
+
+## Usage
+
+### Universal Module Definition
+
+[jQuery](http://jquery.com) is a dependency, so we wrap the code with a
+[UMD](https://github.com/umdjs/umd) pattern in order to allow loading jQuery,
+and jQuery Once, in a number of different ways.
+
+ ((factory) ->
+ if typeof exports is "object"
+ factory require("jquery")
+ else if typeof define is "function" and define.amd
+ define ["jquery"], factory
+ else
+ factory jQuery
+ return
+ ) ($) ->
+ cache = {}
+ uuid = 0
+
+
+### `.once()`
+
+Filter elements by whether they have not yet been processed.
+
+#### Parameters
+
+* `id` *(string)* The optional data id used to determine whether the given
+elements have already been processed or not. When id is not provided, it becomes a unique identifier, depicted as a
+number. The element's data id will then be represented in the form of
+`jquery-once-#`.
+
+#### Returns
+
+jQuery element collection of elements that have now run once by
+the given id.
+
+ $.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]
+ # Filter the elements by which do not have the data yet.
+ name = "jquery-once-" + id
+ @filter(->
+ $(this).data(name) isnt true
+ ).data name, true
+
+
+### `.removeOnce()`
+
+Removes the once data from the given elements, based on the given ID.
+
+#### Parameters
+
+* `id` *string* 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.
+
+#### Returns
+
+jQuery element collection of elements that now have their once
+data removed.
+
+ $.fn.removeOnce = (id) ->
+ # Filter through the elements to find the once'd elements.
+ @findOnce(id).removeData "jquery-once-" + id
+
+
+### `.findOnce()`
+
+Filters elements that have already been processed once.
+
+#### Parameters
+
+* `id` *string* 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.
+
+#### Returns
+
+jQuery element collection of elements that have been run once.
+
+ $.fn.findOnce = (id) ->
+ # Filter the elements by which do have the data.
+ name = "jquery-once-" + id
+ @filter ->
+ $(this).data(name) is true
+
+ return