root / trunk / web / dojo / dojox / widget / AutoRotator.js @ 12
History | View | Annotate | Download (2.27 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dojox.widget.AutoRotator"]){ |
9 |
dojo._hasResource["dojox.widget.AutoRotator"]=true; |
10 |
dojo.provide("dojox.widget.AutoRotator");
|
11 |
dojo.require("dojox.widget.Rotator");
|
12 |
(function(d){
|
13 |
d.declare("dojox.widget.AutoRotator",dojox.widget.Rotator,{suspendOnHover:false,duration:4000,autoStart:true,pauseOnManualChange:false,cycles:-1,random:false,reverse:false,constructor:function(){ |
14 |
var _1=this; |
15 |
if(_1.cycles-0==_1.cycles&&_1.cycles>0){ |
16 |
_1.cycles++; |
17 |
}else{
|
18 |
_1.cycles=_1.cycles?-1:0; |
19 |
} |
20 |
_1._connects=[d.connect(_1._domNode,"onmouseover",function(){ |
21 |
if(_1.suspendOnHover&&!_1.anim&&!_1.wfe){
|
22 |
var t=_1._endTime,n=_1._now();
|
23 |
_1._suspended=true;
|
24 |
_1._resetTimer(); |
25 |
_1._resumeDuration=t>n?t-n:0.01;
|
26 |
} |
27 |
}),d.connect(_1._domNode,"onmouseout",function(){ |
28 |
if(_1.suspendOnHover&&!_1.anim){
|
29 |
_1._suspended=false;
|
30 |
if(_1.playing&&!_1.wfe){
|
31 |
_1.play(true);
|
32 |
} |
33 |
} |
34 |
})]; |
35 |
if(_1.autoStart&&_1.panes.length>1){ |
36 |
_1.play(); |
37 |
}else{
|
38 |
_1.pause(); |
39 |
} |
40 |
},destroy:function(){ |
41 |
d.forEach(this._connects,d.disconnect);
|
42 |
this.inherited(arguments); |
43 |
},play:function(_2,_3){ |
44 |
this.playing=true; |
45 |
this._resetTimer();
|
46 |
if(_2!==true&&this.cycles>0){ |
47 |
this.cycles--;
|
48 |
} |
49 |
if(this.cycles==0){ |
50 |
this.pause();
|
51 |
}else{
|
52 |
if(!this._suspended){ |
53 |
this.onUpdate("play"); |
54 |
if(_3){
|
55 |
this._cycle();
|
56 |
}else{
|
57 |
var r=(this._resumeDuration||0)-0,u=(r>0?r:(this.panes[this.idx].duration||this.duration))-0; |
58 |
this._resumeDuration=0; |
59 |
this._endTime=this._now()+u; |
60 |
this._timer=setTimeout(d.hitch(this,"_cycle",false),u); |
61 |
} |
62 |
} |
63 |
} |
64 |
},pause:function(){ |
65 |
this.playing=this._suspended=false; |
66 |
this.cycles=-1; |
67 |
this._resetTimer();
|
68 |
this.onUpdate("pause"); |
69 |
},_now:function(){ |
70 |
return (new Date()).getTime(); |
71 |
},_resetTimer:function(){ |
72 |
clearTimeout(this._timer);
|
73 |
},_cycle:function(_4){ |
74 |
var _5=this,i=_5.idx,j; |
75 |
if(_5.random){
|
76 |
do{
|
77 |
j=Math.floor(Math.random()*_5.panes.length+1);
|
78 |
}while(j==i);
|
79 |
}else{
|
80 |
j=i+(_5.reverse?-1:1); |
81 |
} |
82 |
var _6=_5.go(j);
|
83 |
if(_6){
|
84 |
_6.addCallback(function(_7){
|
85 |
_5.onUpdate("cycle");
|
86 |
if(_5.playing){
|
87 |
_5.play(false,_7);
|
88 |
} |
89 |
}); |
90 |
} |
91 |
},onManualChange:function(_8){ |
92 |
this.cycles=-1; |
93 |
if(_8!="play"){ |
94 |
this._resetTimer();
|
95 |
if(this.pauseOnManualChange){ |
96 |
this.pause();
|
97 |
} |
98 |
} |
99 |
if(this.playing){ |
100 |
this.play();
|
101 |
} |
102 |
}}); |
103 |
})(dojo); |
104 |
} |