Skip to content

Commit 953eafd

Browse files
authored
Merge pull request #37 from trevorloflin/trevorloflin-feature/count-display-limits
Added display cutoffs
2 parents 2b5cc2e + abc2085 commit 953eafd

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ twoCharCarriageReturn : false, // count carriage
132132
countOverflow : false, // display text overflow element
133133
countOverflowText : "Maximum %type exceeded by %d", // count overflow text
134134
countOverflowContainerClass : "text-count-overflow-wrapper", // class applied to the count overflow wrapper
135+
minDisplayCutoff : -1, // maximum number of characters/words above the minimum to display a count
136+
maxDisplayCutoff : -1, // maximum number of characters/words below the maximum to display a count
135137

136138
// Callback API
137139
maxunder : function(el){}, // Callback: function(element) - Fires when counter under max limit
@@ -163,4 +165,5 @@ init : function(el){} // Callback: func
163165
- [juliovedovatto](https://github.com/juliovedovatto) / [alvaro-canepa](https://github.com/alvaro-canepa) - multiple classes support for counter container
164166
- [dtipson](https://github.com/dtipson) - multiple classes error fix
165167
- [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
168+
- [diptopol](https://github.com/diptopol) - `stopInputAtMaximum` with `twoCharCarriageReturn` count fix, trimmed newline calculation fix, maximum text reached condition fix, text count overflow notification
169+
- [trevorloflin](https://github.com/trevorloflin) - `minDisplayCutoff` and `maxDisplayCutoff` options

textcounter.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@
151151
base.clearErrors('max');
152152
}
153153
}
154+
155+
// hide the counter if it doesn't meet either the minimum or maximum display cutoff
156+
if (base.options.minDisplayCutoff == -1 && base.options.maxDisplayCutoff == -1) {
157+
base.$container.show();
158+
} else if (textCount <= base.options.min + base.options.minDisplayCutoff) {
159+
base.$container.show();
160+
} else if (base.options.max !== -1 && textCount >= base.options.max - base.options.maxDisplayCutoff) {
161+
base.$container.show();
162+
} else {
163+
base.$container.hide();
164+
}
154165
};
155166

156167
base.textCount = function(text) {
@@ -315,6 +326,8 @@
315326
'countOverflow' : false, // display text overflow element
316327
'countOverflowText' : "Maximum %type exceeded by %d", // count overflow text
317328
'countOverflowContainerClass' : "text-count-overflow-wrapper", // class applied to the count overflow wrapper
329+
'minDisplayCutoff' : -1, // maximum number of characters/words above the minimum to display a count
330+
'maxDisplayCutoff' : -1, // maximum number of characters/words below the maximum to display a count
318331

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

textcounter.min.js

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

0 commit comments

Comments
 (0)