-
Notifications
You must be signed in to change notification settings - Fork 12
/
ngQueue.min.js
7 lines (6 loc) · 2.03 KB
/
ngQueue.min.js
1
2
3
4
5
6
7
/*! ngQueue
version: 0.3.1
build date: 2018-06-09
author: Robin Fan
https://github.com/pc035860/ngQueue.git */
!function(t,e){void 0===t&&void 0!==window&&(t=window),"function"==typeof define&&define.amd?define(["angular"],function(t){return e(t)}):"object"==typeof module&&module.exports?module.exports=e(require("angular")):e(t.angular)}(this,function(s){s.module("ngQueue",[]).factory("$queueFactory",["$q","$window","$timeout","$rootScope","$filter",function(f,e,i,u,r){var n=function(t){this.init(t)},t=n.prototype;return t._config={},t._limit=null,t._queue=[],t._deferFunc=null,t._list=[],t.queueTotal=0,t.queuePending=0,t.queueIdle=!0,t.init=function(t){this._config=t,this._limit=t.limit,this._queue=[],this._config.statistics&&(this._list=[]),t.deferred&&(e.setImmediate?this._deferFunc=function(t){e.setImmediate(function(){t(),u.$apply()})}:this._deferFunc=function(t){i(t)})},t.enqueue=function(t,e,i){var u=[t,e,i];return this._queue.push([t,e,i]),this._config.statistics&&this.updateStats(),this.dequeue(),u},t.remove=function(t){var e=this._queue.indexOf(t),i=this._queue.splice(e,1)[0];return this._config.statistics&&this.updateStats(),i},t.dequeue=function(){if(!(this._limit<=0||0===this._queue.length)){this._limit--;var t,e,i=this,u=this._queue.shift(),n=Math.random(),s=u[0],o=u[1],l=u[2];this._config.statistics&&this._list.push({id:n,resolved:!1}),t=e=function(){(i._limit++,i._config.statistics)&&(r("filter")(i._list,function(t){return t.id===n})[0].resolved=!0,i.updateStats());i._deferFunc?i._deferFunc(function(){i.dequeue()}):i.dequeue()},f.when(s.apply(o||null,l||null)).then(t,e)}},t.clear=function(){this._queue=[],this._list=[],this._config.statistics&&this.updateStats()},t.updateStats=function(){this.queueTotal=this._queue.length+this._list.length,this.queuePending=r("filter")(this._list,function(t){return!1===t.resolved}).length+this._queue.length,this.queueIdle=this.queuePending<1},function(t,e){var i;return s.isObject(t)?i=t:(t=t||1,s.isObject(e)?(i=e).limit=i.limit||t:(s.isUndefined(e)&&(e=!1),i={limit:t,deferred:!!e})),new n(i)}}])});