Driver.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * This is the base class for {@link Ext.ux.event.Recorder} and {@link Ext.ux.event.Player}.
  3. */
  4. Ext.define('Ext.ux.event.Driver', {
  5. active: null,
  6. mixins: {
  7. observable: 'Ext.util.Observable'
  8. },
  9. constructor: function (config) {
  10. var me = this;
  11. me.mixins.observable.constructor.apply(this, arguments);
  12. me.addEvents(
  13. /**
  14. * @event start
  15. * Fires when this object is started.
  16. * @param {Ext.ux.event.Driver} this
  17. */
  18. 'start',
  19. /**
  20. * @event stop
  21. * Fires when this object is stopped.
  22. * @param {Ext.ux.event.Driver} this
  23. */
  24. 'stop'
  25. );
  26. },
  27. getTime: function () {
  28. return new Date().getTime();
  29. },
  30. /**
  31. * Returns the number of milliseconds since start was called.
  32. */
  33. getTimestamp: function () {
  34. var d = this.getTime();
  35. return d - this.startTime;
  36. },
  37. onStart: function () {},
  38. onStop: function () {},
  39. /**
  40. * Starts this object. If this object is already started, nothing happens.
  41. */
  42. start: function () {
  43. var me = this;
  44. if (!me.active) {
  45. me.active = new Date();
  46. me.startTime = me.getTime();
  47. me.onStart();
  48. me.fireEvent('start', me);
  49. }
  50. },
  51. /**
  52. * Stops this object. If this object is not started, nothing happens.
  53. */
  54. stop: function () {
  55. var me = this;
  56. if (me.active) {
  57. me.active = null;
  58. me.onStop();
  59. me.fireEvent('stop', me);
  60. }
  61. }
  62. });