AkashSaikia

Queeu add

Jun 21st, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $.__queue = {
  2.     _timer: null,
  3.     _queue: [],
  4.     add: function (fn, context, time) {
  5.         var setTimer = function (time) {
  6.             $.__queue._timer = setTimeout(function () {
  7.                 time = $.__queue.add();
  8.                 if ($.__queue._queue.length) {
  9.                     setTimer(time);
  10.                 }
  11.             }, time || 2);
  12.         }
  13.  
  14.         if (fn) {
  15.             $.__queue._queue.push([fn, context, time]);
  16.             if ($.__queue._queue.length == 1) {
  17.                 setTimer(time);
  18.             }
  19.             return;
  20.         }
  21.  
  22.         var next = $.__queue._queue.shift();
  23.         if (!next) {
  24.             return 0;
  25.         }
  26.         next[0].call(next[1] || window);
  27.         return next[2];
  28.     },
  29.     clear: function () {
  30.         clearTimeout($.__queue._timer);
  31.         $.__queue._queue = [];
  32.     }
  33. };
Add Comment
Please, Sign In to add comment