Dashboard sipadu mbip
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.

aui-simple-anim.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. AUI.add('aui-simple-anim', function(A) {
  2. var Lang = A.Lang,
  3. now = Lang.now;
  4. var SimpleAnim = A.Component.create(
  5. {
  6. EXTENDS: Object,
  7. constructor: function(config) {
  8. var instance = this;
  9. instance.active = false;
  10. instance.duration = config.duration || 200;
  11. instance.easing = config.easing || instance._easeOutQuad;
  12. instance.from = config.from;
  13. instance.intervalRate = config.intervalRate;
  14. instance.to = config.to;
  15. instance._ontween = config.onTween;
  16. instance._oncomplete = config.onComplete;
  17. },
  18. prototype: {
  19. animate: function() {
  20. var instance = this;
  21. var duration = instance.duration;
  22. var continueAnimation = false;
  23. if (instance.active) {
  24. var time = now() - instance._startTime;
  25. if (instance._ontween) {
  26. var pos = instance.easing(time, instance.from, instance.to - instance.from, duration);
  27. if (pos) {
  28. instance._ontween(pos);
  29. }
  30. }
  31. if (time >= duration) {
  32. instance.active = false;
  33. if (instance._oncomplete) {
  34. instance._oncomplete();
  35. }
  36. }
  37. else {
  38. continueAnimation = true;
  39. }
  40. }
  41. return continueAnimation;
  42. },
  43. start: function() {
  44. var instance = this;
  45. instance._startTime = now();
  46. SimpleAnim.queue(instance);
  47. },
  48. stop: function() {
  49. var instance = this;
  50. instance.active = false;
  51. },
  52. _easeOutQuad: function(t, b, c, d) {
  53. return -c * (t /= d) * (t - 2) + b;
  54. }
  55. },
  56. // Static methods/properties
  57. active: false,
  58. queue: function(animObj) {
  59. var instance = this;
  60. instance._queue.push(animObj);
  61. animObj.active = true;
  62. if (!instance.active) {
  63. instance.start(animObj);
  64. }
  65. },
  66. animate: function() {
  67. var instance = this;
  68. var active = 0;
  69. for (var i = 0, length = instance._queue.length; i < length; i++) {
  70. var animObj = instance._queue[i];
  71. if (animObj.active) {
  72. animObj.animate();
  73. active++;
  74. }
  75. }
  76. if (active == 0 && instance._timer) {
  77. instance.stop();
  78. }
  79. },
  80. start: function(animObj) {
  81. var instance = this;
  82. if (!instance._timer && !instance.active) {
  83. var intervalRate = animObj.intervalRate || instance._intervalRate;
  84. instance.active = true;
  85. instance._timer = setInterval(
  86. function() {
  87. instance.animate();
  88. },
  89. intervalRate
  90. );
  91. }
  92. },
  93. stop: function() {
  94. var instance = this;
  95. clearInterval(instance._timer);
  96. instance._timer = null;
  97. instance.active = false;
  98. instance._queue = [];
  99. },
  100. _intervalRate: 20,
  101. _queue: [],
  102. _timer: null
  103. }
  104. );
  105. A.SimpleAnim = SimpleAnim;
  106. }, '@VERSION@' ,{requires:['aui-base'], skinnable:false});