1318 |
alexandre_ |
1 |
/*
|
|
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
|
|
3 |
All Rights Reserved.
|
|
|
4 |
|
|
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
|
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
|
|
7 |
|
|
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
|
|
9 |
*/
|
|
|
10 |
|
1422 |
alexandre_ |
11 |
|
|
|
12 |
|
1318 |
alexandre_ |
13 |
dojo.provide("dojo.widget.SlideShow");
|
|
|
14 |
dojo.require("dojo.event.*");
|
|
|
15 |
dojo.require("dojo.widget.*");
|
|
|
16 |
dojo.require("dojo.lfx.*");
|
|
|
17 |
dojo.require("dojo.html.display");
|
|
|
18 |
dojo.widget.defineWidget("dojo.widget.SlideShow", dojo.widget.HtmlWidget, {templateString:"<div style=\"position: relative; padding: 3px;\">\n\t\t<div>\n\t\t\t<input type=\"button\" value=\"pause\" \n\t\t\t\tdojoAttachPoint=\"startStopButton\"\n\t\t\t\tdojoAttachEvent=\"onClick: togglePaused;\">\n\t\t</div>\n\t\t<div style=\"position: relative; width: ${this.width}; height: ${this.height};\"\n\t\t\tdojoAttachPoint=\"imagesContainer\"\n\t\t\tdojoAttachEvent=\"onClick: togglePaused;\">\n\t\t\t<img dojoAttachPoint=\"img1\" class=\"slideShowImg\" \n\t\t\t\tstyle=\"z-index: 1; width: ${this.width}; height: ${this.height};\" />\n\t\t\t<img dojoAttachPoint=\"img2\" class=\"slideShowImg\" \n\t\t\t\tstyle=\"z-index: 0; width: ${this.width}; height: ${this.height};\" />\n\t\t</div>\t\n</div>\n", templateCssString:".slideShowImg {\n\tposition: absolute;\n\tleft: 0px;\n\ttop: 0px; \n\tborder: 2px solid #4d4d4d;\n\tpadding: 0px;\n\tmargin: 0px;\n}\n\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/SlideShow.css"), imgUrls:[], imgUrlBase:"", delay:4000, transitionInterval:2000, imgWidth:800, imgHeight:600, preventCache:false, stopped:false, _urlsIdx:0, _background:"img2", _foreground:"img1", fadeAnim:null, startStopButton:null, img1:null, img2:null, postMixInProperties:function () {
|
|
|
19 |
this.width = this.imgWidth + "px";
|
|
|
20 |
this.height = this.imgHeight + "px";
|
|
|
21 |
}, fillInTemplate:function () {
|
|
|
22 |
if (dojo.render.html.safari && this.imgUrls.length == 2) {
|
|
|
23 |
this.preventCache = true;
|
|
|
24 |
}
|
|
|
25 |
dojo.html.setOpacity(this.img1, 0.9999);
|
|
|
26 |
dojo.html.setOpacity(this.img2, 0.9999);
|
|
|
27 |
if (this.imgUrls.length > 1) {
|
|
|
28 |
this.img2.src = this.imgUrlBase + this.imgUrls[this._urlsIdx++] + this._getUrlSuffix();
|
|
|
29 |
this._endTransition();
|
|
|
30 |
} else {
|
|
|
31 |
this.img1.src = this.imgUrlBase + this.imgUrls[this._urlsIdx++] + this._getUrlSuffix();
|
|
|
32 |
}
|
|
|
33 |
}, _getUrlSuffix:function () {
|
|
|
34 |
if (this.preventCache) {
|
|
|
35 |
return "?ts=" + (new Date()).getTime();
|
|
|
36 |
} else {
|
|
|
37 |
return "";
|
|
|
38 |
}
|
|
|
39 |
}, togglePaused:function () {
|
|
|
40 |
if (this.stopped) {
|
|
|
41 |
this.stopped = false;
|
|
|
42 |
this._backgroundImageLoaded();
|
|
|
43 |
this.startStopButton.value = "pause";
|
|
|
44 |
} else {
|
|
|
45 |
this.stopped = true;
|
|
|
46 |
this.startStopButton.value = "play";
|
|
|
47 |
}
|
|
|
48 |
}, _backgroundImageLoaded:function () {
|
|
|
49 |
if (this.stopped) {
|
|
|
50 |
return;
|
|
|
51 |
}
|
|
|
52 |
if (this.fadeAnim) {
|
|
|
53 |
this.fadeAnim.stop();
|
|
|
54 |
}
|
|
|
55 |
this.fadeAnim = dojo.lfx.fadeOut(this[this._foreground], this.transitionInterval, null);
|
|
|
56 |
dojo.event.connect(this.fadeAnim, "onEnd", this, "_endTransition");
|
|
|
57 |
this.fadeAnim.play();
|
|
|
58 |
}, _endTransition:function () {
|
|
|
59 |
with (this[this._background].style) {
|
|
|
60 |
zIndex = parseInt(zIndex) + 1;
|
|
|
61 |
}
|
|
|
62 |
with (this[this._foreground].style) {
|
|
|
63 |
zIndex = parseInt(zIndex) - 1;
|
|
|
64 |
}
|
|
|
65 |
var tmp = this._foreground;
|
|
|
66 |
this._foreground = this._background;
|
|
|
67 |
this._background = tmp;
|
|
|
68 |
this._loadNextImage();
|
|
|
69 |
}, _loadNextImage:function () {
|
|
|
70 |
dojo.event.kwConnect({srcObj:this[this._background], srcFunc:"onload", adviceObj:this, adviceFunc:"_backgroundImageLoaded", once:true, delay:this.delay});
|
|
|
71 |
dojo.html.setOpacity(this[this._background], 1);
|
|
|
72 |
this[this._background].src = this.imgUrlBase + this.imgUrls[this._urlsIdx++];
|
|
|
73 |
if (this._urlsIdx > (this.imgUrls.length - 1)) {
|
|
|
74 |
this._urlsIdx = 0;
|
|
|
75 |
}
|
|
|
76 |
}});
|
|
|
77 |
|