-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.SimpleMaxChars.min.js
1 lines (1 loc) · 1.22 KB
/
jquery.SimpleMaxChars.min.js
1
!function(a){function e(a){0===a.length&&alert("No matching form fields were found.")}a.fn.SimpleMaxChars=function(n){var s=a.extend({},a.fn.SimpleMaxChars.defaults,n);return s.debug===!0&&e(this,s),this.each(function(){var e=a(this),n=a("."+s.messageClass).length;n++,e.after('<span id="'+s.messageClass+"-"+n+'"></span>');var r=a("#"+s.messageClass+"-"+n),i=s.maxChars;"undefined"==typeof i?"undefined"==typeof e.attr("maxlength")||""===e.attr("maxlength")?(i=s.defaultMaxChars,e.prop("maxLength",i)):(i=e.prop("maxLength"),"undefined"==typeof i&&(i=e.attr("maxlength"))):e.prop("maxLength",i);var t=e.val(),m=t.length,l=a.fn.SimpleMaxChars.message(m,s,i);r.html(l),e.keyup(function(){t=e.val(),m=t.length,l=a.fn.SimpleMaxChars.message(m,s,i),r.html(l)})})},a.fn.SimpleMaxChars.message=function(a,e,n){var s=n-a,r="",i="",t=e.messageClass,m=e.remainingMessage.replace("__remaining_chars__",s);return e.lineBreak===!0&&(r="<br />"),s<e.warningLimit&&(t+=" "+e.warningClass),i=r+'<span class="'+t+'">'+m+"</span>"},a.fn.SimpleMaxChars.defaults={maxChars:void 0,defaultMaxChars:255,warningLimit:20,messageClass:"simple-maxchars-message",warningClass:"warning",remainingMessage:"__remaining_chars__ characters remaining.",lineBreak:!1,debug:!1}}(jQuery);