ThumbnailController.js 3.1 KB

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