| 1 |
define(["dojo/_base/declare","dojo/_base/html","dojo/_base/connect","dojo/_base/lang","dojo/_base/array", |
| 2 |
"dojo/_base/fx","dojo/fx","dijit/_base/manager","dijit/layout/StackContainer","dijit/layout/StackController","dijit/_Widget", |
| 3 |
"dijit/_Templated","dijit/_Contained" |
| 4 |
],function(declare,html,connect,lang,array,baseFx,coreFx,manager, |
| 5 |
StackContainer,StackController,Widget,Templated,Contained){ |
| 6 |
|
| 7 |
var RotatorContainer = declare("dojox.layout.RotatorContainer",[StackContainer, Templated], { |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
templateString: '<div class="dojoxRotatorContainer"><div dojoAttachPoint="tabNode"></div><div class="dojoxRotatorPager" dojoAttachPoint="pagerNode"></div><div class="dojoxRotatorContent" dojoAttachPoint="containerNode"></div></div>', |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
showTabs: true, |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
transitionDelay: 5000, |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
transition: "fade", |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
transitionDuration: 1000, |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
autoStart: true, |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
suspendOnHover: false, |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
pauseOnManualChange: null, |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
reverse: false, |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
pagerId: "", |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
cycles: -1, |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
pagerClass: "dojox.layout.RotatorPager", |
| 85 |
|
| 86 |
postCreate: function(){ |
| 87 |
|
| 88 |
|
| 89 |
this.inherited(arguments); |
| 90 |
|
| 91 |
|
| 92 |
html.style(this.domNode, "position", "relative"); |
| 93 |
|
| 94 |
|
| 95 |
if(this.cycles-0 == this.cycles && this.cycles != -1){ |
| 96 |
|
| 97 |
this.cycles++; |
| 98 |
}else{ |
| 99 |
this.cycles = -1; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
if(this.pauseOnManualChange === null){ |
| 105 |
this.pauseOnManualChange = !this.suspendOnHover; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
var id = this.id || "rotator"+(new Date()).getTime(), |
| 110 |
sc = new StackController({ containerId:id }, this.tabNode); |
| 111 |
this.tabNode = sc.domNode; |
| 112 |
this._stackController = sc; |
| 113 |
html.style(this.tabNode, "display", this.showTabs ? "" : "none"); |
| 114 |
|
| 115 |
|
| 116 |
this.connect(sc, "onButtonClick","_manualChange"); |
| 117 |
|
| 118 |
|
| 119 |
this._subscriptions = [ |
| 120 |
connect.subscribe(this.id+"-cycle", this, "_cycle"), |
| 121 |
connect.subscribe(this.id+"-state", this, "_state") |
| 122 |
]; |
| 123 |
|
| 124 |
|
| 125 |
var d = Math.round(this.transitionDelay * 0.75); |
| 126 |
if(d < this.transitionDuration){ |
| 127 |
this.transitionDuration = d; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
if(this.suspendOnHover){ |
| 132 |
this.connect(this.domNode, "onmouseover", "_onMouseOver"); |
| 133 |
this.connect(this.domNode, "onmouseout", "_onMouseOut"); |
| 134 |
} |
| 135 |
}, |
| 136 |
|
| 137 |
startup: function(){ |
| 138 |
|
| 139 |
|
| 140 |
if(this._started){ return; } |
| 141 |
|
| 142 |
|
| 143 |
var c = this.getChildren(); |
| 144 |
for(var i=0, len=c.length; i<len; i++){ |
| 145 |
if(c[i].declaredClass == this.pagerClass){ |
| 146 |
this.pagerNode.appendChild(c[i].domNode); |
| 147 |
break; |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
this.inherited(arguments); |
| 153 |
|
| 154 |
|
| 155 |
if(this.autoStart){ |
| 156 |
|
| 157 |
setTimeout(lang.hitch(this, "_play"), 10); |
| 158 |
}else{ |
| 159 |
|
| 160 |
this._updatePager(); |
| 161 |
} |
| 162 |
}, |
| 163 |
|
| 164 |
destroy: function(){ |
| 165 |
|
| 166 |
|
| 167 |
array.forEach(this._subscriptions, connect.unsubscribe); |
| 168 |
this.inherited(arguments); |
| 169 |
}, |
| 170 |
|
| 171 |
_setShowTabsAttr: function(value){ |
| 172 |
this.showTabs = value; |
| 173 |
html.style(this.tabNode, "display", value ? "" : "none"); |
| 174 |
}, |
| 175 |
|
| 176 |
_updatePager: function(){ |
| 177 |
|
| 178 |
|
| 179 |
var c = this.getChildren(); |
| 180 |
connect.publish(this.id+"-update", [this._playing, array.indexOf(c, this.selectedChildWidget)+1, c.length]); |
| 181 |
}, |
| 182 |
|
| 183 |
_onMouseOver: function(){ |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
this._resetTimer(); |
| 189 |
this._over = true; |
| 190 |
}, |
| 191 |
|
| 192 |
_onMouseOut: function(){ |
| 193 |
|
| 194 |
|
| 195 |
this._over = false; |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
if(this._playing){ |
| 200 |
clearTimeout(this._timer); |
| 201 |
this._timer = setTimeout(lang.hitch(this, "_play", true), 200); |
| 202 |
} |
| 203 |
}, |
| 204 |
|
| 205 |
_resetTimer: function(){ |
| 206 |
|
| 207 |
|
| 208 |
clearTimeout(this._timer); |
| 209 |
this._timer = null; |
| 210 |
}, |
| 211 |
|
| 212 |
_cycle: function(next){ |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
if(next instanceof Boolean || typeof next == "boolean"){ |
| 219 |
this._manualChange(); |
| 220 |
} |
| 221 |
|
| 222 |
var c = this.getChildren(), |
| 223 |
len = c.length, |
| 224 |
i = array.indexOf(c, this.selectedChildWidget) + (next === false || (next !== true && this.reverse) ? -1 : 1); |
| 225 |
this.selectChild(c[(i < len ? (i < 0 ? len-1 : i) : 0)]); |
| 226 |
this._updatePager(); |
| 227 |
}, |
| 228 |
|
| 229 |
_manualChange: function(){ |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
if(this.pauseOnManualChange){ |
| 234 |
this._playing = false; |
| 235 |
} |
| 236 |
this.cycles = -1; |
| 237 |
}, |
| 238 |
|
| 239 |
_play: function(skip){ |
| 240 |
|
| 241 |
|
| 242 |
this._playing = true; |
| 243 |
this._resetTimer(); |
| 244 |
if(skip !== true && this.cycles>0){ |
| 245 |
this.cycles--; |
| 246 |
} |
| 247 |
if(this.cycles==0){ |
| 248 |
this._pause(); |
| 249 |
}else if((!this.suspendOnHover || !this._over) && this.transitionDelay){ |
| 250 |
|
| 251 |
this._timer = setTimeout(lang.hitch(this, "_cycle"), this.selectedChildWidget.domNode.getAttribute("transitionDelay") || this.transitionDelay); |
| 252 |
} |
| 253 |
this._updatePager(); |
| 254 |
}, |
| 255 |
|
| 256 |
_pause: function(){ |
| 257 |
|
| 258 |
|
| 259 |
this._playing = false; |
| 260 |
this._resetTimer(); |
| 261 |
}, |
| 262 |
|
| 263 |
_state: function(playing){ |
| 264 |
|
| 265 |
|
| 266 |
if(playing){ |
| 267 |
|
| 268 |
this.cycles = -1; |
| 269 |
this._play(); |
| 270 |
}else{ |
| 271 |
this._pause(); |
| 272 |
} |
| 273 |
}, |
| 274 |
|
| 275 |
_transition: function( next, prev){ |
| 276 |
|
| 277 |
|
| 278 |
this._resetTimer(); |
| 279 |
|
| 280 |
|
| 281 |
if(prev && this.transitionDuration){ |
| 282 |
switch(this.transition){ |
| 283 |
case "fade": this._fade(next, prev); return; |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
this._transitionEnd(); |
| 288 |
this.inherited(arguments); |
| 289 |
}, |
| 290 |
|
| 291 |
_transitionEnd: function(){ |
| 292 |
if(this._playing){ |
| 293 |
this._play(); |
| 294 |
}else{ |
| 295 |
this._updatePager(); |
| 296 |
} |
| 297 |
}, |
| 298 |
|
| 299 |
_fade: function( next, prev){ |
| 300 |
|
| 301 |
|
| 302 |
this._styleNode(prev.domNode, 1, 1); |
| 303 |
this._styleNode(next.domNode, 0, 2); |
| 304 |
|
| 305 |
|
| 306 |
this._showChild(next); |
| 307 |
if(this.doLayout && next.resize){ |
| 308 |
next.resize(this._containerContentBox || this._contentBox); |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
var args = { duration:this.transitionDuration }, |
| 313 |
anim = coreFx.combine([ |
| 314 |
baseFx["fadeOut"](lang.mixin({node:prev.domNode}, args)), |
| 315 |
baseFx["fadeIn"](lang.mixin({node:next.domNode}, args)) |
| 316 |
]); |
| 317 |
|
| 318 |
this.connect(anim, "onEnd", lang.hitch(this,function(){ |
| 319 |
this._hideChild(prev); |
| 320 |
this._transitionEnd(); |
| 321 |
})); |
| 322 |
|
| 323 |
anim.play(); |
| 324 |
}, |
| 325 |
|
| 326 |
_styleNode: function(node, opacity, zIndex){ |
| 327 |
|
| 328 |
|
| 329 |
html.style(node, "opacity", opacity); |
| 330 |
html.style(node, "zIndex", zIndex); |
| 331 |
html.style(node, "position", "absolute"); |
| 332 |
} |
| 333 |
}); |
| 334 |
|
| 335 |
declare("dojox.layout.RotatorPager", [Widget, Templated, Contained], { |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
widgetsInTemplate: true, |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
rotatorId: "", |
| 414 |
|
| 415 |
postMixInProperties: function(){ |
| 416 |
this.templateString = "<div>" + this.srcNodeRef.innerHTML + "</div>"; |
| 417 |
}, |
| 418 |
|
| 419 |
postCreate: function(){ |
| 420 |
var p = manager.byId(this.rotatorId) || this.getParent(); |
| 421 |
if(p && p.declaredClass == "dojox.layout.RotatorContainer"){ |
| 422 |
if(this.previous){ |
| 423 |
connect.connect(this.previous, "onClick", function(){ |
| 424 |
connect.publish(p.id+"-cycle", [false]); |
| 425 |
}); |
| 426 |
} |
| 427 |
if(this.next){ |
| 428 |
connect.connect(this.next, "onClick", function(){ |
| 429 |
connect.publish(p.id+"-cycle", [true]); |
| 430 |
}); |
| 431 |
} |
| 432 |
if(this.playPause){ |
| 433 |
connect.connect(this.playPause, "onClick", function(){ |
| 434 |
this.set('label', this.checked ? "Pause" : "Play"); |
| 435 |
connect.publish(p.id+"-state", [this.checked]); |
| 436 |
}); |
| 437 |
} |
| 438 |
this._subscriptions = [ |
| 439 |
connect.subscribe(p.id+"-state", this, "_state"), |
| 440 |
connect.subscribe(p.id+"-update", this, "_update") |
| 441 |
]; |
| 442 |
} |
| 443 |
}, |
| 444 |
|
| 445 |
destroy: function(){ |
| 446 |
|
| 447 |
array.forEach(this._subscriptions, connect.unsubscribe); |
| 448 |
this.inherited(arguments); |
| 449 |
}, |
| 450 |
|
| 451 |
_state: function(playing){ |
| 452 |
|
| 453 |
|
| 454 |
if(this.playPause && this.playPause.checked != playing){ |
| 455 |
this.playPause.set("label", playing ? "Pause" : "Play"); |
| 456 |
this.playPause.set("checked", playing); |
| 457 |
} |
| 458 |
}, |
| 459 |
|
| 460 |
_update: function(playing, current, total){ |
| 461 |
|
| 462 |
|
| 463 |
this._state(playing); |
| 464 |
if(this.current && current){ |
| 465 |
this.current.innerHTML = current; |
| 466 |
} |
| 467 |
if(this.total && total){ |
| 468 |
this.total.innerHTML = total; |
| 469 |
} |
| 470 |
} |
| 471 |
}); |
| 472 |
return RotatorContainer; |
| 473 |
}); |