1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
/*
Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
Available via Academic Free License >= 2.1 OR the modified BSD license.
see: http://dojotoolkit.org/license for details
*/
dojo._xdResourceLoaded(function(dojo, dijit, dojox){
return {depends: [["provide", "dojox.widget.AutoRotator"],
["require", "dojox.widget.Rotator"]],
defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.widget.AutoRotator"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.widget.AutoRotator"] = true;
dojo.provide("dojox.widget.AutoRotator");
dojo.require("dojox.widget.Rotator");
(function(d){
d.declare("dojox.widget.AutoRotator", dojox.widget.Rotator, {
// summary:
// A rotator that automatically transitions between child nodes.
//
// description:
// Adds automatic rotating to the dojox.widget.Rotator. The
// AutoRotator has parameters that control how user input can
// affect the rotator including a suspend when hovering over the
// rotator and pausing when the user manually advances to another
// pane.
//
// example:
// | <div dojoType="dojox.widget.AutoRotator" duration="3000">
// | <div>
// | Pane 1!
// | </div>
// | <div duration="5000">
// | Pane 2 with an overrided duration!
// | </div>
// | </div>
// suspendOnHover: boolean
// Pause the rotator when the mouse hovers over it.
suspendOnHover: false,
// duration: int
// The time in milliseconds before transitioning to the next pane. The
// default value is 4000 (4 seconds).
duration: 4000,
// autoStart: boolean
// Starts the timer to transition children upon creation.
autoStart: true,
// pauseOnManualChange: boolean
// Pause the rotator when the pane is changed or a controller's next or
// previous buttons are clicked.
pauseOnManualChange: false,
// cycles: int
// Number of cycles before pausing.
cycles: -1,
// random: boolean
// Determines if the panes should cycle randomly.
random: false,
// reverse: boolean
// Causes the rotator to rotate in reverse order.
reverse: false,
constructor: function(){
// summary:
// Initializes the timer and connect to the rotator.
var _t = this;
// validate the cycles counter
if(_t.cycles-0 == _t.cycles && _t.cycles > 0){
// we need to add 1 because we decrement cycles before the animation starts
_t.cycles++;
}else{
_t.cycles = _t.cycles ? -1 : 0;
}
// wire up the mouse hover events
_t._connects = [
d.connect(_t._domNode, "onmouseover", function(){
// temporarily suspend the cycling, but don't officially pause
// it and don't allow suspending if we're transitioning
if(_t.suspendOnHover && !_t.anim && !_t.wfe){
var t = _t._endTime,
n = _t._now();
_t._suspended = true;
_t._resetTimer();
_t._resumeDuration = t > n ? t - n : 0.01;
}
}),
d.connect(_t._domNode, "onmouseout", function(){
// if we were playing, resume playback unless were in the
// middle of a transition
if(_t.suspendOnHover && !_t.anim){
_t._suspended = false;
if(_t.playing && !_t.wfe){
_t.play(true);
}
}
})
];
// everything is ready, so start
if(_t.autoStart && _t.panes.length > 1){
// start playing
_t.play();
}else{
// since we're not playing, lets pause
_t.pause();
}
},
destroy: function(){
// summary:
// Disconnect the AutoRotator's events.
d.forEach(this._connects, d.disconnect);
this.inherited(arguments);
},
play: function(/*boolean?*/skipCycleDecrement, /*boolean?*/skipDuration){
// summary:
// Sets the state to "playing" and schedules the next cycle to run.
this.playing = true;
this._resetTimer();
// don't decrement the count if we're resuming play
if(skipCycleDecrement !== true && this.cycles > 0){
this.cycles--;
}
if(this.cycles == 0){
// we have reached the number of cycles, so pause
this.pause();
}else if(!this._suspended){
this.onUpdate("play");
// if we haven't been suspended, then grab the duration for this pane and
// schedule a cycle to be run
if(skipDuration){
this._cycle();
}else{
var r = (this._resumeDuration || 0)-0,
u = (r > 0 ? r : (this.panes[this.idx].duration || this.duration))-0;
// call _cycle() after a duration and pass in false so it isn't manual
this._resumeDuration = 0;
this._endTime = this._now() + u;
this._timer = setTimeout(d.hitch(this, "_cycle", false), u);
}
}
},
pause: function(){
// summary:
// Sets the state to "not playing" and clears the cycle timer.
this.playing = this._suspended = false;
this.cycles = -1;
this._resetTimer();
// notify the controllers we're paused
this.onUpdate("pause");
},
_now: function(){
// summary:
// Helper function to return the current system time in milliseconds.
return (new Date()).getTime(); /*int*/
},
_resetTimer: function(){
// summary:
// Resets the timer used to schedule the next transition.
clearTimeout(this._timer);
},
_cycle: function(/*boolean|int?*/manual){
// summary:
// Cycles the rotator to the next/previous pane.
var _t = this,
i = _t.idx,
j;
if(_t.random){
// make sure we don't randomly pick the pane we're already on
do{
j = Math.floor(Math.random() * _t.panes.length + 1);
}while(j == i);
}else{
j = i + (_t.reverse ? -1 : 1)
}
// rotate!
var def = _t.go(j);
if(def){
def.addCallback(function(/*boolean?*/skipDuration){
_t.onUpdate("cycle");
if(_t.playing){
_t.play(false, skipDuration);
}
});
}
},
onManualChange: function(/*string*/action){
// summary:
// Override the Rotator's onManualChange so we can pause.
this.cycles = -1;
// obviously we don't want to pause if play was just clicked
if(action != "play"){
this._resetTimer();
if(this.pauseOnManualChange){
this.pause();
}
}
if(this.playing){
this.play();
}
}
});
})(dojo);
}
}};});
|