Gallery.js 6.4 KB

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