Skip to content

Commit 28cb82e

Browse files
committed
Add option to execute callback only once
1 parent f7bbe04 commit 28cb82e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Countable.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* elements.
55
*
66
* @author Sacha Schmid (<https://github.com/RadLikeWhoa>)
7-
* @version 1.4.0
7+
* @version 1.4.1
88
* @license MIT
99
* @see <http://radlikewhoa.github.io/Countable/>
1010
*/
@@ -39,10 +39,12 @@
3939
* the result. The callback should
4040
* accept only one parameter. (default:
4141
* logs to console)
42-
* @param {Boolean} [options] hardReturns: Use two line breaks
42+
* @param {Object} [options] hardReturns: Use two line breaks
4343
* instead of one.
4444
* stripTags: Strip HTML tags before
4545
* counting.
46+
* once: Execute the callback only once
47+
* and don't bind any events.
4648
*
4749
* @example new Countable(elem, function (counter) {
4850
* alert(counter.words)
@@ -81,7 +83,8 @@
8183

8284
self.options = {
8385
hardReturns: false,
84-
stripTags: false
86+
stripTags: false,
87+
once: false
8588
}
8689

8790
/**
@@ -103,6 +106,8 @@
103106

104107
self.callback(self.count())
105108

109+
if (self.options.once) return
110+
106111
if (element.addEventListener) {
107112
element.addEventListener((hasInput ? 'input' : 'keydown'), function () {
108113
self.callback(self.count())

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Countable",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"main": "Countable.js",
55
"ignore": [ "CONTRIBUTING.md" ]
66
}

0 commit comments

Comments
 (0)