(function(a){a.fn.maxlength=function(c){function g(a){var b=a.value;c.words&&(b=a.value.length?b.split(/\s+/):{length:0});return b.length}"string"==typeof c&&(c={feedback:c});c=a.extend({},a.fn.maxlength.defaults,c);return this.each(function(){function k(b){var a=g(this);b=b.keyCode;if(a>=d)switch(b){case 8:case 9:case 17:case 36:case 35:case 37:case 38:case 39:case 40:case 46:case 65:break;default:return c.words&&32!=b&&13!=b&&a==d}}var b=this,f=a(b),h=a(b.form),d=c.useInput?h.find("input[name=maxlength]").val():
f.attr("maxlength"),l=h.find(c.feedback),e=function(){var a=g(b),a=d-a;l.html(a||"0");c.hardLimit&&0>a&&(b.value=c.words?b.value.split(/(\s+)/,2*d-1).join(""):b.value.substr(0,d),e())};f.keyup(e).change(e);c.hardLimit&&f.keydown(k);e()})};a.fn.maxlength.defaults={useInput:!1,hardLimit:!0,feedback:".charsLeft",words:!1}})(jQuery);
