-
Notifications
You must be signed in to change notification settings - Fork 0
/
jchecks.min.js
1 lines (1 loc) · 2.18 KB
/
jchecks.min.js
1
!function(t){var e=function(){function t(){this.callbacks=[]}return t.prototype.on=function(t,e){return this.callbacks.push({event:t,fn:e}),this},t.prototype.off=function(t,e){return this.callbacks=this.callbacks.filter(function(i){return!(i.event===t&&i.fn===e)}),this},t.prototype.once=function(t,e){function i(){this.off(t,i),e.apply(this,arguments)}return this.on(t,i),this},t.prototype.emit=function(t){for(var e=this,i=[],n=1;n<arguments.length;n++)i[n-1]=arguments[n];return this.callbacks.filter(function(e){return e.event===t}).forEach(function(t){t.fn.apply(e,i)}),this},t}(),i=function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}(),n=function(t){function e(e){var i=t.call(this)||this;return e=e||{},i._items=e.items||[],i._interval=e.interval||1e3,i._timeout=e.timeout||5e3,i}return i(e,t),Object.defineProperty(e.prototype,"items",{get:function(){return this._items},enumerable:!0,configurable:!0}),e.prototype.run=function(){if(this._timer){var t=this._items[this._stepIndex];if(!t)return void this.stop();var e=void 0===t.timeout?this._timeout:t.timeout,i=null;if(e>0&&(i=Date.now()-this._stepTime)>e)return void this.error("timeout");if(this.emit("check",t,i),void 0===t.checker||t.checker()){if(void 0!==t.processor){this.emit("process",t);var n=t.processor();if(n)return void this.error(n)}this.next()}}},e.prototype.start=function(){var t=this;this._timer&&this.stop(),this._timer=setInterval(function(){t.run()},this._interval),this._stepIndex=0,this._stepTime=Date.now(),this.run(),this.emit("start")},e.prototype.next=function(){this._stepIndex++,this._stepTime=Date.now(),this._items[this._stepIndex]?this.emit("next"):this.stop()},e.prototype.stop=function(){clearInterval(this._timer),this._timer=0,this.emit("stop")},e.prototype.error=function(t){this.emit("error",t),this.stop()},e}(e),o={Checklist:n};"function"==typeof define?(define.amd||define.cmd)&&define(function(){return o}):"undefined"!=typeof module&&module.exports?module.exports=o:window.jchecks=o}();