TaskMgr-min.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.util.TaskRunner = function(E) {
  7. E = E || 10;
  8. var F = [], A = [];
  9. var B = 0;
  10. var G = false;
  11. var D = function() {
  12. G = false;
  13. clearInterval(B);
  14. B = 0
  15. };
  16. var H = function() {
  17. if (!G) {
  18. G = true;
  19. B = setInterval(I, E)
  20. }
  21. };
  22. var C = function(J) {
  23. A.push(J);
  24. if (J.onStop) {
  25. J.onStop.apply(J.scope || J)
  26. }
  27. };
  28. var I = function() {
  29. if (A.length > 0) {
  30. for (var O = 0, K = A.length; O < K; O++) {
  31. F.remove(A[O])
  32. }
  33. A = [];
  34. if (F.length < 1) {
  35. D();
  36. return
  37. }
  38. }
  39. var M = allGetServerTime().getTime();
  40. for (var O = 0, K = F.length; O < K; ++O) {
  41. var N = F[O];
  42. var J = M - N.taskRunTime;
  43. if (N.interval <= J) {
  44. var L = N.run.apply(N.scope || N, N.args || [++N.taskRunCount]);
  45. N.taskRunTime = M;
  46. if (L === false || N.taskRunCount === N.repeat) {
  47. C(N);
  48. return
  49. }
  50. }
  51. if (N.duration && N.duration <= (M - N.taskStartTime)) {
  52. C(N)
  53. }
  54. }
  55. };
  56. this.start = function(J) {
  57. F.push(J);
  58. J.taskStartTime = allGetServerTime().getTime();
  59. J.taskRunTime = 0;
  60. J.taskRunCount = 0;
  61. H();
  62. return J
  63. };
  64. this.stop = function(J) {
  65. C(J);
  66. return J
  67. };
  68. this.stopAll = function() {
  69. D();
  70. for (var K = 0, J = F.length; K < J; K++) {
  71. if (F[K].onStop) {
  72. F[K].onStop()
  73. }
  74. }
  75. F = [];
  76. A = []
  77. }
  78. };
  79. Ext.TaskMgr = new Ext.util.TaskRunner();