diff --git a/README.md b/README.md
index 45ca221..998a40f 100644
--- a/README.md
+++ b/README.md
@@ -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
@@ -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
\ No newline at end of file
+- [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
\ No newline at end of file
diff --git a/textcounter.js b/textcounter.js
index 4078a3d..25addc6 100644
--- a/textcounter.js
+++ b/textcounter.js
@@ -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) {
@@ -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
diff --git a/textcounter.min.js b/textcounter.min.js
index ad6f19f..033a9b2 100644
--- a/textcounter.min.js
+++ b/textcounter.min.js
@@ -1,8 +1,8 @@
-/*!
-* jQuery Text Counter Plugin v0.7.0
-* https://github.com/ractoon/jQuery-Text-Counter
-*
-* Copyright 2014 ractoon
-* Released under the MIT license
-*/
-!function(t){t.textcounter=function(n,o){var e=this;e.$el=t(n),e.el=n,e.$el.data("textcounter",e),e.init=function(){e.options=t.extend({},t.textcounter.defaultOptions,o);var n=e.options.countDown?e.options.countDownText:e.options.counterText,r=e.options.countDown?e.options.max:0,s=t("
").addClass(e.options.textCountMessageClass).html(n.replace("%d",''+r+"")),i=t("").addClass(e.options.countOverflowContainerClass);e.hideMessage(i),e.$container=t("<"+e.options.countContainerElement+"/>").addClass(e.options.countContainerClass).append(s).append(i),e.$text_counter=e.$container.find("span"),e.$el.after(e.$container),e.$el.bind("keyup.textcounter click.textcounter blur.textcounter focus.textcounter change.textcounter paste.textcounter",e.checkLimits).trigger("click.textcounter"),e.options.init(e.el)},e.checkLimits=function(n){var o=e.$el,r=(e.$container,o.val()),s=0,i=0,a=void 0!==n.originalEvent;if(t.isEmptyObject(r)||(s=e.textCount(r)),"auto"==e.options.max){var u=e.$el.attr("maxlength");void 0!==u&&!1!==u?e.options.max=u:e.$container.text("error: [maxlength] attribute not set")}if(i=e.options.countDown?e.options.max-s:s,e.setCount(i),e.options.min>0&&a&&(s=e.options.min&&(e.options.mincount(e.el),e.clearErrors("min"))),-1!==e.options.max)if(s===e.options.max&&0!==e.options.max)e.options.maxcount(e.el),e.clearErrors("max");else if(s>e.options.max&&0!==e.options.max)if(e.options.stopInputAtMaximum){var c="";if("word"==e.options.type)for(var l=r.split(/[^\S\n]/g),p=0;p=e.options.max);)void 0!==l[p]&&(c+=l[p]+" ",p++);else{var x=e.options.twoCharCarriageReturn?e.options.max-e.twoCharCarriageReturnCount(r):e.options.max;if(e.options.countSpaces)c=r.substring(0,x);else for(var m=r.split(""),C=m.length,d=0,p=0;d'+r+""+e.options.errorTextElement+">"))},e.setOverflowMessage=function(){e.hideMessage(e.$container.find("."+e.options.textCountMessageClass)),e.removeOverflowMessage();var t=e.options.countOverflowText.replace("%d",e.textCount(e.$el.val())-e.options.max).replace("%type",e.options.type+"s"),n=e.$container.find("."+e.options.countOverflowContainerClass).append(t);e.showMessage(n)},e.removeOverflowMessage=function(){e.$container.find("."+e.options.countOverflowContainerClass).empty()},e.showMessage=function(t){t.css("display","inline")},e.hideMessage=function(t){t.css("display","none")},e.clearErrors=function(t){var n=e.$el,o=e.$container;o.children(".error-text-"+t).remove(),0==o.children(".error-text").length&&(e.removeOverflowMessage(),e.showMessage(e.$container.find("."+e.options.textCountMessageClass)),n.removeClass(e.options.inputErrorClass),o.removeClass(e.options.counterErrorClass))},e.init()},t.textcounter.defaultOptions={type:"character",min:0,max:200,countContainerElement:"div",countContainerClass:"text-count-wrapper",textCountMessageClass:"text-count-message",textCountClass:"text-count",inputErrorClass:"error",counterErrorClass:"error",counterText:"Total Count: %d",errorTextElement:"div",minimumErrorText:"Minimum not met",maximumErrorText:"Maximum exceeded",displayErrorText:!0,stopInputAtMaximum:!0,countSpaces:!1,countDown:!1,countDownText:"Remaining: %d",countExtendedCharacters:!1,twoCharCarriageReturn:!1,countOverflow:!1,countOverflowText:"Maximum %type exceeded by %d",countOverflowContainerClass:"text-count-overflow-wrapper",maxunder:function(t){},minunder:function(t){},maxcount:function(t){},mincount:function(t){},init:function(t){}},t.fn.textcounter=function(n){return this.each(function(){new t.textcounter(this,n)})}}(jQuery);
\ No newline at end of file
+/*!
+* jQuery Text Counter Plugin v0.7.0
+* https://github.com/ractoon/jQuery-Text-Counter
+*
+* Copyright 2014 ractoon
+* Released under the MIT license
+*/
+!function(t){t.textcounter=function(o,n){var e=this;e.$el=t(o),e.el=o,e.$el.data("textcounter",e),e.init=function(){e.options=t.extend({},t.textcounter.defaultOptions,n);var o=e.options.countDown?e.options.countDownText:e.options.counterText,r=e.options.countDown?e.options.max:0,s=t("").addClass(e.options.textCountMessageClass).html(o.replace("%d",''+r+"")),i=t("").addClass(e.options.countOverflowContainerClass);e.hideMessage(i),e.$container=t("<"+e.options.countContainerElement+"/>").addClass(e.options.countContainerClass).append(s).append(i),e.$text_counter=e.$container.find("span"),e.$el.after(e.$container),e.$el.bind("keyup.textcounter click.textcounter blur.textcounter focus.textcounter change.textcounter paste.textcounter",e.checkLimits).trigger("click.textcounter"),e.options.init(e.el)},e.checkLimits=function(o){var n=e.$el,r=(e.$container,n.val()),s=0,i=0,a=void 0!==o.originalEvent;if(t.isEmptyObject(r)||(s=e.textCount(r)),"auto"==e.options.max){var u=e.$el.attr("maxlength");void 0!==u&&!1!==u?e.options.max=u:e.$container.text("error: [maxlength] attribute not set")}if(i=e.options.countDown?e.options.max-s:s,e.setCount(i),e.options.min>0&&a&&(s=e.options.min&&(e.options.mincount(e.el),e.clearErrors("min"))),-1!==e.options.max)if(s===e.options.max&&0!==e.options.max)e.options.maxcount(e.el),e.clearErrors("max");else if(s>e.options.max&&0!==e.options.max)if(e.options.stopInputAtMaximum){var c="";if("word"==e.options.type)for(var l=r.split(/[^\S\n]/g),p=0;p=e.options.max);)void 0!==l[p]&&(c+=l[p]+" ",p++);else{var x=e.options.twoCharCarriageReturn?e.options.max-e.twoCharCarriageReturnCount(r):e.options.max;if(e.options.countSpaces)c=r.substring(0,x);else for(var m=r.split(""),C=m.length,f=0,p=0;f=e.options.max-e.options.maxDisplayCutoff?e.$container.show():e.$container.hide()},e.textCount=function(t){return"word"==e.options.type?e.wordCount(t):e.characterCount(t)},e.wordCount=function(t){return t.trim().replace(/\s+/gi," ").split(" ").length},e.characterCount=function(t){var o=0,n=0;if(e.options.twoCharCarriageReturn&&(n=e.twoCharCarriageReturnCount(t)),o=e.options.countSpaces?t.replace(/[^\S\n|\r|\r\n]/g," ").length:t.replace(/\s/g,"").length,e.options.countExtendedCharacters){var r=t.match(/[^\x00-\xff]/gi);o=null==r?t.length:t.length+r.length}return e.options.twoCharCarriageReturn&&(o+=n),o},e.twoCharCarriageReturnCount=function(t){var o=t.match(/(\r\n|\n|\r)/g),n=0;return null!==o&&(n=o.length),n},e.setCount=function(t){e.$text_counter.text(t)},e.setErrors=function(t){var o=e.$el,n=e.$container,r="";switch(o.addClass(e.options.inputErrorClass),n.addClass(e.options.counterErrorClass),t){case"min":r=e.options.minimumErrorText;break;case"max":r=e.options.maximumErrorText,e.options.countOverflow&&e.setOverflowMessage()}e.options.displayErrorText&&(n.children(".error-text-"+t).length||n.append("<"+e.options.errorTextElement+' class="error-text error-text-'+t+'">'+r+""+e.options.errorTextElement+">"))},e.setOverflowMessage=function(){e.hideMessage(e.$container.find("."+e.options.textCountMessageClass)),e.removeOverflowMessage();var t=e.options.countOverflowText.replace("%d",e.textCount(e.$el.val())-e.options.max).replace("%type",e.options.type+"s"),o=e.$container.find("."+e.options.countOverflowContainerClass).append(t);e.showMessage(o)},e.removeOverflowMessage=function(){e.$container.find("."+e.options.countOverflowContainerClass).empty()},e.showMessage=function(t){t.css("display","inline")},e.hideMessage=function(t){t.css("display","none")},e.clearErrors=function(t){var o=e.$el,n=e.$container;n.children(".error-text-"+t).remove(),0==n.children(".error-text").length&&(e.removeOverflowMessage(),e.showMessage(e.$container.find("."+e.options.textCountMessageClass)),o.removeClass(e.options.inputErrorClass),n.removeClass(e.options.counterErrorClass))},e.init()},t.textcounter.defaultOptions={type:"character",min:0,max:200,countContainerElement:"div",countContainerClass:"text-count-wrapper",textCountMessageClass:"text-count-message",textCountClass:"text-count",inputErrorClass:"error",counterErrorClass:"error",counterText:"Total Count: %d",errorTextElement:"div",minimumErrorText:"Minimum not met",maximumErrorText:"Maximum exceeded",displayErrorText:!0,stopInputAtMaximum:!0,countSpaces:!1,countDown:!1,countDownText:"Remaining: %d",countExtendedCharacters:!1,twoCharCarriageReturn:!1,countOverflow:!1,countOverflowText:"Maximum %type exceeded by %d",countOverflowContainerClass:"text-count-overflow-wrapper",minDisplayCutoff:-1,maxDisplayCutoff:-1,maxunder:function(t){},minunder:function(t){},maxcount:function(t){},mincount:function(t){},init:function(t){}},t.fn.textcounter=function(o){return this.each(function(){new t.textcounter(this,o)})}}(jQuery);
\ No newline at end of file