Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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