Gallery.js 6.7 KB

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