/* ========================================================== * bootstrap-maxlength.js v1.3.7 * * Copyright (c) 2013 Maurizio Napoleoni; * * Licensed under the terms of the MIT license. * See: https://github.com/mimo84/bootstrap-maxlength/blob/master/LICENSE * ========================================================== */ (function(h){h.fn.extend({maxlength:function(d,l){function m(b){var c=b.val().match(/\n/g),c=c?c.length:0;return b.val().length+c}function k(b,c){return c-m(b)}function n(b,c){var a="";d.preText&&(a+=d.preText);a=a+c+d.separator+b;d.postText&&(a+=d.postText);return a}function p(b,c,a,e){e.html(n(a,b));if(0b&&(f=!1);f?e.removeClass(d.limitReachedClass).addClass(d.warningClass).css({display:"block"}):e.css({display:"none"})}else e.removeClass(d.warningClass).addClass(d.limitReachedClass).css({display:"block"})} function q(b,c){var a;a=b[0];a=h.extend({},"function"===typeof a.getBoundingClientRect?a.getBoundingClientRect():{width:a.offsetWidth,height:a.offsetHeight},b.offset());var e=b.outerWidth(),f=c.outerWidth(),g=c.width(),j=c.height();switch(d.placement){case "bottom":c.css({top:a.top+a.height,left:a.left+a.width/2-g/2});break;case "top":c.css({top:a.top-j,left:a.left+a.width/2-g/2});break;case "left":c.css({top:a.top+a.height/2-j/2,left:a.left-g});break;case "right":c.css({top:a.top+a.height/2-j/2, left:a.left+a.width});break;case "bottom-right":c.css({top:a.top+a.height,left:a.left+a.width});break;case "top-right":c.css({top:a.top-j,left:a.left+e});break;case "top-left":c.css({top:a.top-j,left:a.left-f});break;case "bottom-left":c.css({top:a.top+b.outerHeight(),left:a.left-f});break;case "centered-right":c.css({top:a.top+j/2,left:a.left+e-f-3})}}function g(b){return b.attr("maxlength")||b.attr("size")}var r=h("body");h.isFunction(d)&&!l&&(l=d,d={});d=h.extend({alwaysShow:!1,threshold:10,warningClass:"badge badge-success", limitReachedClass:"badge badge-important",separator:" / ",preText:"",postText:"",placement:"bottom",validate:!1},d);return this.each(function(){var b=h(this),c=g(b),a=h("").css({display:"none",position:"absolute",whiteSpace:"nowrap",zIndex:999}).html(n(c,"0"));b.is("textarea")&&(b.data("maxlenghtsizex",b.outerWidth()),b.data("maxlenghtsizey",b.outerHeight()),b.mouseup(function(){(b.outerWidth()!==b.data("maxlenghtsizex")||b.outerHeight()!==b.data("maxlenghtsizey"))&&q(b,a);b.data("maxlenghtsizex", b.outerWidth());b.data("maxlenghtsizey",b.outerHeight())}));r.append(a);b.focus(function(){var d=k(b,g(b));p(d,b,c,a);q(b,a)});b.blur(function(){a.css("display","none")});b.keyup(function(){var e=k(b,g(b)),f=!0;d.validate&&0>e?f=!1:p(e,b,c,a);return f});b.keydown(function(a){if(0>=k(b,g(b))&&46!==a.keyCode&&8!==a.keyCode)return!1})})}})})(jQuery);