root / trunk / web / dojo / dojox / widget / rotator / Controller.js
History | View | Annotate | Download (2.33 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
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.Controller"]){ |
||
9 | dojo._hasResource["dojox.widget.rotator.Controller"]=true; |
||
10 | dojo.provide("dojox.widget.rotator.Controller");
|
||
11 | (function(d){
|
||
12 | var _1="dojoxRotator",_2=_1+"Play",_3=_1+"Pause",_4=_1+"Number",_5=_1+"Tab",_6=_1+"Selected"; |
||
13 | d.declare("dojox.widget.rotator.Controller",null,{rotator:null,commands:"prev,play/pause,info,next",constructor:function(_7,_8){ |
||
14 | d.mixin(this,_7);
|
||
15 | var r=this.rotator; |
||
16 | if(r){
|
||
17 | while(_8.firstChild){
|
||
18 | _8.removeChild(_8.firstChild); |
||
19 | } |
||
20 | var ul=this._domNode=d.create("ul",null,_8),_9=" "+_1+"Icon",cb=function(_a,_b,_c){ |
||
21 | d.create("li",{className:_b,innerHTML:"<a href=\"#\"><span>"+_a+"</span></a>",onclick:function(e){ |
||
22 | d.stopEvent(e); |
||
23 | if(r){
|
||
24 | r.control.apply(r,_c); |
||
25 | } |
||
26 | }},ul); |
||
27 | }; |
||
28 | d.forEach(this.commands.split(","),function(b,i){ |
||
29 | switch(b){
|
||
30 | case "prev": |
||
31 | cb("Prev",_1+"Prev"+_9,["prev"]); |
||
32 | break;
|
||
33 | case "play/pause": |
||
34 | cb("Play",_2+_9,["play"]); |
||
35 | cb("Pause",_3+_9,["pause"]); |
||
36 | break;
|
||
37 | case "info": |
||
38 | this._info=d.create("li",{className:_1+"Info",innerHTML:this._buildInfo(r)},ul); |
||
39 | break;
|
||
40 | case "next": |
||
41 | cb("Next",_1+"Next"+_9,["next"]); |
||
42 | break;
|
||
43 | case "#": |
||
44 | case "titles": |
||
45 | for(var j=0;j<r.panes.length;j++){ |
||
46 | cb(b=="#"?j+1:r.panes[j].title||"Tab "+(j+1),(b=="#"?_4:_5)+" "+(j==r.idx?_6:"")+" "+_1+"Pane"+j,["go",j]); |
||
47 | } |
||
48 | break;
|
||
49 | } |
||
50 | },this);
|
||
51 | d.query("li:first-child",ul).addClass(_1+"First"); |
||
52 | d.query("li:last-child",ul).addClass(_1+"Last"); |
||
53 | this._togglePlay();
|
||
54 | this._con=d.connect(r,"onUpdate",this,"_onUpdate"); |
||
55 | } |
||
56 | },destroy:function(){ |
||
57 | d.disconnect(this._con);
|
||
58 | d.destroy(this._domNode);
|
||
59 | },_togglePlay:function(_d){ |
||
60 | var p=this.rotator.playing; |
||
61 | d.query("."+_2,this._domNode).style("display",p?"none":""); |
||
62 | d.query("."+_3,this._domNode).style("display",p?"":"none"); |
||
63 | },_buildInfo:function(r){ |
||
64 | return "<span>"+(r.idx+1)+" / "+r.panes.length+"</span>"; |
||
65 | },_onUpdate:function(_e){ |
||
66 | var r=this.rotator; |
||
67 | switch(_e){
|
||
68 | case "play": |
||
69 | case "pause": |
||
70 | this._togglePlay();
|
||
71 | break;
|
||
72 | case "onAfterTransition": |
||
73 | if(this._info){ |
||
74 | this._info.innerHTML=this._buildInfo(r); |
||
75 | } |
||
76 | var s=function(n){ |
||
77 | if(r.idx<n.length){
|
||
78 | d.addClass(n[r.idx],_6); |
||
79 | } |
||
80 | }; |
||
81 | s(d.query("."+_4,this._domNode).removeClass(_6)); |
||
82 | s(d.query("."+_5,this._domNode).removeClass(_6)); |
||
83 | break;
|
||
84 | } |
||
85 | }}); |
||
86 | })(dojo); |
||
87 | } |