-
Notifications
You must be signed in to change notification settings - Fork 31
/
jquery.charactercounter.min.js
1 lines (1 loc) · 1.33 KB
/
jquery.charactercounter.min.js
1
!function(e){e.fn.characterCounter=function(t){function n(e){var t,n="";for(t in e)n+=" "+t+'="'+e[t]+'"';return n}function r(){var e=i.counterCssClass;return i.customFields.class&&(e+=" "+i.customFields.class,delete i.customFields.class),"<"+i.counterWrapper+n(i.customFields)+' class="'+e+'"></'+i.counterWrapper+">"}function c(e){var t=i.counterFormat.replace(/%1/,e);return i.renderTotal&&(t+="/"+i.limit),t}function s(t){var n=e(t).val().length;i.countNewLineChars&&(n+=e(t).val().split(/\r*\n/).length);var r=i.counterSelector?e(i.counterSelector):e(t).nextAll("."+i.counterCssClass).first(),s=i.limit-n,o=s<0;i.increaseCounting&&(o=(s=n)>i.limit),o?(r.addClass(i.counterExceededCssClass),i.exceeded=!0,i.onExceed(n)):i.exceeded&&(r.removeClass(i.counterExceededCssClass),i.onDeceed(n),i.exceeded=!1),r.html(c(s))}function o(t){e(t).on("input change",function(){s(t)})}var a={exceeded:!1,counterSelector:!1,countNewLineChars:!1,limit:150,renderTotal:!1,counterWrapper:"span",counterCssClass:"counter",counterFormat:"%1",counterExceededCssClass:"exceeded",increaseCounting:!1,onExceed:function(e){},onDeceed:function(e){},customFields:{}},i=e.extend(a,t);return this.each(function(){var t=e(this).attr("maxlength");void 0!==t&&!1!==t&&e.extend(a,{limit:parseInt(e(this).attr("maxlength"))}),i.counterSelector||e(this).after(r()),o(this),s(this)})}}(jQuery);