source: Dev/branches/rest-dojo-ui/client/dojox/image/Gallery.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

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