root / trunk / web / dojo / dojox / widget / Rotator.js @ 9
History | View | Annotate | Download (3.97 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.Rotator"]){ |
9 |
dojo._hasResource["dojox.widget.Rotator"]=true; |
10 |
dojo.provide("dojox.widget.Rotator");
|
11 |
dojo.require("dojo.parser");
|
12 |
(function(d){
|
13 |
var _1="dojox.widget.rotator.swap",_2=500,_3="display",_4="none",_5="zIndex"; |
14 |
d.declare("dojox.widget.Rotator",null,{transition:_1,transitionParams:"duration:"+_2,panes:null,constructor:function(_6,_7){ |
15 |
d.mixin(this,_6);
|
16 |
var _8=this,t=_8.transition,tt=_8._transitions={},_9=_8._idMap={},tp=_8.transitionParams=eval("({ "+_8.transitionParams+" })"),_7=_8._domNode=dojo.byId(_7),cb=_8._domNodeContentBox=d.contentBox(_7),p={left:0,top:0},_a=function(bt,dt){ |
17 |
console.warn(_8.declaredClass," - Unable to find transition \"",bt,"\", defaulting to \"",dt,"\"."); |
18 |
}; |
19 |
_8.id=_7.id||(new Date()).getTime();
|
20 |
if(d.style(_7,"position")=="static"){ |
21 |
d.style(_7,"position","relative"); |
22 |
} |
23 |
tt[t]=d.getObject(t); |
24 |
if(!tt[t]){
|
25 |
_a(t,_1); |
26 |
tt[_8.transition=_1]=d.getObject(_1); |
27 |
} |
28 |
if(!tp.duration){
|
29 |
tp.duration=_2; |
30 |
} |
31 |
d.forEach(_8.panes,function(p){
|
32 |
d.create("div",p,_7);
|
33 |
}); |
34 |
var pp=_8.panes=[];
|
35 |
d.query(">",_7).forEach(function(n,i){ |
36 |
var q={node:n,idx:i,params:d.mixin({},tp,eval("({ "+(d.attr(n,"transitionParams")||"")+" })"))},r=q.trans=d.attr(n,"transition")||_8.transition; |
37 |
d.forEach(["id","title","duration","waitForEvent"],function(a){ |
38 |
q[a]=d.attr(n,a); |
39 |
}); |
40 |
if(q.id){
|
41 |
_9[q.id]=i; |
42 |
} |
43 |
if(!tt[r]&&!(tt[r]=d.getObject(r))){
|
44 |
_a(r,q.trans=_8.transition); |
45 |
} |
46 |
p.position="absolute";
|
47 |
p.display=_4; |
48 |
if(_8.idx==null||d.attr(n,"selected")){ |
49 |
if(_8.idx!=null){ |
50 |
d.style(pp[_8.idx].node,_3,_4); |
51 |
} |
52 |
_8.idx=i; |
53 |
p.display="";
|
54 |
} |
55 |
d.style(n,p); |
56 |
d.query("> script[type^='dojo/method']",n).orphan().forEach(function(s){ |
57 |
var e=d.attr(s,"event"); |
58 |
if(e){
|
59 |
q[e]=d.parser._functionFromScript(s); |
60 |
} |
61 |
}); |
62 |
pp.push(q); |
63 |
}); |
64 |
_8._controlSub=d.subscribe(_8.id+"/rotator/control",_8,"control"); |
65 |
},destroy:function(){ |
66 |
d.forEach([this._controlSub,this.wfe],d.unsubscribe); |
67 |
d.destroy(this._domNode);
|
68 |
},next:function(){ |
69 |
return this.go(this.idx+1); |
70 |
},prev:function(){ |
71 |
return this.go(this.idx-1); |
72 |
},go:function(p){ |
73 |
var _b=this,i=_b.idx,pp=_b.panes,_c=pp.length,_d=_b._idMap[p]; |
74 |
_b._resetWaitForEvent(); |
75 |
p=_d!=null?_d:(p||0); |
76 |
p=p<_c?(p<0?_c-1:p):0; |
77 |
if(p==i||_b.anim){
|
78 |
return null; |
79 |
} |
80 |
var _e=pp[i],_f=pp[p];
|
81 |
d.style(_e.node,_5,2);
|
82 |
d.style(_f.node,_5,1);
|
83 |
var _10={current:_e,next:_f,rotator:_b},_11=_b.anim=_b._transitions[_f.trans](d.mixin({rotatorBox:_b._domNodeContentBox},_10,_f.params)); |
84 |
if(_11){
|
85 |
var def=new d.Deferred(),ev=_f.waitForEvent,h=d.connect(_11,"onEnd",function(){ |
86 |
d.style(_e.node,{display:_4,left:0,opacity:1,top:0,zIndex:0}); |
87 |
d.disconnect(h); |
88 |
_b.anim=null;
|
89 |
_b.idx=p; |
90 |
if(_e.onAfterOut){
|
91 |
_e.onAfterOut(_10); |
92 |
} |
93 |
if(_f.onAfterIn){
|
94 |
_f.onAfterIn(_10); |
95 |
} |
96 |
_b.onUpdate("onAfterTransition");
|
97 |
if(!ev){
|
98 |
_b._resetWaitForEvent(); |
99 |
def.callback(); |
100 |
} |
101 |
}); |
102 |
_b.wfe=ev?d.subscribe(ev,function(){
|
103 |
_b._resetWaitForEvent(); |
104 |
def.callback(true);
|
105 |
}):null;
|
106 |
_b.onUpdate("onBeforeTransition");
|
107 |
if(_e.onBeforeOut){
|
108 |
_e.onBeforeOut(_10); |
109 |
} |
110 |
if(_f.onBeforeIn){
|
111 |
_f.onBeforeIn(_10); |
112 |
} |
113 |
_11.play(); |
114 |
return def;
|
115 |
} |
116 |
},onUpdate:function(_12,_13){ |
117 |
d.publish(this.id+"/rotator/update",[_12,this,_13||{}]); |
118 |
},_resetWaitForEvent:function(){ |
119 |
if(this.wfe){ |
120 |
d.unsubscribe(this.wfe);
|
121 |
this.wfe=null; |
122 |
} |
123 |
},control:function(_14){ |
124 |
var _15=d._toArray(arguments),_16=this; |
125 |
_15.shift(); |
126 |
_16._resetWaitForEvent(); |
127 |
if(_16[_14]){
|
128 |
var def=_16[_14].apply(_16,_15);
|
129 |
if(def){
|
130 |
def.addCallback(function(){
|
131 |
_16.onUpdate(_14); |
132 |
}); |
133 |
} |
134 |
_16.onManualChange(_14); |
135 |
}else{
|
136 |
console.warn(_16.declaredClass," - Unsupported action \"",_14,"\"."); |
137 |
} |
138 |
},resize:function(_17,_18){ |
139 |
var b=this._domNodeContentBox={w:_17,h:_18}; |
140 |
d.contentBox(this._domNode,b);
|
141 |
d.forEach(this.panes,function(p){ |
142 |
d.contentBox(p.node,b); |
143 |
}); |
144 |
},onManualChange:function(){ |
145 |
}}); |
146 |
d.setObject(_1,function(_19){
|
147 |
return new d._Animation({play:function(){ |
148 |
d.style(_19.current.node,_3,_4); |
149 |
d.style(_19.next.node,_3,"");
|
150 |
this._fire("onEnd"); |
151 |
}}); |
152 |
}); |
153 |
})(dojo); |
154 |
} |