FisheyeLite.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. define("dojox/widget/FisheyeLite", ["dojo", "dojox", "dijit/_Widget", "dojo/fx/easing"], function(dojo, dojox, widget, easing){
  2. dojo.getObject("widget", true, dojox);
  3. dojo.experimental("dojox.widget.FisheyeLite");
  4. return dojo.declare("dojox.widget.FisheyeLite",
  5. dijit._Widget,
  6. {
  7. // summary: A Light-weight Fisheye Component, or an exhanced version
  8. // of dojo.fx.Toggler ...
  9. //
  10. // description:
  11. // A Simple FisheyeList-like widget which (in the interest of
  12. // performance) relies on well-styled content for positioning,
  13. // and natural page layout for rendering.
  14. //
  15. // use position:absolute/relative nodes to prevent layout
  16. // changes, and use caution when seleting properties to
  17. // scale. Negative scaling works, but some properties
  18. // react poorly to being set to negative values, IE being
  19. // particularly annoying in that regard.
  20. //
  21. // quirk: uses the domNode as the target of the animation
  22. // unless it finds a node class="fisheyeTarget" in the container
  23. // being turned into a FisheyeLite instance
  24. //
  25. // example:
  26. // | // make all the LI's in a node Fisheye's:
  27. // | dojo.query("#node li").forEach(function(n){
  28. // | new dojox.widget.FisheyeLite({},n);
  29. // | });
  30. //
  31. //
  32. // example:
  33. // | new dojox.widget.FisheyeLite({
  34. // | properties:{
  35. // | // height is literal, width is multiplied
  36. // | height:{ end: 200 }, width:2.3
  37. // | }
  38. // | }, "someNode");
  39. //
  40. // duationIn: Integer
  41. // The time (in ms) the run the show animation
  42. durationIn: 350,
  43. // easeIn: Function
  44. // An easing function to use for the show animation
  45. easeIn: easing.backOut,
  46. // durationOut: Integer
  47. // The Time (in ms) to run the hide animation
  48. durationOut: 1420,
  49. // easeOut: Function
  50. // An easing function to use for the hide animation
  51. easeOut: easing.elasticOut,
  52. // properties: Object
  53. // An object of "property":scale pairs, or "property":{} pairs.
  54. // defaults to font-size with a scale of 2.75
  55. // If a named property is an integer or float, the "scale multiplier"
  56. // is used. If the named property is an object, that object is mixed
  57. // into the animation directly. eg: height:{ end:20, units:"em" }
  58. properties: null,
  59. // units: String
  60. // Sometimes, you need to specify a unit. Should be part of
  61. // properties attrib, but was trying to shorthand the logic there
  62. units:"px",
  63. constructor: function(props, node){
  64. this.properties = props.properties || {
  65. fontSize: 2.75
  66. }
  67. },
  68. postCreate: function(){
  69. this.inherited(arguments);
  70. this._target = dojo.query(".fisheyeTarget", this.domNode)[0] || this.domNode;
  71. this._makeAnims();
  72. this.connect(this.domNode, "onmouseover", "show");
  73. this.connect(this.domNode, "onmouseout", "hide");
  74. this.connect(this._target, "onclick", "onClick");
  75. },
  76. show: function(){
  77. // summary:
  78. // Show this Fisheye item.
  79. this._runningOut.stop();
  80. this._runningIn.play();
  81. },
  82. hide: function(){
  83. // summary:
  84. // Hide this fisheye item on mouse leave
  85. this._runningIn.stop();
  86. this._runningOut.play();
  87. },
  88. _makeAnims: function(){
  89. // summary:
  90. // Pre-generate the animations
  91. // create two properties: objects, one for each "state"
  92. var _in = {}, _out = {}, cs = dojo.getComputedStyle(this._target);
  93. for(var p in this.properties){
  94. var prop = this.properties[p],
  95. deep = dojo.isObject(prop),
  96. v = parseInt(cs[p])
  97. ;
  98. // note: do not set negative scale for [a list of properties] for IE support
  99. // note: filter:'s are your own issue, too ;)
  100. // FIXME: this.unit here is bad, likely. d._toPixelValue ?
  101. _out[p] = { end: v, units:this.units };
  102. _in[p] = deep ? prop : { end: prop * v, units:this.units };
  103. }
  104. this._runningIn = dojo.animateProperty({
  105. node: this._target,
  106. easing: this.easeIn,
  107. duration: this.durationIn,
  108. properties: _in
  109. });
  110. this._runningOut = dojo.animateProperty({
  111. node: this._target,
  112. duration: this.durationOut,
  113. easing: this.easeOut,
  114. properties: _out
  115. });
  116. this.connect(this._runningIn, "onEnd", dojo.hitch(this, "onSelected", this));
  117. },
  118. onClick: function(/* Event */e){
  119. // summary: stub function fired when target is clicked
  120. // connect or override to use.
  121. },
  122. onSelected: function(/* Object */e){
  123. // summary: stub function fired when Fisheye Item is fully visible and
  124. // hovered. connect or override use.
  125. }
  126. });
  127. });