-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtimestore.1.2.0.min.js
1 lines (1 loc) · 7.24 KB
/
timestore.1.2.0.min.js
1
(function(t){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=t()}else if(typeof define==="function"&&define.amd){define([],t)}else{var e;if(typeof window!=="undefined"){e=window}else if(typeof global!=="undefined"){e=global}else if(typeof self!=="undefined"){e=self}else{e=this}e.timestore=t()}})(function(){var t,e,i;return function t(e,i,s){function n(o,u){if(!i[o]){if(!e[o]){var h=typeof require=="function"&&require;if(!u&&h)return h(o,!0);if(r)return r(o,!0);var a=new Error("Cannot find module '"+o+"'");throw a.code="MODULE_NOT_FOUND",a}var l=i[o]={exports:{}};e[o][0].call(l.exports,function(t){var i=e[o][1][t];return n(i?i:t)},l,l.exports,t,e,i,s)}return i[o].exports}var r=typeof require=="function"&&require;for(var o=0;o<s.length;o++)n(s[o]);return n}({1:[function(t,e,i){"use strict";function s(){}function n(t,e,i,n,r){var o=this;this.callback=t;this.delay=e;this.fireBeforeClear=i;this.id=n||null;this.onClear=r||s;this.thisArg=null;this.withArgs=[];this.nativeTimeoutId=setTimeout(function(){o.callback.apply(o.thisArg,o.withArgs);o.onClear();o.burnt=true;o.log("execute")},this.delay);this.isPaused=false;this.pausedAt=0;this.resumedAt=Date.now();this.cumulativeWork=0;this.burnt=false;this.log("create")}n.prototype.setThis=function(t){this.thisArg=t||null;return this};n.prototype.callWith=function(){this.withArgs=Array.prototype.slice.call(arguments);return this};n.prototype.applyWith=function(t){this.withArgs=t||[];return this};n.prototype.clear=function(){if(this.burnt)return;if(this.fireBeforeClear&&this.isPaused===false){this.callback.apply(this.thisArg,this.withArgs)}clearTimeout(this.nativeTimeoutId);this.onClear();this.burnt=true;this.log("clear")};n.prototype.pause=function(){if(this.isPaused===true||this.burnt)return;clearTimeout(this.nativeTimeoutId);this.isPaused=true;this.pausedAt=Date.now();this.log("pause");return this};n.prototype.resume=function(){var t=this,e;if(this.isPaused===false||this.burnt)return;e=this.pausedAt-this.resumedAt;this.delay-=e;if(this.delay<0){this.delay=0}this.nativeTimeoutId=setTimeout(function(){t.callback.apply(t.thisArg,t.withArgs);t.onClear();t.burnt=true;t.log("execute")},this.delay);this.isPaused=false;this.resumedAt=Date.now();this.cumulativeWork+=e;this.log("resume");return this};n.prototype.toggle=function(){if(this.isPaused){this.resume()}else{this.pause()}return this};n.prototype.changeDelay=function(t){var e=this.isPaused;!e&&this.pause();this.delay=t-this.cumulativeWork;!e&&this.resume();return this};n.prototype.getTimeLeft=function(){if(this.burnt){return 0}else if(this.isPaused){return this.delay-(this.pausedAt-this.resumedAt)}else{return this.delay-(Date.now()-this.resumedAt)}};n.prototype.log=s;function r(t,e,i,r,o){var u=this;this.callback=t;this.delay=e;this.fireBeforeClear=i;this.id=r||null;this.onClear=o||s;this.thisArg=null;this.withArgs=[];this.run=function(){u.timeout=new n(u.run.bind(u),u.delay);u.callback.apply(u.thisArg,u.withArgs)};this.timeout=new n(this.run.bind(this),this.delay)}r.prototype.setThis=function(t){this.thisArg=t||null;return this};r.prototype.callWith=function(){this.withArgs=Array.prototype.slice.call(arguments);return this};r.prototype.applyWith=function(t){this.withArgs=t||[];return this};r.prototype.clear=function(){if(this.fireBeforeClear&&this.timeout.isPaused===false){this.callback.apply(this.thisArg,this.withArgs)}this.timeout.clear();this.onClear()};r.prototype.pause=function(){this.timeout.pause();return this};r.prototype.resume=function(){this.timeout.resume();return this};r.prototype.toggle=function(){this.timeout.toggle();return this};r.prototype.changeDelay=function(t){this.delay=t;this.timeout.changeDelay(this.delay);return this};r.prototype.getTimeLeft=function(){return this.timeout.getTimeLeft()};function o(){this.timeouts={};this.uniqueTimeoutId=0;this.intervals={};this.uniqueIntervalId=0}o.prototype.setTimeout=function(t,e,i,s){var r=this;if(typeof t==="function"){s=i;i=e;e=t;t=this.uniqueTimeoutId++}else{t=t||this.uniqueTimeoutId++}t=t.toString();if(t in this.timeouts)this.clearTimeout(t);this.timeouts[t]=new n(e,i,s,t,function(){delete r.timeouts[t]});return this.timeouts[t]};o.prototype.clearTimeout=function(t){t in this.timeouts&&this.timeouts[t].clear()};o.prototype.clearTimeouts=function(t){t.forEach(function(t){t in this.timeouts&&this.timeouts[t].clear()},this)};o.prototype.pauseTimeout=function(t){t in this.timeouts&&this.timeouts[t].pause()};o.prototype.pauseTimeouts=function(t){t.forEach(function(t){t in this.timeouts&&this.timeouts[t].pause()},this)};o.prototype.resumeTimeout=function(t){t in this.timeouts&&this.timeouts[t].resume()};o.prototype.resumeTimeouts=function(t){t.forEach(function(t){t in this.timeouts&&this.timeouts[t].resume()},this)};o.prototype.toggleTimeout=function(t){t in this.timeouts&&this.timeouts[t].toggle()};o.prototype.toggleTimeouts=function(t){t.forEach(function(t){t in this.timeouts&&this.timeouts[t].toggle()},this)};o.prototype.changeTimeoutDelay=function(t,e){t in this.timeouts&&this.timeouts[t].changeDelay(e)};o.prototype.getTimeoutTimeLeft=function(t){if(t in this.timeouts){return this.timeouts[t].getTimeLeft()}else{return 0}};o.prototype.setInterval=function(t,e,i,s){var n=this;if(typeof t==="function"){s=i;i=e;e=t;t=this.uniqueIntervalId++}else{t=t||this.uniqueIntervalId++}t=t.toString();if(t in this.intervals)this.clearInterval(t);this.intervals[t]=new r(e,i,s,t,function(){delete n.intervals[t]});return this.intervals[t]};o.prototype.clearInterval=function(t){t in this.intervals&&this.intervals[t].clear()};o.prototype.clearIntervals=function(t){t.forEach(function(t){t in this.intervals&&this.intervals[t].clear()},this)};o.prototype.pauseInterval=function(t){t in this.intervals&&this.intervals[t].pause()};o.prototype.pauseIntervals=function(t){t.forEach(function(t){t in this.intervals&&this.intervals[t].pause()},this)};o.prototype.resumeInterval=function(t){t in this.intervals&&this.intervals[t].resume()};o.prototype.resumeIntervals=function(t){t.forEach(function(t){t in this.intervals&&this.intervals[t].resume()},this)};o.prototype.toggleInterval=function(t){t in this.intervals&&this.intervals[t].toggle()};o.prototype.toggleIntervals=function(t){t.forEach(function(t){t in this.intervals&&this.intervals[t].toggle()},this)};o.prototype.changeIntervalDelay=function(t,e){t in this.intervals&&this.intervals[t].changeDelay(e)};o.prototype.getIntervalTimeLeft=function(t){if(t in this.intervals){return this.intervals[t].getTimeLeft()}else{return 0}};o.prototype.clearAll=function(){Object.keys(this.timeouts).forEach(this.clearTimeout.bind(this));this.uniqueTimeoutId=0;Object.keys(this.intervals).forEach(this.clearInterval.bind(this));this.uniqueIntervalId=0};o.prototype.pauseAll=function(){Object.keys(this.timeouts).forEach(this.pauseTimeout.bind(this));Object.keys(this.intervals).forEach(this.pauseInterval.bind(this))};o.prototype.resumeAll=function(){Object.keys(this.timeouts).forEach(this.resumeTimeout.bind(this));Object.keys(this.intervals).forEach(this.resumeInterval.bind(this))};o.prototype.getTimeouts=function(){return Object.keys(this.timeouts)};o.prototype.hasTimeout=function(t){return t in this.timeouts};o.prototype.getIntervals=function(){return Object.keys(this.intervals)};o.prototype.hasInterval=function(t){return t in this.intervals};e.exports={Timeout:n,Interval:r,Timestore:o}},{}]},{},[1])(1)});