| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/_base/array", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/on", |
| 6 |
"dojo/mouse", |
| 7 |
"dojox/widget/Rotator" |
| 8 |
], function(declare, array, lang, on, mouse, Rotator) { |
| 9 |
|
| 10 |
return declare("dojox.widget.AutoRotator", Rotator,{ |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
suspendOnHover: false, |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
duration: 4000, |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
autoStart: true, |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
pauseOnManualChange: false, |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
cycles: -1, |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
random: false, |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
reverse: false, |
| 58 |
|
| 59 |
constructor: function(){ |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
var _t = this; |
| 64 |
|
| 65 |
|
| 66 |
if(_t.cycles-0 == _t.cycles && _t.cycles > 0){ |
| 67 |
|
| 68 |
_t.cycles++; |
| 69 |
}else{ |
| 70 |
_t.cycles = _t.cycles ? -1 : 0; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
_t._signals = [ |
| 75 |
on(_t._domNode, mouse.enter, function(){ |
| 76 |
|
| 77 |
|
| 78 |
if(_t.suspendOnHover && !_t.anim && !_t.wfe){ |
| 79 |
var t = _t._endTime, |
| 80 |
n = _t._now(); |
| 81 |
_t._suspended = true; |
| 82 |
_t._resetTimer(); |
| 83 |
_t._resumeDuration = t > n ? t - n : 0.01; |
| 84 |
} |
| 85 |
}), |
| 86 |
|
| 87 |
on(_t._domNode, mouse.leave, function(){ |
| 88 |
|
| 89 |
|
| 90 |
if(_t.suspendOnHover && !_t.anim){ |
| 91 |
_t._suspended = false; |
| 92 |
if(_t.playing && !_t.wfe){ |
| 93 |
_t.play(true); |
| 94 |
} |
| 95 |
} |
| 96 |
}) |
| 97 |
]; |
| 98 |
|
| 99 |
|
| 100 |
if(_t.autoStart && _t.panes.length > 1){ |
| 101 |
|
| 102 |
_t.play(); |
| 103 |
}else{ |
| 104 |
|
| 105 |
_t.pause(); |
| 106 |
} |
| 107 |
}, |
| 108 |
|
| 109 |
destroy: function(){ |
| 110 |
|
| 111 |
|
| 112 |
array.forEach(this._signals, function(signal) { signal.remove(); }); |
| 113 |
delete this._signals; |
| 114 |
dojo.forEach(this._connects, dojo.disconnect); |
| 115 |
this.inherited(arguments); |
| 116 |
}, |
| 117 |
|
| 118 |
play: function(skipCycleDecrement, skipDuration){ |
| 119 |
|
| 120 |
|
| 121 |
this.playing = true; |
| 122 |
this._resetTimer(); |
| 123 |
|
| 124 |
|
| 125 |
if(skipCycleDecrement !== true && this.cycles > 0){ |
| 126 |
this.cycles--; |
| 127 |
} |
| 128 |
|
| 129 |
if(this.cycles == 0){ |
| 130 |
|
| 131 |
this.pause(); |
| 132 |
}else if(!this._suspended){ |
| 133 |
this.onUpdate("play"); |
| 134 |
|
| 135 |
|
| 136 |
if(skipDuration){ |
| 137 |
this._cycle(); |
| 138 |
}else{ |
| 139 |
var r = (this._resumeDuration || 0)-0, |
| 140 |
u = (r > 0 ? r : (this.panes[this.idx].duration || this.duration))-0; |
| 141 |
|
| 142 |
this._resumeDuration = 0; |
| 143 |
this._endTime = this._now() + u; |
| 144 |
this._timer = setTimeout(lang.hitch(this, "_cycle", false), u); |
| 145 |
} |
| 146 |
} |
| 147 |
}, |
| 148 |
|
| 149 |
pause: function(){ |
| 150 |
|
| 151 |
|
| 152 |
this.playing = this._suspended = false; |
| 153 |
this.cycles = -1; |
| 154 |
this._resetTimer(); |
| 155 |
|
| 156 |
|
| 157 |
this.onUpdate("pause"); |
| 158 |
}, |
| 159 |
|
| 160 |
_now: function(){ |
| 161 |
|
| 162 |
|
| 163 |
return (new Date()).getTime(); |
| 164 |
}, |
| 165 |
|
| 166 |
_resetTimer: function(){ |
| 167 |
|
| 168 |
|
| 169 |
clearTimeout(this._timer); |
| 170 |
}, |
| 171 |
|
| 172 |
_cycle: function(manual){ |
| 173 |
|
| 174 |
|
| 175 |
var _t = this, |
| 176 |
i = _t.idx, |
| 177 |
j; |
| 178 |
|
| 179 |
if(_t.random){ |
| 180 |
|
| 181 |
do{ |
| 182 |
j = Math.floor(Math.random() * _t.panes.length + 1); |
| 183 |
}while(j == i); |
| 184 |
}else{ |
| 185 |
j = i + (_t.reverse ? -1 : 1) |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
var def = _t.go(j); |
| 190 |
|
| 191 |
if(def){ |
| 192 |
def.addCallback(function(skipDuration){ |
| 193 |
_t.onUpdate("cycle"); |
| 194 |
if(_t.playing){ |
| 195 |
_t.play(false, skipDuration); |
| 196 |
} |
| 197 |
}); |
| 198 |
} |
| 199 |
}, |
| 200 |
|
| 201 |
onManualChange: function(action){ |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
this.cycles = -1; |
| 206 |
|
| 207 |
|
| 208 |
if(action != "play"){ |
| 209 |
this._resetTimer(); |
| 210 |
if(this.pauseOnManualChange){ |
| 211 |
this.pause(); |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
if(this.playing){ |
| 216 |
this.play(); |
| 217 |
} |
| 218 |
} |
| 219 |
}); |
| 220 |
}); |