95d7820b3579b2048438b2200a71ad2b2e6fc36d.svn-base 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. if (!dojo._hasResource["dojox.timing._base"]) { // _hasResource checks added by
  2. // build. Do not use
  3. // _hasResource directly in your
  4. // code.
  5. dojo._hasResource["dojox.timing._base"] = true;
  6. dojo.provide("dojox.timing._base");
  7. dojo.experimental("dojox.timing");
  8. dojox.timing.Timer = function(/* int */interval) {
  9. // summary: Timer object executes an "onTick()" method repeatedly at a
  10. // specified interval.
  11. // repeatedly at a given interval.
  12. // interval: Interval between function calls, in milliseconds.
  13. this.timer = null;
  14. this.isRunning = false;
  15. this.interval = interval;
  16. this.onStart = null;
  17. this.onStop = null;
  18. };
  19. dojo.extend(dojox.timing.Timer, {
  20. onTick : function() {
  21. // summary: Method called every time the interval passes.
  22. // Override to do something useful.
  23. },
  24. setInterval : function(interval) {
  25. // summary: Reset the interval of a timer, whether running
  26. // or not.
  27. // interval: New interval, in milliseconds.
  28. if (this.isRunning) {
  29. window.clearInterval(this.timer);
  30. }
  31. this.interval = interval;
  32. if (this.isRunning) {
  33. this.timer = window.setInterval(dojo.hitch(this,
  34. "onTick"), this.interval);
  35. }
  36. },
  37. start : function() {
  38. // summary: Start the timer ticking.
  39. // description: Calls the "onStart()" handler, if defined.
  40. // Note that the onTick() function is not called right away,
  41. // only after first interval passes.
  42. if (typeof this.onStart == "function") {
  43. this.onStart();
  44. }
  45. this.isRunning = true;
  46. this.timer = window.setInterval(dojo.hitch(this, "onTick"),
  47. this.interval);
  48. },
  49. stop : function() {
  50. // summary: Stop the timer.
  51. // description: Calls the "onStop()" handler, if defined.
  52. if (typeof this.onStop == "function") {
  53. this.onStop();
  54. }
  55. this.isRunning = false;
  56. window.clearInterval(this.timer);
  57. }
  58. });
  59. }