Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.image.Gallery"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.image.Gallery"] = true;
3
dojo.provide("dojox.image.Gallery");
4
dojo.experimental("dojox.image.Gallery");
5
//
6
// dojox.image.Gallery courtesy Shane O Sullivan, licensed under a Dojo CLA
7
// @author  Copyright 2007 Shane O Sullivan (shaneosullivan1@gmail.com)
8
//
9
// For a sample usage, see http://www.skynet.ie/~sos/photos.php
10
//
11
//	TODO: Make public, document params and privitize non-API conformant methods.
12
//	document topics.
13
 
14
dojo.require("dojo.fx");
15
dojo.require("dijit._Widget");
16
dojo.require("dijit._Templated");
17
dojo.require("dojox.image.ThumbnailPicker");
18
dojo.require("dojox.image.SlideShow");
19
 
20
dojo.declare("dojox.image.Gallery",
21
	[dijit._Widget, dijit._Templated],
22
	{
23
	// summary:
24
	//	Gallery widget that wraps a dojox.image.ThumbnailPicker and dojox.image.SlideShow widget
25
 
26
	// imageHeight: Number
27
	//	Maximum height of an image in the SlideShow widget
28
	imageHeight: 375,
29
 
30
	// imageWidth: Number
31
	//	Maximum width of an image in the SlideShow widget
32
	imageWidth: 500,
33
 
34
	// pageSize: Number
35
	//	The number of records to retrieve from the data store per request.
36
	pageSize: dojox.image.SlideShow.prototype.pageSize,
37
 
38
	// autoLoad: Boolean
39
	//	If true, images are loaded before the user views them. If false, an
40
	//	image is loaded when the user displays it.
41
	autoLoad: true,
42
 
43
	// linkAttr: String
44
	//	Defines the name of the attribute to request from the store to retrieve the
45
	//	URL to link to from an image, if any.
46
	linkAttr: "link",
47
 
48
	// imageThumbAttr: String
49
	//	Defines the name of the attribute to request from the store to retrieve the
50
	//	URL to the thumbnail image.
51
	imageThumbAttr: "imageUrlThumb",
52
 
53
	// imageLargeAttr: String
54
	//	Defines the name of the attribute to request from the store to retrieve the
55
	//	URL to the image.
56
	imageLargeAttr: "imageUrl",
57
 
58
	// titleAttr: String
59
	//	Defines the name of the attribute to request from the store to retrieve the
60
	//	title of the picture, if any.
61
	titleAttr: "title",
62
 
63
	// slideshowInterval: Integer
64
	//	time in seconds, between image changes in the slide show.
65
	slideshowInterval: 3,
66
 
67
	templateString:"<div dojoAttachPoint=\"outerNode\" class=\"imageGalleryWrapper\">\n\t<div dojoAttachPoint=\"thumbPickerNode\"></div>\n\t<div dojoAttachPoint=\"slideShowNode\"></div>\n</div>\n",
68
 
69
	postCreate: function(){
70
		// summary: Initializes the widget, creates the ThumbnailPicker and SlideShow widgets
71
		this.widgetid = this.id;
72
		this.inherited("postCreate",arguments)
73
 
74
		this.thumbPicker = new dojox.image.ThumbnailPicker({
75
			linkAttr: this.linkAttr,
76
			imageLargeAttr: this.imageLargeAttr,
77
			titleAttr: this.titleAttr,
78
			useLoadNotifier: true
79
		}, this.thumbPickerNode);
80
 
81
 
82
		this.slideShow = new dojox.image.SlideShow({
83
			imageHeight: this.imageHeight,
84
			imageWidth: this.imageWidth,
85
			autoLoad: this.autoLoad,
86
			linkAttr: this.linkAttr,
87
			imageLargeAttr: this.imageLargeAttr,
88
			titleAttr: this.titleAttr,
89
			slideshowInterval: this.slideshowInterval,
90
			pageSize: this.pageSize
91
		}, this.slideShowNode);
92
 
93
		var _this = this;
94
		//When an image is shown in the Slideshow, make sure it is visible
95
		//in the ThumbnailPicker
96
		dojo.subscribe(this.slideShow.getShowTopicName(), function(packet){
97
			//if(packet.index < _this.thumbPicker._thumbIndex
98
			//   || packet.index > _this.thumbPicker._thumbIndex + _this.thumbPicker.numberThumbs -1){
99
			//if(!_this.thumbPicker.isVisible(packet.index)){
100
				//var index = packet.index - (packet.index % _this.thumbPicker.numberThumbs);
101
				_this.thumbPicker._showThumbs(packet.index);
102
			//}
103
		});
104
		//When the user clicks a thumbnail, show that image
105
		dojo.subscribe(this.thumbPicker.getClickTopicName(), function(evt){
106
			_this.slideShow.showImage(evt.index);
107
		});
108
		//When the ThumbnailPicker moves to show a new set of pictures,
109
		//make the Slideshow start loading those pictures first.
110
		dojo.subscribe(this.thumbPicker.getShowTopicName(), function(evt){
111
			_this.slideShow.moveImageLoadingPointer(evt.index);
112
		});
113
		//When an image finished loading in the slideshow, update the loading
114
		//notification in the ThumbnailPicker
115
		dojo.subscribe(this.slideShow.getLoadTopicName(), function(index){
116
			_this.thumbPicker.markImageLoaded(index);
117
		});
118
		this._centerChildren();
119
	},
120
 
121
  	setDataStore: function(dataStore, request, /*optional*/paramNames){
122
		// summary: Sets the data store and request objects to read data from.
123
		// dataStore:
124
		//	An implementation of the dojo.data.api.Read API. This accesses the image
125
		//	data.
126
		// request:
127
		//	An implementation of the dojo.data.api.Request API. This specifies the
128
		//	query and paging information to be used by the data store
129
		// paramNames:
130
		//	An object defining the names of the item attributes to fetch from the
131
		//	data store.  The four attributes allowed are 'linkAttr', 'imageLargeAttr',
132
		//	'imageThumbAttr' and 'titleAttr'
133
		this.thumbPicker.setDataStore(dataStore, request, paramNames);
134
		this.slideShow.setDataStore(dataStore, request, paramNames);
135
  	},
136
 
137
  	reset: function(){
138
		// summary: Resets the widget to its initial state
139
		this.slideShow.reset();
140
		this.thumbPicker.reset();
141
  	},
142
 
143
	showNextImage: function(inTimer){
144
		// summary: Changes the image being displayed in the SlideShow to the next
145
		//	image in the data store
146
		// inTimer: Boolean
147
		//	If true, a slideshow is active, otherwise the slideshow is inactive.
148
		this.slideShow.showNextImage();
149
	},
150
 
151
	toggleSlideshow: function(){
152
		// summary: Switches the slideshow mode on and off.
153
		this.slideShow.toggleSlideshow();
154
	},
155
 
156
	showImage: function(index, /*optional*/callback){
157
		// summary: Shows the image at index 'idx'.
158
		// idx: Number
159
		//	The position of the image in the data store to display
160
		// callback: Function
161
		//	Optional callback function to call when the image has finished displaying.
162
		this.slideShow.showImage(index, callback);
163
	},
164
 
165
	_centerChildren: function() {
166
		// summary: Ensures that the ThumbnailPicker and the SlideShow widgets
167
		//	are centered.
168
		var thumbSize = dojo.marginBox(this.thumbPicker.outerNode);
169
		var slideSize = dojo.marginBox(this.slideShow.outerNode);
170
 
171
		var diff = (thumbSize.w - slideSize.w) / 2;
172
 
173
		if(diff > 0) {
174
			dojo.style(this.slideShow.outerNode, "marginLeft", diff + "px");
175
		} else if(diff < 0) {
176
			dojo.style(this.thumbPicker.outerNode, "marginLeft", (diff * -1) + "px");
177
		}
178
	}
179
});
180
 
181
}