@ryanwhitman/delay.js
Version:
Delay.js is a JavaScript tool that allows a developer to establish a minimum amount of time that must pass prior to executing one or more callbacks. This tool is especially useful for delaying a quick AJAX response that may otherwise cause a spinner to fl
10 lines • 1.01 kB
JavaScript
/**
* Delay.js is a JavaScript tool that allows a developer to establish a minimum amount of time that must elapse prior to executing one or more callbacks. This tool is especially useful for delaying a quick AJAX response that may otherwise cause a spinner to flash on/off, or something to that nature. This software is designed to be >=IE11 compatible.
*
* @package Delay.js
* @copyright Copyright (c) 2018 Ryan Whitman (https://ryanwhitman.com)
* @license https://opensource.org/licenses/MIT MIT
* @version 1.0.1
* @see https://github.com/RyanWhitman/delay.js
*/
var Delay=function(c){var i=(new Date).getTime();void 0===c&&(c=250);var l=[];this.add_callback=function(a){l.push({func:a,args:Array.prototype.slice.call(arguments,1)})},this.exe=function(a){if("function"==typeof a){var t=Array.prototype.slice.call(arguments,1);t.unshift(a),this.add_callback.apply(null,t)}var n=(new Date).getTime(),e=Math.max(i+c-n,0);setTimeout(function(){l.forEach(function(a){a.func.apply(null,a.args)})},e)}};