| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/_base/lang", |
| 4 |
"dojo/_base/html", |
| 5 |
"dojo/_base/event", |
| 6 |
"dojo/_base/array", |
| 7 |
"dojo/_base/connect", |
| 8 |
"dojo/query" |
| 9 |
], function(declare, lang, html, event, array, connect, query) { |
| 10 |
|
| 11 |
var _dojoxRotator = "dojoxRotator", |
| 12 |
_play = _dojoxRotator + "Play", |
| 13 |
_pause = _dojoxRotator + "Pause", |
| 14 |
_number = _dojoxRotator + "Number", |
| 15 |
_tab = _dojoxRotator + "Tab", |
| 16 |
_selected = _dojoxRotator + "Selected"; |
| 17 |
|
| 18 |
return declare("dojox.widget.rotator.Controller", null, { |
| 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 |
rotator: null, |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
commands: "prev,play/pause,info,next", |
| 67 |
|
| 68 |
constructor: function(params, node){ |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
lang.mixin(this, params); |
| 73 |
|
| 74 |
|
| 75 |
var r = this.rotator; |
| 76 |
if(r){ |
| 77 |
|
| 78 |
while(node.firstChild){ |
| 79 |
node.removeChild(node.firstChild); |
| 80 |
} |
| 81 |
|
| 82 |
var ul = this._domNode = html.create("ul", null, node), |
| 83 |
icon = " " + _dojoxRotator + "Icon", |
| 84 |
|
| 85 |
|
| 86 |
cb = function(label, css, action){ |
| 87 |
html.create("li", { |
| 88 |
className: css, |
| 89 |
innerHTML: '<a href="#"><span>' + label + '</span></a>', |
| 90 |
onclick: function(e){ |
| 91 |
event.stop(e); |
| 92 |
if(r){ |
| 93 |
r.control.apply(r, action); |
| 94 |
} |
| 95 |
} |
| 96 |
}, ul); |
| 97 |
}; |
| 98 |
|
| 99 |
|
| 100 |
array.forEach(this.commands.split(','), function(b, i){ |
| 101 |
switch(b){ |
| 102 |
case "prev": |
| 103 |
cb("Prev", _dojoxRotator + "Prev" + icon, ["prev"]); |
| 104 |
break; |
| 105 |
case "play/pause": |
| 106 |
cb("Play", _play + icon, ["play"]); |
| 107 |
cb("Pause", _pause + icon, ["pause"]); |
| 108 |
break; |
| 109 |
case "info": |
| 110 |
this._info = html.create("li", { |
| 111 |
className: _dojoxRotator + "Info", |
| 112 |
innerHTML: this._buildInfo(r) |
| 113 |
}, ul); |
| 114 |
break; |
| 115 |
case "next": |
| 116 |
cb("Next", _dojoxRotator + "Next" + icon, ["next"]); |
| 117 |
break; |
| 118 |
case "#": |
| 119 |
case "titles": |
| 120 |
for(var j=0; j<r.panes.length; j++){ |
| 121 |
cb( |
| 122 |
b == '#' ? j+1 : r.panes[j].title || "Tab " + (j+1), |
| 123 |
(b == '#' ? _number : _tab) + ' ' + (j == r.idx ? _selected : "") + ' ' + _dojoxRotator + "Pane" + j, |
| 124 |
["go", j] |
| 125 |
); |
| 126 |
} |
| 127 |
break; |
| 128 |
} |
| 129 |
}, this); |
| 130 |
|
| 131 |
|
| 132 |
query("li:first-child", ul).addClass(_dojoxRotator + "First"); |
| 133 |
query("li:last-child", ul).addClass(_dojoxRotator + "Last"); |
| 134 |
|
| 135 |
|
| 136 |
this._togglePlay(); |
| 137 |
|
| 138 |
this._con = connect.connect(r, "onUpdate", this, "_onUpdate"); |
| 139 |
} |
| 140 |
}, |
| 141 |
|
| 142 |
destroy: function(){ |
| 143 |
|
| 144 |
|
| 145 |
connect.disconnect(this._con); |
| 146 |
html.destroy(this._domNode); |
| 147 |
}, |
| 148 |
|
| 149 |
_togglePlay: function(playing){ |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
var p = this.rotator.playing; |
| 154 |
query('.'+_play, this._domNode).style("display", p ? "none" : ""); |
| 155 |
query('.'+_pause, this._domNode).style("display", p ? "" : "none"); |
| 156 |
}, |
| 157 |
|
| 158 |
_buildInfo: function(r){ |
| 159 |
|
| 160 |
|
| 161 |
return '<span>' + (r.idx+1) + ' / ' + r.panes.length + '</span>'; |
| 162 |
}, |
| 163 |
|
| 164 |
_onUpdate: function(type){ |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
var r = this.rotator; |
| 169 |
|
| 170 |
switch(type){ |
| 171 |
case "play": |
| 172 |
case "pause": |
| 173 |
this._togglePlay(); |
| 174 |
break; |
| 175 |
case "onAfterTransition": |
| 176 |
if(this._info){ |
| 177 |
this._info.innerHTML = this._buildInfo(r); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
var s = function(n){ |
| 182 |
if(r.idx < n.length){ |
| 183 |
html.addClass(n[r.idx], _selected); |
| 184 |
} |
| 185 |
}; |
| 186 |
|
| 187 |
s(query('.' + _number, this._domNode).removeClass(_selected)); |
| 188 |
s(query('.' + _tab, this._domNode).removeClass(_selected)); |
| 189 |
break; |
| 190 |
} |
| 191 |
} |
| 192 |
}); |
| 193 |
}); |