Skip to content

Commit 518ff2c

Browse files
committed
Merge #38
Merging conflicts, version update 0.8.0
2 parents 2b5cc2e + 3a88079 commit 518ff2c

File tree

6 files changed

+42
-13
lines changed

6 files changed

+42
-13
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ Fires when counter is under min limit.
111111
```javascript
112112
type : "character", // "character" or "word"
113113
min : 0, // minimum number of characters/words
114-
max : 200, // maximum number of characters/words, -1 for unlimited, 'auto' to use maxlength attribute
114+
max : 200, // maximum number of characters/words, -1 for unlimited, 'auto' to use maxlength attribute, , 'autocustom' to use a custom attribute for the length (must set "autoCustomAttr")
115+
autoCustomAttr : "counterlimit", // custom attribute name with the counter limit if the max is 'autocustom'
115116
countContainerElement : "div", // HTML element to wrap the text count in
116117
countContainerClass : "text-count-wrapper", // class applied to the countContainerElement
117118
textCountMessageClass : "text-count-message", // class applied to the counter message
@@ -132,10 +133,12 @@ twoCharCarriageReturn : false, // count carriage
132133
countOverflow : false, // display text overflow element
133134
countOverflowText : "Maximum %type exceeded by %d", // count overflow text
134135
countOverflowContainerClass : "text-count-overflow-wrapper", // class applied to the count overflow wrapper
136+
minDisplayCutoff : -1, // maximum number of characters/words above the minimum to display a count
137+
maxDisplayCutoff : -1, // maximum number of characters/words below the maximum to display a count
135138

136139
// Callback API
137-
maxunder : function(el){}, // Callback: function(element) - Fires when counter under max limit
138-
minunder : function(el){}, // Callback: function(element) - Fires when counter under min limit
140+
maxunder : function(el){}, // Callback: function(element) - Fires when counter is under max limit
141+
minunder : function(el){}, // Callback: function(element) - Fires when counter is under min limit
139142
maxcount : function(el){}, // Callback: function(element) - Fires when the counter hits the maximum word/character count
140143
mincount : function(el){}, // Callback: function(element) - Fires when the counter hits the minimum word/character count
141144
init : function(el){} // Callback: function(element) - Fires after the counter is initially setup
@@ -163,4 +166,6 @@ init : function(el){} // Callback: func
163166
- [juliovedovatto](https://github.com/juliovedovatto) / [alvaro-canepa](https://github.com/alvaro-canepa) - multiple classes support for counter container
164167
- [dtipson](https://github.com/dtipson) - multiple classes error fix
165168
- [jmichalicek](https://github.com/jmichalicek) - count carriage returns/newlines as 2 characters
166-
- [diptopol](https://github.com/diptopol) - `stopInputAtMaximum` with `twoCharCarriageReturn` count fix, trimmed newline calculation fix, maximum text reached condition fix, text count overflow notification
169+
- [diptopol](https://github.com/diptopol) - `stopInputAtMaximum` with `twoCharCarriageReturn` count fix, trimmed newline calculation fix, maximum text reached condition fix, text count overflow notification
170+
- [trevorloflin](https://github.com/trevorloflin) - `minDisplayCutoff` and `maxDisplayCutoff` options
171+
- [t3mujin](https://github.com/t3mujin) - autocustom support (maxlength workaround), text fixes

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-text-counter",
3-
"version": "0.7.0",
3+
"version": "0.8.0",
44
"main": "textcounter.js",
55
"license": "MIT",
66
"ignore": [

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
"minimum",
1212
"maximum"
1313
],
14-
"version": "0.7.0",
14+
"version": "0.8.0",
1515
"author": {
1616
"name": "ractoon",
17-
"url": "http://www.ractoon.com"
17+
"url": "https://www.ractoon.com"
1818
},
1919
"licenses": [
2020
{

textcounter.jquery.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
"minimum",
1010
"maximum"
1111
],
12-
"version": "0.7.0",
12+
"version": "0.8.0",
1313
"author": {
1414
"name": "ractoon",
15-
"url": "http://www.ractoon.com"
15+
"url": "https://www.ractoon.com"
1616
},
1717
"licenses": [
1818
{

textcounter.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* jQuery Text Counter Plugin v0.7.0
2+
* jQuery Text Counter Plugin v0.8.0
33
* https://github.com/ractoon/jQuery-Text-Counter
44
*
55
* Copyright 2014 ractoon
@@ -68,6 +68,16 @@
6868
base.$container.text('error: [maxlength] attribute not set');
6969
}
7070
}
71+
else if (base.options.max == 'autocustom') {
72+
var max = base.$el.attr(base.options.autoCustomAttr);
73+
74+
if (typeof max !== 'undefined' && max !== false) {
75+
base.options.max = max;
76+
}
77+
else {
78+
base.$container.text('error: [' + base.options.autoCustomAttr + '] attribute not set');
79+
}
80+
}
7181

7282
// if this is a countdown counter deduct from the max characters/words
7383
textTotalCount = base.options.countDown ? base.options.max - textCount : textCount;
@@ -151,6 +161,17 @@
151161
base.clearErrors('max');
152162
}
153163
}
164+
165+
// hide the counter if it doesn't meet either the minimum or maximum display cutoff
166+
if (base.options.minDisplayCutoff == -1 && base.options.maxDisplayCutoff == -1) {
167+
base.$container.show();
168+
} else if (textCount <= base.options.min + base.options.minDisplayCutoff) {
169+
base.$container.show();
170+
} else if (base.options.max !== -1 && textCount >= base.options.max - base.options.maxDisplayCutoff) {
171+
base.$container.show();
172+
} else {
173+
base.$container.hide();
174+
}
154175
};
155176

156177
base.textCount = function(text) {
@@ -294,7 +315,8 @@
294315
$.textcounter.defaultOptions = {
295316
'type' : "character", // "character" or "word"
296317
'min' : 0, // minimum number of characters/words
297-
'max' : 200, // maximum number of characters/words, -1 for unlimited, 'auto' to use maxlength attribute
318+
'max' : 200, // maximum number of characters/words, -1 for unlimited, 'auto' to use maxlength attribute, 'autocustom' to use a custom attribute for the length (must set "autoCustomAttr")
319+
'autoCustomAttr' : "counterlimit", // custom attribute name with the counter limit if the max is 'autocustom'
298320
'countContainerElement' : "div", // HTML element to wrap the text count in
299321
'countContainerClass' : "text-count-wrapper", // class applied to the countContainerElement
300322
'textCountMessageClass' : "text-count-message", // class applied to the counter message
@@ -315,6 +337,8 @@
315337
'countOverflow' : false, // display text overflow element
316338
'countOverflowText' : "Maximum %type exceeded by %d", // count overflow text
317339
'countOverflowContainerClass' : "text-count-overflow-wrapper", // class applied to the count overflow wrapper
340+
'minDisplayCutoff' : -1, // maximum number of characters/words above the minimum to display a count
341+
'maxDisplayCutoff' : -1, // maximum number of characters/words below the maximum to display a count
318342

319343
// Callback API
320344
'maxunder' : function(el){}, // Callback: function(element) - Fires when counter under max limit

textcounter.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)