-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.mechounter.min.js
2 lines (2 loc) · 9.85 KB
/
jquery.mechounter.min.js
1
2
!function(t){"use strict";"function"==typeof define&&define.amd?define(["jquery","jquery.ui.widget"],t):"object"==typeof exports?t(require("jquery"),require("./vendor/jquery.ui.widget")):t(window.jQuery)}(function(t){function e(t,e){return e=e||1,Math.pow(10,e*t-2)}function i(t,i){return i=i||1,l*e(t,i)/i}function s(t,e){return e=e||1,l*t/e}function a(t,e){return e=e||1,r(t*e*u,e)}function r(t,e){return e=e||1,(l*Math.log(t)+2)/e}function n(t,e){for(var i=e;--t;)i+=e;return i}function o(e,i){var s=this;return this._opts=i=t.extend(o.defaultOptions,i),i.mask&&this._parseMask(i.mask,this._opts),this._validateOpts(),this.$el=t(e).addClass(this._opts.baseClass),Object.defineProperty(this,"_height",{enumerable:!0,configurable:!0,get:function(){var t=s.$el.height();return t<=0?-1e4:(Object.defineProperty(s,"_height",{value:t,writable:!0,enumerable:!0}),t)}}),this._digits=[],this._initDom(),{execute:function(t,e,i){return s.execute(t,e,i)},spinTo:function(t,e){return s.spinTo(t,e)},resetTo:function(t){return s.resetTo(t)},setImmediate:function(t){return s.resetTo(t)},getValue:function(){return s.getValue()},destroy:function(){return s.destroy()}}}function h(e,i){this.owner=e;var s=this.owner._opts;i&&(this.$sep=t(e._thousandSepStr).prependTo(e.$el)),this.$el=t(e._digitStr).prependTo(e.$el),this.$el.html(e._makeSpan("rect","0")+n(2,e._makeSpan("card",""))),this.$all=this.$el.add(this.$sep),this._showMs=s.showDigitMs,this._num=e._digits.length,this.$all.animate({width:"toggle",opacity:.01},0);var a=this.$el.find("."+s.baseClass+"-card");this.$card0=a.eq(0),this.$card1=a.eq(1),this.empty=!0,this.wasted=!1}t.fn.mechounter=function(e,i,s){var a=i;return null!=e&&"object"!=typeof e||(a=e||{},e="create"),"number"==typeof e&&(i=e,e="spinCloserOrResetTo"),"get"===e?this.eq(0).data("mechounter"):"getValue"===e?this.eq(0).data("mechounter").getValue():"create"===e?this.each(function(){var e=t(this);e.data("mechounter")||e.data("mechounter",new o(e,a))}):"getDefaults"===e?o.defaultOptions:this.each(function(){var a=t(this).data("mechounter");a&&a.execute(e,i,s)})};var l=.4342944819032518,u=2.302585092994046;o.defaultOptions={mask:"3.2",decimalSep:".",thousandSep:"",value:0,baseClass:"mechounter",showDigitMs:300,refreshDelayMs:30,resetDelayMs:2500,spinCloserDelayMs:2e4,spinCloserSmoothDelayMs:1e3,spinCloserMinStep:.15,perceptibleShift:.2,onBeforeSpin:function(t,e,i){},onSpinStep:function(t,e){}},o.pluginName="mechounter";var p="spinTo,resetTo,setImmediate,spinCloserOrResetTo,destroy".split(",");o.prototype.execute=function(t,e,i){~p.indexOf(t)&&this[t](e,i)},o.prototype._parseMask=function(t,e){(t=/(\D?)(\d+)((\D)(\d+))?/.exec(t))&&(e=e||{},e.thousandSep=t[1],e.digits=t[2],e.decimalSep=t[4]||".",e.decimals=t[5])},o.prototype._validateOpts=function(){var t=this._opts;t.digits=Math.min(15,Math.max(1,Math.floor(+t.digits)||1)),t.decimals=Math.min(t.digits-1,Math.max(0,Math.floor(+t.decimals)||0)),t.intDigits=t.digits-t.decimals,t.multiplier=Math.pow(10,t.decimals)},o.prototype._makeSpan=function(t,e){return"<span class='"+this._opts.baseClass+"-"+t+"'>"+e+"</span>"},o.prototype._addSpan=function(e,i){return t(this._makeSpan(e,i)).prependTo(this.$el)},o.prototype._initDom=function(){var e=this,i=this._opts,s=i.decimals,a=i.intDigits;if(this._oldHtml=this.$el.html(),this.$el.html(""),this._digitStr=this._makeSpan("digit",""),this._thousandSepStr=this._makeSpan("thousandSep",i.thousandSep),s){for(;s--;)this._addDecimalDigit();t(this._makeSpan("decimalSep",i.decimalSep)).prependTo(e.$el)}for(this._addDigit=i.thousandSep?this._addIntDigitWithSep:this._addIntDigit,this._intDigits=0,this._addIntDigit();a--;)this._addDigit();this.setImmediate(i.value)},o.prototype.setImmediate=function(t){this._setImmediate(t*this._opts.multiplier)},o.prototype._setImmediate=function(t){clearInterval(this._interval);var e,i,s,a=this._opts,r=this._digits.length,n=1;for(this._value=t,i=this._digits[0].setVisValue(t),t=Math.floor(.1*t);t>0||n<a.digits||n<r;)s=t<1&&n>=a.digits,e=this._digits[n++]||this._addDigit(),i=e.setVisValue(t+i,s),t=Math.floor(.1*t);this._dropEmptyDigits()},o.prototype._addDecimalDigit=function(t){var e=new h(this,t);return this._digits.push(e),e},o.prototype._addIntDigit=function(t){return this._intDigits++,this._addDecimalDigit(t)},o.prototype._addIntDigitWithSep=function(){return this._addIntDigit(this._intDigits%3==0)},o.prototype._calcSlowdownParams=function(t,i,r){var n,o=a(t),h=0,l=1,u=l,p=1,d=0,_=1,c=o;if(o>i)do{n=o,l*=1+p,o=a(t,l),o<i?(p*=.5,l=u):u=l}while(n!==o);else do{n=o,c*=.5,o+=d>_?c:-c,h=i-o,_=e(o),d=(t-s(_))/h}while(n!==o);r(h,o,l,e(o,l))},o.prototype._setSpeed=function(t){var e=this._opts;this._speed=.001*t,this._perceptibleDgt=l*Math.log(this._speed*e.multiplier)-e.perceptibleShift},o.prototype.getValue=function(){return this._value/this._opts.multiplier},o.prototype.spinCloserOrResetTo=function(t){var e=this.getValue();if(t!==e){var i,s,a=this._opts;if(e>t)return void this.resetTo(t);if(!(t-e<a.spinCloserMinStep)){if(a.spinCloserDelayMs)return void this.spinTo(t,a.spinCloserDelayMs);i=Date.now(),s=i-this._lastCallMs||i,this._lastCallMs=i,this.spinTo(t,s+a.spinCloserSmoothDelayMs)}}},o.prototype.spinTo=function(t,e){this._spinTo(t*this._opts.multiplier,e)},o.prototype._spinTo=function(t,i){if(this._isResetInProgress)return void(this._onResetDone=function(){this._spinTo(t,i)});if(!i||this._value===t)return clearInterval(this._interval),void this._setImmediate(t);var a,r=this,n=this._opts,o=this._value,h=.001*i,l=t-o,u=l>0,p=u?1:-1,d=Math.abs(l),_=1,c=0,f=0;clearInterval(r._interval),this._setImmediate(o),this._calcSlowdownParams(d,h,function(t,e,i,s){f=t,a=e,_=i,c=s}),this._startTime=Date.now(),this._setSpeed(c),this._maxPerceptibleDgt=this._perceptibleDgt,this._currentValues=function(i){var n=.001*i;if(n<=f)return void(r._value=o+p*c*n);n-=f,c=e(a-n,_),r._setSpeed(c),r._value=t-p*s(c,_),p*r._value<p*o&&(r._value=o)},function(){for(var e,i=0,s=r._digits.length,a=o,n=t,h=Math.floor(a),l=Math.floor(n),p=a-h,d=n-l;n>=.1||i<s;)e=r._digits[i++]||r._addDigit(),e.createValueUpdaterForSet(a,n,u),p=h%10==9?p:0,h=Math.floor(.1*h),a=h+p,d=l%10==9?d:0,l=Math.floor(.1*l),n=l+d}(),n.onBeforeSpin(i,l,o),r._interval=setInterval(function(){var e=r._elapsed();if(e>=i)return clearInterval(r._interval),void r._setImmediate(t);r._currentValues(e),n.onSpinStep(e,r._value);for(var s,a=r._value+u,o=r._digits.length,h=0,l=0;h<o;)s=a<1&&h>=n.digits,l=r._digits[h++]._updateValue(a,l,s),a*=.1;r._dropEmptyDigits()},n.refreshDelayMs)},o.prototype.resetTo=function(t){this._resetTo(t*this._opts.multiplier)},o.prototype._resetTo=function(t){var e=this._opts;if(this._value===t)return void this._finalizeValueReset(t);this._isResetInProgress=!0;var i,a,r,n,o=this,h=(this._value,e.resetDelayMs),l=.001*h,u=o._digits.length,p=0;!function(t){for(var e,i=0;i<u;)e=o._digits[i++].prepareValueIntervalForReset(t),e>p&&(p=e),t=Math.floor(.1*t);for(l=.1*l*p,h=.1*h*p;t>0;)o._addDigit().setVisValue(t),t=Math.floor(.1*t)}(t),this._calcSlowdownParams(p,l,function(t,e,s,o){i=t,a=e,r=s,n=o}),function(){for(var t=0,e=s(n,r);t<u;)o._digits[t++].createValueUpdaterForReset(r,a,n,e)}(),this._startTime=Date.now(),this._value=t,clearInterval(o._interval),o._interval=setInterval(function(){var e=0,i=o._elapsed();if(i>=h)return void o._finalizeValueReset(t);for(i*=.001;e<u;)o._digits[e++]._updateValue(i)},e.refreshDelayMs)},o.prototype._finalizeValueReset=function(t){clearInterval(this._interval),this._isResetInProgress=null,this._setImmediate(t),this._onResetDone&&(this._onResetDone(),this._onResetDone=null)},o.prototype._dropEmptyDigits=function(){var t=this._digits.length,e=this._digits[--t];if(e.wasted){do{e.remove(),this._intDigits--,e=this._digits[--t]}while(e.wasted);this._digits.length=++t}},o.prototype._elapsed=function(){return Date.now()-this._startTime},o.prototype.destroy=function(){clearInterval(this._interval),this.$el.removeClass(this._opts.baseClass).html(this._oldHtml),delete this.$el.data().mechounter},h.prototype.reveal=function(){this.$all.animate({width:"toggle"},this._showMs).animate({opacity:1},this._showMs)},h.prototype.remove=function(t){if(t)return this.$all.remove();var e=this;e.$all.stop(!0).animate({opacity:.01},this._showMs).hide(this._showMs,function(){e.$all.remove()})},h.prototype.prepareValueIntervalForReset=function(t){return this._srcVal=this._value%10,this._dstVal=t%10,this._dstVal<this._srcVal&&(this._dstVal+=10),this._aDif=this._dstVal-this._srcVal,this._aDif},h.prototype.createValueUpdaterForReset=function(t,e,s,r){var n,o,h=this,l=0;r>this._aDif?n=a(this._aDif,t):(n=e,l=(this._aDif-r)/s),o=l+n,this._updateValue=function(e){return e>o?void h.setVisValue(h._dstVal):e<=l?void h.setVisValue(h._srcVal+s*e):(e-=l,void h.setVisValue(h._dstVal-i(n-e,t)))}},h.prototype.createValueUpdaterForSet=function(t,e,i){if(i=+i,t===e)return void(this._updateValue=function(){return 0});if(this._setVisValue=i?this.setVis2Value:this.setVisValue,0===this._num)return void(this._updateValue=function(t){return this._setVisValue(t-i)});var s;if(s=i?function(i){return i<t?t:e<i?e:i}:function(i){return i<e?e:t<i?t:i},this._num-this.owner._maxPerceptibleDgt>=1)return void(this._updateValue=function(t,e,i){var a=Math.floor(t);return this._setVisValue(s(a+e),i)});this._updateValue=function(t,e,a){var r=this._num-this.owner._perceptibleDgt;if(r<1)return this._setVisValue(s(t-i),a);var n=Math.floor(t);if(r<2){r--;var o=t-n;return o=r*e+(1-r)*(o-i),this._setVisValue(s(n+o),a)}return this._setVisValue(s(n+e),a)}},h.prototype.setVisValue=function(t,e){this._value=t;var i=Math.floor(t),s=i%10,a=t-i,r=a*this.owner._height,n=r-this.owner._height;this.$card0.css("top",r+"px"),this.$card1.css("top",n+"px");var o=e?"":"0",h=o+s;return this._zRnDgt!==h&&(this._zRnDgt=h,this.$card0.text(0===s?o:s),this.$card1.text(9===s?o:s+1)),e=0===s&&a<.3&&e,!this.empty&&e&&(this.wasted=!0),this.empty&&!e&&this.reveal(),this.empty=e,9!==s?0:a},h.prototype.setVis2Value=function(t,e){var i=this.setVisValue(t,e);return i?i-1:0}});
//# sourceMappingURL=maps/jquery.mechounter.min.js.map