forked from pc035860/ngQueue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathngQueue.min.js
More file actions
6 lines (6 loc) · 1.82 KB
/
ngQueue.min.js
File metadata and controls
6 lines (6 loc) · 1.82 KB
1
2
3
4
5
6
/*! ngQueue
version: 0.2.0
build date: 2017-05-16
author: Robin Fan
https://github.com/pc035860/ngQueue.git */
angular.module("ngQueue",[]).factory("$queueFactory",["$q","$window","$timeout","$rootScope","$filter",function(a,b,c,d,e){var f=function(a){this.init(a)},g=f.prototype;return g._config={},g._limit=null,g._queue=[],g._deferFunc=null,g._list=[],g.queueTotal=0,g.queuePending=0,g.queueIdle=!0,g.init=function(a){this._config=a,this._limit=a.limit,this._queue=[],this._config.statistics&&(this._list=[]),a.deferred&&(b.setImmediate?this._deferFunc=function(a){b.setImmediate(function(){a(),d.$apply()})}:this._deferFunc=function(a){c(a)})},g.enqueue=function(a,b,c){var d=[a,b,c];return this._queue.push([a,b,c]),this._config.statistics&&this.updateStats(),this.dequeue(),d},g.remove=function(a){var b=this._queue.indexOf(a),c=this._queue.splice(b,1)[0];return this._config.statistics&&this.updateStats(),c},g.dequeue=function(){if(!(this._limit<=0||0===this._queue.length)){this._limit--;var b,c,d=this,f=this._queue.shift(),g=Math.random(),h=f[0],i=f[1],j=f[2];this._config.statistics&&this._list.push({id:g,resolved:!1}),b=c=function(){if(d._limit++,d._config.statistics){var a=e("filter")(d._list,function(a){return a.id===g})[0];a.resolved=!0,d.updateStats()}d._deferFunc?d._deferFunc(function(){d.dequeue()}):d.dequeue()},a.when(h.apply(i||null,j||null)).then(b,c)}},g.clear=function(){this._queue=[],this._list=[],this._config.statistics&&this.updateStats()},g.updateStats=function(){this.queueTotal=this._queue.length+this._list.length,this.queuePending=e("filter")(this._list,function(a){return a.resolved===!1}).length+this._queue.length,this.queueIdle=this.queuePending<1},function(a,b){var c;return angular.isObject(a)?c=a:(a=a||1,angular.isObject(b)?(c=b,c.limit=c.limit||a):(angular.isUndefined(b)&&(b=!1),c={limit:a,deferred:!!b})),new f(c)}}]);