FisheyeLite.js 4.6 KB

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