This repository has been archived by the owner on Aug 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
wChar.min.js
1 lines (1 loc) · 3.12 KB
/
wChar.min.js
1
/*! wChar - v2.1.2 - 2013-06-29 */!function(a){function b(b,c){this.$el=a(b),this.options=c,this.timeout=null,this.generate()}b.prototype={generate:function(){if(!this.$char){var b=this;this.$container=a('<div style="position:relative; display:inline-block; *display:inline; zoom:1;"></div>'),this.$el.after(this.$container).appendTo(this.$container),this.$char=a('<div class="wChar">123</div>').hide(),this.$char.appendTo(this.$container),this.setTheme(this.options.theme),this.setOpacity(this.options.opacity),this.setPosition(this.options.position),this.$el.keyup(function(a){b.onKeyup(a)})}return this.$char},onKeyup:function(){var a=this.$el.val().length,b=this.options.max-a;this.setTimeout(),0>b&&(this.$el.val(this.$el.val().substring(0,this.options.max)),b=0),this.options.showMinCount&&this.options.min>0&&a<this.options.min?(this.$char.html(a+(this.options.messageMin?" "+this.options.messageMin:"")),this.$char.addClass("wChar-min")):(0>=b?this.$char.addClass("wChar-min"):this.$char.removeClass("wChar-min"),this.$char.html(b+(this.options.message?" "+this.options.message:"")))},setTimeout:function(){var a=this;window.setTimeout(function(){a.$char.fadeIn(a.options.fadeIn)},a.options.delayIn),window.clearTimeout(this.timeout),this.timeout=window.setTimeout(function(){a.$char.fadeOut(a.options.fadeOut)},a.options.delayOut)},setTheme:function(a){this.$char.attr("class",this.$char.attr("class").replace(/wChar-theme-.+\s|wChar-theme-.+$/,"")),this.$char.addClass("wChar-theme-"+a)},setOpacity:function(a){this.$char.css("opacity",a)},setPosition:function(a){var b=this.$char.outerWidth(!0),c=this.$char.outerHeight(!0),d=this.$el.outerWidth()/2-b/2,e=this.$el.outerHeight()/2-c/2;switch(this.$char.css({left:"",right:"",top:"",bottom:""}),a){case"tl":this.$char.css({left:0,top:-1*c});break;case"tc":this.$char.css({left:d,top:-1*c});break;case"tr":this.$char.css({right:0,top:-1*c});break;case"rt":this.$char.css({right:-1*b,top:0});break;case"rm":this.$char.css({right:-1*b,top:e});break;case"rb":this.$char.css({right:-1*b,bottom:0});break;case"br":this.$char.css({right:0,bottom:-1*c});break;case"bc":this.$char.css({left:d,bottom:-1*c});break;case"bl":this.$char.css({left:0,bottom:-1*c});break;case"lb":this.$char.css({left:-1*b,bottom:0});break;case"lm":this.$char.css({left:-1*b,top:e});break;case"lt":this.$char.css({left:-1*b,top:0})}}},a.fn.wChar=function(c,d){function e(d){var e=a.data(d,"wChar");if(!e){var f=a.extend(!0,{},c);f.min=a(d).attr("data-minlength")||f.min,f.max=a(d).attr("data-maxlength")||f.max,e=new b(d,f),a.data(d,"wChar",e)}return e}if("string"==typeof c){var f=[],g=this.each(function(){var b=a(this).data("wChar");if(b){var e=(d?"set":"get")+c.charAt(0).toUpperCase()+c.substring(1).toLowerCase();b[c]?b[c].apply(b,[d]):d?(b[e]&&b[e].apply(b,[d]),b.options[c]&&(b.options[c]=d)):b[e]?f.push(b[e].apply(b,[d])):b.options[c]?f.push(b.options[c]):f.push(null)}});return 1===f.length?f[0]:f.length>0?f:g}return c=a.extend({},a.fn.wChar.defaults,c),this.each(function(){e(this)})},a.fn.wChar.defaults={theme:"classic",position:"tr",opacity:.9,showMinCount:!0,min:0,max:100,fadeIn:500,fadeOut:500,delayIn:0,delayOut:2e3,message:"",messageMin:""}}(jQuery);