Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ twoCharCarriageReturn : false, // count carriage
countOverflow : false, // display text overflow element
countOverflowText : "Maximum %type exceeded by %d", // count overflow text
countOverflowContainerClass : "text-count-overflow-wrapper", // class applied to the count overflow wrapper
minDisplayCutoff : -1, // maximum number of characters/words above the minimum to display a count
maxDisplayCutoff : -1, // maximum number of characters/words below the maximum to display a count

// Callback API
maxunder : function(el){}, // Callback: function(element) - Fires when counter under max limit
Expand Down Expand Up @@ -163,4 +165,5 @@ init : function(el){} // Callback: func
- [juliovedovatto](https://github.com/juliovedovatto) / [alvaro-canepa](https://github.com/alvaro-canepa) - multiple classes support for counter container
- [dtipson](https://github.com/dtipson) - multiple classes error fix
- [jmichalicek](https://github.com/jmichalicek) - count carriage returns/newlines as 2 characters
- [diptopol](https://github.com/diptopol) - `stopInputAtMaximum` with `twoCharCarriageReturn` count fix, trimmed newline calculation fix, maximum text reached condition fix, text count overflow notification
- [diptopol](https://github.com/diptopol) - `stopInputAtMaximum` with `twoCharCarriageReturn` count fix, trimmed newline calculation fix, maximum text reached condition fix, text count overflow notification
- [trevorloflin](https://github.com/trevorloflin) - `minDisplayCutoff` and `maxDisplayCutoff` options
13 changes: 13 additions & 0 deletions textcounter.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@
base.clearErrors('max');
}
}

// hide the counter if it doesn't meet either the minimum or maximum display cutoff
if (base.options.minDisplayCutoff == -1 && base.options.maxDisplayCutoff == -1) {
base.$container.show();
} else if (textCount <= base.options.min + base.options.minDisplayCutoff) {
base.$container.show();
} else if (base.options.max !== -1 && textCount >= base.options.max - base.options.maxDisplayCutoff) {
base.$container.show();
} else {
base.$container.hide();
}
};

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

// Callback API
'maxunder' : function(el){}, // Callback: function(element) - Fires when counter under max limit
Expand Down
16 changes: 8 additions & 8 deletions textcounter.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.