summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Loach <robloach@gmail.com>2014-10-07 15:22:27 -0400
committerRob Loach <robloach@gmail.com>2014-10-07 15:22:27 -0400
commit1984238124a32c2b979105e586a6e510c15bd8a9 (patch)
tree0b8ddce737c5fcbd79c481ff15ac92e39e76a6a1
parent4f85b53ac34a4fd2671c1a1dc55a12907edadf6e (diff)
downloadjquery-once-1984238124a32c2b979105e586a6e510c15bd8a9.zip
jquery-once-1984238124a32c2b979105e586a6e510c15bd8a9.tar.gz
jquery-once-1984238124a32c2b979105e586a6e510c15bd8a9.tar.bz2
Update documentation
-rw-r--r--.npmignore2
-rw-r--r--README.md58
-rw-r--r--jquery.once.litcoffee37
3 files changed, 36 insertions, 61 deletions
diff --git a/.npmignore b/.npmignore
index 6924651..d86b814 100644
--- a/.npmignore
+++ b/.npmignore
@@ -36,4 +36,4 @@ bower.json
# =====================================
# CUSTOM MODIFICATIONS
-# None
+*.litcoffee
diff --git a/README.md b/README.md
index 867ced2..28a5abe 100644
--- a/README.md
+++ b/README.md
@@ -24,10 +24,6 @@ Act on jQuery elements only once.
<!-- /DESCRIPTION -->
-Filters out all elements that had the same filter applied on them before. It can
-be used to ensure that a function is only applied once to an element.
-
-
<!-- INSTALL/ -->
## Install
@@ -58,57 +54,7 @@ be used to ensure that a function is only applied once to an element.
## Usage
-### `.once()`
-
-Filter elements by whether they have not yet been processed.
-
-``` javascript
-$('div.calendar').once('calendar').each(function() {
- // This function is only executed once for each div, even if this
- // code segment is executed repeatedly.
-});
-$('div.calendar').once('calendar').click(function() {
- // .once('calendar') filters out all elements which already have been
- // filtered with once(), and the elements that haven't been filtered
- // yet remain. The previous set of elements can be restored with
- // .end().
-});
-```
-
-It is also possible to use `.once()` without supplying a name:
-
-``` javascript
-$('div.calendar').once().each(function() {
- // This function is only executed once for each div, even if this
- // code segment is executed repeatedly. Other scripts can't refer
- // to this `once` method. The once data used to store execution are
- // in the form "jquery-once-1", "jquery-once-2", etc.
-});
-```
-
-### `.findOnce()`
-
-After `.once()` is used and you need to retrieve all elements that have already
-been executed with `.once()`, you can use the `.findOnce() function:
-
-``` javascript
-$('div.calendar').findOnce('calendar').each(function() {
- // This function is called for each element that was already called "once"
- // with the "calendar" ID.
-});
-```
-
-### `.removeOnce()`
-
-It is possible to remove the `.once()` data, and iterate through each element
-whose once state is removed:
-
-``` javascript
-$('div.calendar').removeOnce('calendar').each(function() {
- // This function is called for each element whose once() data is removed.
-});
-```
-
+[See the `jquery.once.litcoffee` for documentation.](jquery.once.litcoffee)
## Development
@@ -182,5 +128,3 @@ These amazing people have contributed code to this project:
[Become a contributor!](https://github.com/RobLoach/jquery-once/blob/master/CONTRIBUTING.md#files)
<!-- /BACKERS -->
-
-
diff --git a/jquery.once.litcoffee b/jquery.once.litcoffee
index c6b3601..2f8fedc 100644
--- a/jquery.once.litcoffee
+++ b/jquery.once.litcoffee
@@ -31,15 +31,24 @@ 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-#`.
+ 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
+
+``` javascript
+// Change the color of the text to green.
+$('p').once('changecolor').css('color', 'green');
+```
+
+#### Source
+
$.fn.once = (id) ->
if typeof id isnt "string"
# Generate a numeric ID if the id passed is not a string.
@@ -68,6 +77,17 @@ was originally passed to the once() function.
jQuery element collection of elements that now have their once
data removed.
+#### Example
+
+``` javascript
+// Remove the once
+$('p').removeOnce('changecolor').each(function() {
+ // This function is run for each element that had its once data removed.
+});
+```
+
+#### Source
+
$.fn.removeOnce = (id) ->
# Filter through the elements to find the once'd elements.
@findOnce(id).removeData "jquery-once-" + id
@@ -88,6 +108,17 @@ was originally passed to the `.once()` function.
jQuery element collection of elements that have been run once.
+#### Example
+
+``` javascript
+// Remove the once
+$('p').findOnce('changecolor').each(function() {
+ // This function is run for each element that has already been run once.
+});
+```
+
+#### Source
+
$.fn.findOnce = (id) ->
# Filter the elements by which do have the data.
name = "jquery-once-" + id