mxAnimation.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Copyright (c) 2006-2015, JGraph Ltd
  3. * Copyright (c) 2006-2015, Gaudenz Alder
  4. */
  5. /**
  6. *
  7. * Class: mxAnimation
  8. *
  9. * Implements a basic animation in JavaScript.
  10. *
  11. * Constructor: mxAnimation
  12. *
  13. * Constructs an animation.
  14. *
  15. * Parameters:
  16. *
  17. * graph - Reference to the enclosing <mxGraph>.
  18. */
  19. function mxAnimation(delay)
  20. {
  21. this.delay = (delay != null) ? delay : 20;
  22. };
  23. /**
  24. * Extends mxEventSource.
  25. */
  26. mxAnimation.prototype = new mxEventSource();
  27. mxAnimation.prototype.constructor = mxAnimation;
  28. /**
  29. * Variable: delay
  30. *
  31. * Specifies the delay between the animation steps. Defaul is 30ms.
  32. */
  33. mxAnimation.prototype.delay = null;
  34. /**
  35. * Variable: thread
  36. *
  37. * Reference to the thread while the animation is running.
  38. */
  39. mxAnimation.prototype.thread = null;
  40. /**
  41. * Function: isRunning
  42. *
  43. * Returns true if the animation is running.
  44. */
  45. mxAnimation.prototype.isRunning = function()
  46. {
  47. return this.thread != null;
  48. };
  49. /**
  50. * Function: startAnimation
  51. *
  52. * Starts the animation by repeatedly invoking updateAnimation.
  53. */
  54. mxAnimation.prototype.startAnimation = function()
  55. {
  56. if (this.thread == null)
  57. {
  58. this.thread = window.setInterval(mxUtils.bind(this, this.updateAnimation), this.delay);
  59. }
  60. };
  61. /**
  62. * Function: updateAnimation
  63. *
  64. * Hook for subclassers to implement the animation. Invoke stopAnimation
  65. * when finished, startAnimation to resume. This is called whenever the
  66. * timer fires and fires an mxEvent.EXECUTE event with no properties.
  67. */
  68. mxAnimation.prototype.updateAnimation = function()
  69. {
  70. this.fireEvent(new mxEventObject(mxEvent.EXECUTE));
  71. };
  72. /**
  73. * Function: stopAnimation
  74. *
  75. * Stops the animation by deleting the timer and fires an <mxEvent.DONE>.
  76. */
  77. mxAnimation.prototype.stopAnimation = function()
  78. {
  79. if (this.thread != null)
  80. {
  81. window.clearInterval(this.thread);
  82. this.thread = null;
  83. this.fireEvent(new mxEventObject(mxEvent.DONE));
  84. }
  85. };
  86. __mxOutput.mxAnimation = typeof mxAnimation !== 'undefined' ? mxAnimation : undefined;