This repository was archived by the owner on Aug 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjquery.textCounter.min.js
More file actions
1 lines (1 loc) · 4.36 KB
/
jquery.textCounter.min.js
File metadata and controls
1 lines (1 loc) · 4.36 KB
1
typeof Object.create!="function"&&(Object.create=function(n){"use strict";function t(){}return t.prototype=n,new t}),function(n){"use strict";var s="right",u=10,f=!0,e=!1,y="counterProgressBar",v="counterTextPattern",o="counterWarning",a="txtWarning",l="textCounter",h="string",c="none";var p={init:function(t,i){var s="100%",p="<div></div>",f="absolute",u=this,e="#textCounter_",r;u.elem=i,u.$elem=n(i),u.options=n.extend({},n.fn.textCounter.options,t),r=u.options,e+=u.id?u.id:u.$elem.attr("name"),u.$obj=n(e).length?n("#"+e).css({display:c,position:f,top:0,left:0}).addClass(r.defaultClass):n(p,{id:e,"class":r.defaultClass}).appendTo("body").css({display:c,position:f,top:0,left:0}),n(p,{"class":r.counterPatternClass}).css({"z-index":r.zIndex,position:f,top:0,left:0,height:s,width:s}).appendTo(u.$obj),r.showProgressBar&&n("<span></span>",{"class":r.progressBarClass}).css({"z-index":r.zIndex-1,position:f,top:0,left:0,height:s}).appendTo(u.$obj),typeof r.posX==h&&(r.posX=r.posX.toLowerCase()),typeof r.posY==h&&(r.posY=r.posY.toLowerCase()),r.countDown=u._convertToBoolean(r.countDown),r.showBeforeWarn=u._convertToBoolean(r.showBeforeWarn),r.defaultClass=r.defaultClass||l,r.txtWarningClass=r.txtWarningClass||a,r.counterWarningClass=r.counterWarningClass||o,r.counterPatternClass=r.counterPatternClass||v,r.progressBarClass=r.progressBarClass||y,u._bindEvents()},_bindEvents:function(){var n=this,t=n.options,r=n.$elem,i=n.$obj;n.$elem.on("focusin focusout keyup keydown input paste",function(u){switch(u.type){case"focusout":r.removeClass(t.txtWarningClass),i.removeClass(t.counterWarningClass),n._doTransition(e);break;case"focusin":i.removeClass(t.counterWarningClass),r.removeClass(t.txtWarningClass),n._checkChars(),n._setXY(),n._doTransition(f);break;default:n._checkChars()}})},_doTransition:function(n){var t=this,r=t.options.transition,f=t.options.transitionSpeed,u=t.options.showBeforeWarn,e=t.options.easing,i=t.$obj;u&&(r!==c&&r?i[r](f,e):n?i.show(0):i.hide(0))},_setXY:function(){var o="center",r=this,t=0,f=0,e=r.options.posX,h=r.options.posY,c=parseInt(r.options.posXoffset,u),l=parseInt(r.options.posYoffset,u),i=r.$obj,n=r.$elem;switch(e){case"left":t=n.offset().left;break;case o:t=n.offset().left+n.width()/2-i.width()/2;break;case s:t=n.offset().left+n.width()-i.width()-4;break;default:t=parseInt(e,u)}switch(h){case"top":f=n.offset().top-i.height()-8;break;case o:f=n.offset().top+n.height()/2-i.height()/2;break;case"bottom":f=n.offset().top+n.height()+11;break;default:f=parseInt(h,u)}e==="left"&&h===o&&(t-=i.width()+13),e===s&&h===o&&(t+=i.width()+12),typeof c=="number"&&(t+=parseInt(c,u)),typeof l=="number"&&(f+=parseInt(l,u)),i.css({top:f,left:t})},_checkChars:function(){var r=this,i=r.$elem,e=r.options,f=e.countDown,t=i.attr("maxlength"),n=0;typeof t||(t=e.maxLength),n=f?parseInt(Math.round(t-i.val().length),u):parseInt(Math.round(i.val().length,u),u),(n>t||n<0)&&(i.val(i.val().substring(0,t)),n=f?n++:n--),r._setClassAndShow(r._buildString(n,t,f))},_buildString:function(t,i,r){var o=this.options,u=o.textPattern,h=0,s=f;return h=r?Math.round((i-t)/i*100):Math.round(t/i*100),s=u.indexOf("[%]")>-1?r?h<=o.warnAt?e:f:h>=100-o.warnAt?e:f:r?t<=o.warnAt?e:f:i-t<=o.warnAt?e:f,u=u.replace("[+]",t),u=u.replace("[=]",i),u=u.replace("[%]",h),n("."+o.counterPatternClass).html(u),o.showProgressBar&&n("."+o.progressBarClass).animate({width:h+"%"},1),s},_setClassAndShow:function(n){var r=this,t=r.options,u=r.$elem,i=r.$obj;u.hasClass(t.txtWarningClass)?n&&u.removeClass(t.txtWarningClass):n||u.addClass(t.txtWarningClass),i.hasClass(t.counterWarningClass)?n&&(i.removeClass(t.counterWarningClass),u.trigger("counterPass")):n||(i.addClass(t.counterWarningClass),u.trigger(o)),!t.showBeforeWarn&&i.hasClass(t.counterWarningClass)&&i.is(":hidden")&&r._doTransition(f),t.showBeforeWarn||i.hasClass(t.counterWarningClass)||!i.is(":visible")||r._doTransition(e)},_convertToBoolean:function(n){return typeof n==h&&n.toLowerCase(),n==="false"?e:Boolean(n)}};n.fn.textCounter=function(t){return this.each(function(){var i=Object.create(p);i.init(t,this),n.data(this,l,i)})},n.fn.textCounter.options={countDown:f,counterPatternClass:v,counterWarningClass:o,defaultClass:l,easing:"swing",maxLength:500,posX:s,posY:"bottom",posXoffset:0,posYoffset:0,progressBarClass:y,showBeforeWarn:f,showProgressBar:e,textPattern:"[+] / [=]",transition:"slideToggle",transitionSpeed:200,txtWarningClass:a,warnAt:u,zIndex:100}}(jQuery,window,document);