not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.1 KiB

  1. 
  2. // Timer object
  3. enyo.kind({
  4. name: "Timer",
  5. kind: enyo.Component,
  6. minInterval: 50,
  7. published: {
  8. baseInterval: 100, paused: false
  9. },
  10. events: {
  11. onTriggered: ""
  12. },
  13. // Constructor, start the timer
  14. create: function() {
  15. this.inherited(arguments);
  16. this.start();
  17. },
  18. // Destroy the timer
  19. destroy: function() {
  20. this.stop();
  21. this.inherited(arguments);
  22. },
  23. // Start the timer
  24. start: function() {
  25. this.job = window.setInterval(enyo.bind(this, "timer"), this.baseInterval);
  26. },
  27. // Stop the timer
  28. stop: function() {
  29. window.clearInterval(this.job);
  30. },
  31. // Pause timer
  32. pause: function() {
  33. this.paused = true;
  34. },
  35. // Resume the timer
  36. resume: function() {
  37. this.paused = false;
  38. },
  39. // Periodic event raised
  40. timer: function() {
  41. if (!this.paused)
  42. this.doTriggered({time: new Date().getTime()});
  43. },
  44. // Interval changed event
  45. baseIntervalChanged: function(inOldValue) {
  46. this.baseInterval = Math.max(this.minInterval, this.baseInterval);
  47. this.stop();
  48. this.start();
  49. }
  50. });