AnimationSequence.js
上传用户:kimgenplus
上传日期:2016-06-05
资源大小:20877k
文件大小:3k
源码类别:

OA系统

开发平台:

Java

  1. /*
  2. Copyright (c) 2004-2006, The Dojo Foundation
  3. All Rights Reserved.
  4. Licensed under the Academic Free License version 2.1 or above OR the
  5. modified BSD license. For more information on Dojo licensing, see:
  6. http://dojotoolkit.org/community/licensing.shtml
  7. */
  8. dojo.provide("dojo.animation.AnimationSequence");
  9. dojo.require("dojo.animation.AnimationEvent");
  10. dojo.require("dojo.animation.Animation");
  11. dojo.deprecated("dojo.animation.AnimationSequence is slated for removal in 0.5; use dojo.lfx.* instead.", "0.5");
  12. dojo.animation.AnimationSequence = function (repeatCount) {
  13. this._anims = [];
  14. this.repeatCount = repeatCount || 0;
  15. };
  16. dojo.lang.extend(dojo.animation.AnimationSequence, {repeatCount:0, _anims:[], _currAnim:-1, onBegin:null, onEnd:null, onNext:null, handler:null, add:function () {
  17. for (var i = 0; i < arguments.length; i++) {
  18. this._anims.push(arguments[i]);
  19. arguments[i]._animSequence = this;
  20. }
  21. }, remove:function (anim) {
  22. for (var i = 0; i < this._anims.length; i++) {
  23. if (this._anims[i] == anim) {
  24. this._anims[i]._animSequence = null;
  25. this._anims.splice(i, 1);
  26. break;
  27. }
  28. }
  29. }, removeAll:function () {
  30. for (var i = 0; i < this._anims.length; i++) {
  31. this._anims[i]._animSequence = null;
  32. }
  33. this._anims = [];
  34. this._currAnim = -1;
  35. }, clear:function () {
  36. this.removeAll();
  37. }, play:function (gotoStart) {
  38. if (this._anims.length == 0) {
  39. return;
  40. }
  41. if (gotoStart || !this._anims[this._currAnim]) {
  42. this._currAnim = 0;
  43. }
  44. if (this._anims[this._currAnim]) {
  45. if (this._currAnim == 0) {
  46. var e = {type:"begin", animation:this._anims[this._currAnim]};
  47. if (typeof this.handler == "function") {
  48. this.handler(e);
  49. }
  50. if (typeof this.onBegin == "function") {
  51. this.onBegin(e);
  52. }
  53. }
  54. this._anims[this._currAnim].play(gotoStart);
  55. }
  56. }, pause:function () {
  57. if (this._anims[this._currAnim]) {
  58. this._anims[this._currAnim].pause();
  59. }
  60. }, playPause:function () {
  61. if (this._anims.length == 0) {
  62. return;
  63. }
  64. if (this._currAnim == -1) {
  65. this._currAnim = 0;
  66. }
  67. if (this._anims[this._currAnim]) {
  68. this._anims[this._currAnim].playPause();
  69. }
  70. }, stop:function () {
  71. if (this._anims[this._currAnim]) {
  72. this._anims[this._currAnim].stop();
  73. }
  74. }, status:function () {
  75. if (this._anims[this._currAnim]) {
  76. return this._anims[this._currAnim].status();
  77. } else {
  78. return "stopped";
  79. }
  80. }, _setCurrent:function (anim) {
  81. for (var i = 0; i < this._anims.length; i++) {
  82. if (this._anims[i] == anim) {
  83. this._currAnim = i;
  84. break;
  85. }
  86. }
  87. }, _playNext:function () {
  88. if (this._currAnim == -1 || this._anims.length == 0) {
  89. return;
  90. }
  91. this._currAnim++;
  92. if (this._anims[this._currAnim]) {
  93. var e = {type:"next", animation:this._anims[this._currAnim]};
  94. if (typeof this.handler == "function") {
  95. this.handler(e);
  96. }
  97. if (typeof this.onNext == "function") {
  98. this.onNext(e);
  99. }
  100. this._anims[this._currAnim].play(true);
  101. } else {
  102. var e = {type:"end", animation:this._anims[this._anims.length - 1]};
  103. if (typeof this.handler == "function") {
  104. this.handler(e);
  105. }
  106. if (typeof this.onEnd == "function") {
  107. this.onEnd(e);
  108. }
  109. if (this.repeatCount > 0) {
  110. this._currAnim = 0;
  111. this.repeatCount--;
  112. this._anims[this._currAnim].play(true);
  113. } else {
  114. if (this.repeatCount == -1) {
  115. this._currAnim = 0;
  116. this._anims[this._currAnim].play(true);
  117. } else {
  118. this._currAnim = -1;
  119. }
  120. }
  121. }
  122. }});