Skip to content

Commit

Permalink
Add option to execute callback only once
Browse files Browse the repository at this point in the history
  • Loading branch information
RadLikeWhoa committed May 22, 2013
1 parent f7bbe04 commit 28cb82e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions Countable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* elements.
*
* @author Sacha Schmid (<https://github.com/RadLikeWhoa>)
* @version 1.4.0
* @version 1.4.1
* @license MIT
* @see <http://radlikewhoa.github.io/Countable/>
*/
Expand Down Expand Up @@ -39,10 +39,12 @@
* the result. The callback should
* accept only one parameter. (default:
* logs to console)
* @param {Boolean} [options] hardReturns: Use two line breaks
* @param {Object} [options] hardReturns: Use two line breaks
* instead of one.
* stripTags: Strip HTML tags before
* counting.
* once: Execute the callback only once
* and don't bind any events.
*
* @example new Countable(elem, function (counter) {
* alert(counter.words)
Expand Down Expand Up @@ -81,7 +83,8 @@

self.options = {
hardReturns: false,
stripTags: false
stripTags: false,
once: false
}

/**
Expand All @@ -103,6 +106,8 @@

self.callback(self.count())

if (self.options.once) return

if (element.addEventListener) {
element.addEventListener((hasInput ? 'input' : 'keydown'), function () {
self.callback(self.count())
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Countable",
"version": "1.4.0",
"version": "1.4.1",
"main": "Countable.js",
"ignore": [ "CONTRIBUTING.md" ]
}

0 comments on commit 28cb82e

Please sign in to comment.