ThumbnailController.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // wrapped by build app
  2. define("dojox/widget/rotator/ThumbnailController", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.widget.rotator.ThumbnailController");
  4. (function(d){
  5. var _css = "dojoxRotatorThumb",
  6. _selected = _css + "Selected";
  7. d.declare("dojox.widget.rotator.ThumbnailController", null, {
  8. // summary:
  9. // A rotator controller that displays thumbnails of each rotator pane.
  10. //
  11. // description:
  12. // The ThumbnailController will look at each of the rotator's panes and
  13. // only if the node is an <img> tag, then it will create an thumbnail of
  14. // the pane's image using the <img> tag's "thumbsrc" or "src" attribute.
  15. //
  16. // The size of the thumbnails and the style of the selected thumbnail is
  17. // controlled using CSS.
  18. //
  19. // example:
  20. // | <div dojoType="dojox.widget.Rotator" jsId="myRotator">
  21. // | <img src="/path/to/image1.jpg" thumbsrc="/path/to/thumb1.jpg" alt="Image 1"/>
  22. // | <img src="/path/to/image2.jpg" thumbsrc="/path/to/thumb2.jpg" alt="Image 2"/>
  23. // | </div>
  24. // | <div dojoType="dojox.widget.rotator.ThumbnailController" rotator="myRotator"></div>
  25. // rotator: dojox.widget.Rotator
  26. // An instance of a Rotator widget.
  27. rotator: null,
  28. constructor: function(/*Object*/params, /*DomNode|string*/node){
  29. // summary:
  30. // Initializes the thumbnails and connect to the rotator.
  31. d.mixin(this, params);
  32. this._domNode = node;
  33. // check if we have a valid rotator
  34. var r = this.rotator;
  35. if(r){
  36. // remove all of the controller's child nodes just in case
  37. while(node.firstChild){
  38. node.removeChild(node.firstChild);
  39. }
  40. for(var i=0; i<r.panes.length; i++){
  41. var n = r.panes[i].node,
  42. s = d.attr(n, "thumbsrc") || d.attr(n, "src"),
  43. t = d.attr(n, "alt") || "";
  44. if(/img/i.test(n.tagName)){
  45. (function(j){
  46. d.create("a", {
  47. classname: _css + ' ' + _css + j + ' ' + (j == r.idx ? _selected : ""),
  48. href: s,
  49. onclick: function(e){
  50. d.stopEvent(e);
  51. if(r){
  52. r.control.apply(r, ["go", j]);
  53. }
  54. },
  55. title: t,
  56. innerHTML: '<img src="' + s + '" alt="' + t + '"/>'
  57. }, node);
  58. })(i);
  59. }
  60. }
  61. this._con = d.connect(r, "onUpdate", this, "_onUpdate");
  62. }
  63. },
  64. destroy: function(){
  65. // summary:
  66. // Disconnect from the rotator.
  67. d.disconnect(this._con);
  68. d.destroy(this._domNode);
  69. },
  70. _onUpdate: function(/*string*/type){
  71. // summary:
  72. // Updates various pager controls when the rotator updates.
  73. var r = this.rotator; // no need to test if this is null since _onUpdate is only fired by the rotator
  74. if(type == "onAfterTransition"){
  75. var n = d.query('.' + _css, this._domNode).removeClass(_selected);
  76. if(r.idx < n.length){
  77. d.addClass(n[r.idx], _selected);
  78. }
  79. }
  80. }
  81. });
  82. })(dojo);
  83. });