Skip to content

Commit b48d136

Browse files
author
trevorloflin
committed
Added display cutoffs.
1 parent 2b5cc2e commit b48d136

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
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

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)