f2b2e91edae8dfca72b79f54256bf3b887a56f88.svn-base 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. if (!dojo._hasResource["dojo.fx"]) { // _hasResource checks added by build.
  2. // Do not use _hasResource directly in
  3. // your code.
  4. dojo._hasResource["dojo.fx"] = true;
  5. dojo.provide("dojo.fx");
  6. dojo.provide("dojo.fx.Toggler");
  7. dojo.fx.chain = function(/* dojo._Animation[] */animations) {
  8. // summary: Chain a list of dojo._Animation s to run in sequence
  9. // example:
  10. // | dojo.fx.chain([
  11. // | dojo.fadeIn({ node:node }),
  12. // | dojo.fadeOut({ node:otherNode })
  13. // | ]).play();
  14. //
  15. var first = animations.shift();
  16. var previous = first;
  17. dojo.forEach(animations, function(current) {
  18. dojo.connect(previous, "onEnd", current, "play");
  19. previous = current;
  20. });
  21. return first; // dojo._Animation
  22. };
  23. dojo.fx.combine = function(/* dojo._Animation[] */animations) {
  24. // summary: Combine a list of dojo._Animation s to run in parallel
  25. // example:
  26. // | dojo.fx.combine([
  27. // | dojo.fadeIn({ node:node }),
  28. // | dojo.fadeOut({ node:otherNode })
  29. // | ]).play();
  30. var ctr = new dojo._Animation({
  31. curve : [0, 1]
  32. });
  33. if (!animations.length) {
  34. return ctr;
  35. }
  36. // animations.sort(function(a, b){ return a.duration-b.duration; });
  37. ctr.duration = animations[0].duration;
  38. dojo.forEach(animations, function(current) {
  39. dojo.forEach(["play", "pause", "stop"], function(e) {
  40. if (current[e]) {
  41. dojo.connect(ctr, e, current, e);
  42. }
  43. });
  44. });
  45. return ctr; // dojo._Animation
  46. };
  47. dojo.declare("dojo.fx.Toggler", null, {
  48. // summary:
  49. // class constructor for an animation toggler. It accepts a
  50. // packed
  51. // set of arguments about what type of animation to use in each
  52. // direction, duration, etc.
  53. //
  54. // example:
  55. // | var t = new dojo.fx.Toggler({
  56. // | node: "nodeId",
  57. // | showDuration: 500,
  58. // | // hideDuration will default to "200"
  59. // | showFunc: dojo.wipeIn,
  60. // | // hideFunc will default to "fadeOut"
  61. // | });
  62. // | t.show(100); // delay showing for 100ms
  63. // | // ...time passes...
  64. // | t.hide();
  65. // FIXME: need a policy for where the toggler should "be" the
  66. // next
  67. // time show/hide are called if we're stopped somewhere in the
  68. // middle.
  69. constructor : function(args) {
  70. var _t = this;
  71. dojo.mixin(_t, args);
  72. _t.node = args.node;
  73. _t._showArgs = dojo.mixin({}, args);
  74. _t._showArgs.node = _t.node;
  75. _t._showArgs.duration = _t.showDuration;
  76. _t.showAnim = _t.showFunc(_t._showArgs);
  77. _t._hideArgs = dojo.mixin({}, args);
  78. _t._hideArgs.node = _t.node;
  79. _t._hideArgs.duration = _t.hideDuration;
  80. _t.hideAnim = _t.hideFunc(_t._hideArgs);
  81. dojo.connect(_t.showAnim, "beforeBegin", dojo.hitch(
  82. _t.hideAnim, "stop", true));
  83. dojo.connect(_t.hideAnim, "beforeBegin", dojo.hitch(
  84. _t.showAnim, "stop", true));
  85. },
  86. // node: DomNode
  87. // the node to toggle
  88. node : null,
  89. // showFunc: Function
  90. // The function that returns the dojo._Animation to show the
  91. // node
  92. showFunc : dojo.fadeIn,
  93. // hideFunc: Function
  94. // The function that returns the dojo._Animation to hide the
  95. // node
  96. hideFunc : dojo.fadeOut,
  97. // showDuration:
  98. // Time in milliseconds to run the show Animation
  99. showDuration : 200,
  100. // hideDuration:
  101. // Time in milliseconds to run the hide Animation
  102. hideDuration : 200,
  103. /*
  104. * ===== _showArgs: null, _showAnim: null,
  105. *
  106. * _hideArgs: null, _hideAnim: null,
  107. *
  108. * _isShowing: false, _isHiding: false, =====
  109. */
  110. show : function(delay) {
  111. // summary: Toggle the node to showing
  112. return this.showAnim.play(delay || 0);
  113. },
  114. hide : function(delay) {
  115. // summary: Toggle the node to hidden
  116. return this.hideAnim.play(delay || 0);
  117. }
  118. });
  119. dojo.fx.wipeIn = function(/* Object */args) {
  120. // summary
  121. // Returns an animation that will expand the
  122. // node defined in 'args' object from it's current height to
  123. // it's natural height (with no scrollbar).
  124. // Node must have no margin/border/padding.
  125. args.node = dojo.byId(args.node);
  126. var node = args.node, s = node.style;
  127. var anim = dojo.animateProperty(dojo.mixin({
  128. properties : {
  129. height : {
  130. // wrapped in functions so we wait till the last
  131. // second to query (in case value has changed)
  132. start : function() {
  133. // start at current [computed] height, but use
  134. // 1px rather than 0
  135. // because 0 causes IE to display the whole
  136. // panel
  137. s.overflow = "hidden";
  138. if (s.visibility == "hidden"
  139. || s.display == "none") {
  140. s.height = "1px";
  141. s.display = "";
  142. s.visibility = "";
  143. return 1;
  144. } else {
  145. var height = dojo.style(node, "height");
  146. return Math.max(height, 1);
  147. }
  148. },
  149. end : function() {
  150. return node.scrollHeight;
  151. }
  152. }
  153. }
  154. }, args));
  155. dojo.connect(anim, "onEnd", function() {
  156. s.height = "auto";
  157. });
  158. return anim; // dojo._Animation
  159. }
  160. dojo.fx.wipeOut = function(/* Object */args) {
  161. // summary
  162. // Returns an animation that will shrink node defined in "args"
  163. // from it's current height to 1px, and then hide it.
  164. var node = args.node = dojo.byId(args.node);
  165. var s = node.style;
  166. var anim = dojo.animateProperty(dojo.mixin({
  167. properties : {
  168. height : {
  169. end : 1
  170. // 0 causes IE to display the whole panel
  171. }
  172. }
  173. }, args));
  174. dojo.connect(anim, "beforeBegin", function() {
  175. s.overflow = "hidden";
  176. s.display = "";
  177. });
  178. dojo.connect(anim, "onEnd", function() {
  179. s.height = "auto";
  180. s.display = "none";
  181. });
  182. return anim; // dojo._Animation
  183. }
  184. dojo.fx.slideTo = function(/* Object? */args) {
  185. // summary
  186. // Returns an animation that will slide "node"
  187. // defined in args Object from its current position to
  188. // the position defined by (args.left, args.top).
  189. // example:
  190. // | dojo.fx.slideTo({ node: node, left:"40", top:"50", unit:"px"
  191. // }).play()
  192. var node = (args.node = dojo.byId(args.node));
  193. var top = null;
  194. var left = null;
  195. var init = (function(n) {
  196. return function() {
  197. var cs = dojo.getComputedStyle(n);
  198. var pos = cs.position;
  199. top = (pos == 'absolute' ? n.offsetTop : parseInt(cs.top) || 0);
  200. left = (pos == 'absolute' ? n.offsetLeft : parseInt(cs.left)
  201. || 0);
  202. if (pos != 'absolute' && pos != 'relative') {
  203. var ret = dojo.coords(n, true);
  204. top = ret.y;
  205. left = ret.x;
  206. n.style.position = "absolute";
  207. n.style.top = top + "px";
  208. n.style.left = left + "px";
  209. }
  210. };
  211. })(node);
  212. init();
  213. var anim = dojo.animateProperty(dojo.mixin({
  214. properties : {
  215. top : {
  216. end : args.top || 0
  217. },
  218. left : {
  219. end : args.left || 0
  220. }
  221. }
  222. }, args));
  223. dojo.connect(anim, "beforeBegin", anim, init);
  224. return anim; // dojo._Animation
  225. }
  226. }