NodeList-fx.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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["dojo.NodeList-fx"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojo.NodeList-fx"] = true;
  8. dojo.provide("dojo.NodeList-fx");
  9. dojo.require("dojo.fx");
  10. /*=====
  11. dojo["NodeList-fx"] = {
  12. // summary: Adds dojo.fx animation support to dojo.query()
  13. };
  14. =====*/
  15. dojo.extend(dojo.NodeList, {
  16. _anim: function(obj, method, args){
  17. args = args||{};
  18. var a = dojo.fx.combine(
  19. this.map(function(item){
  20. var tmpArgs = { node: item };
  21. dojo.mixin(tmpArgs, args);
  22. return obj[method](tmpArgs);
  23. })
  24. );
  25. return args.auto ? a.play() && this : a; // dojo.Animation|dojo.NodeList
  26. },
  27. wipeIn: function(args){
  28. // summary:
  29. // wipe in all elements of this NodeList via `dojo.fx.wipeIn`
  30. //
  31. // args: Object?
  32. // Additional dojo.Animation arguments to mix into this set with the addition of
  33. // an `auto` parameter.
  34. //
  35. // returns: dojo.Animation|dojo.NodeList
  36. // A special args member `auto` can be passed to automatically play the animation.
  37. // If args.auto is present, the original dojo.NodeList will be returned for further
  38. // chaining. Otherwise the dojo.Animation instance is returned and must be .play()'ed
  39. //
  40. // example:
  41. // Fade in all tables with class "blah":
  42. // | dojo.query("table.blah").wipeIn().play();
  43. //
  44. // example:
  45. // Utilizing `auto` to get the NodeList back:
  46. // | dojo.query(".titles").wipeIn({ auto:true }).onclick(someFunction);
  47. //
  48. return this._anim(dojo.fx, "wipeIn", args); // dojo.Animation|dojo.NodeList
  49. },
  50. wipeOut: function(args){
  51. // summary:
  52. // wipe out all elements of this NodeList via `dojo.fx.wipeOut`
  53. //
  54. // args: Object?
  55. // Additional dojo.Animation arguments to mix into this set with the addition of
  56. // an `auto` parameter.
  57. //
  58. // returns: dojo.Animation|dojo.NodeList
  59. // A special args member `auto` can be passed to automatically play the animation.
  60. // If args.auto is present, the original dojo.NodeList will be returned for further
  61. // chaining. Otherwise the dojo.Animation instance is returned and must be .play()'ed
  62. //
  63. // example:
  64. // Wipe out all tables with class "blah":
  65. // | dojo.query("table.blah").wipeOut().play();
  66. return this._anim(dojo.fx, "wipeOut", args); // dojo.Animation|dojo.NodeList
  67. },
  68. slideTo: function(args){
  69. // summary:
  70. // slide all elements of the node list to the specified place via `dojo.fx.slideTo`
  71. //
  72. // args: Object?
  73. // Additional dojo.Animation arguments to mix into this set with the addition of
  74. // an `auto` parameter.
  75. //
  76. // returns: dojo.Animation|dojo.NodeList
  77. // A special args member `auto` can be passed to automatically play the animation.
  78. // If args.auto is present, the original dojo.NodeList will be returned for further
  79. // chaining. Otherwise the dojo.Animation instance is returned and must be .play()'ed
  80. //
  81. // example:
  82. // | Move all tables with class "blah" to 300/300:
  83. // | dojo.query("table.blah").slideTo({
  84. // | left: 40,
  85. // | top: 50
  86. // | }).play();
  87. return this._anim(dojo.fx, "slideTo", args); // dojo.Animation|dojo.NodeList
  88. },
  89. fadeIn: function(args){
  90. // summary:
  91. // fade in all elements of this NodeList via `dojo.fadeIn`
  92. //
  93. // args: Object?
  94. // Additional dojo.Animation arguments to mix into this set with the addition of
  95. // an `auto` parameter.
  96. //
  97. // returns: dojo.Animation|dojo.NodeList
  98. // A special args member `auto` can be passed to automatically play the animation.
  99. // If args.auto is present, the original dojo.NodeList will be returned for further
  100. // chaining. Otherwise the dojo.Animation instance is returned and must be .play()'ed
  101. //
  102. // example:
  103. // Fade in all tables with class "blah":
  104. // | dojo.query("table.blah").fadeIn().play();
  105. return this._anim(dojo, "fadeIn", args); // dojo.Animation|dojo.NodeList
  106. },
  107. fadeOut: function(args){
  108. // summary:
  109. // fade out all elements of this NodeList via `dojo.fadeOut`
  110. //
  111. // args: Object?
  112. // Additional dojo.Animation arguments to mix into this set with the addition of
  113. // an `auto` parameter.
  114. //
  115. // returns: dojo.Animation|dojo.NodeList
  116. // A special args member `auto` can be passed to automatically play the animation.
  117. // If args.auto is present, the original dojo.NodeList will be returned for further
  118. // chaining. Otherwise the dojo.Animation instance is returned and must be .play()'ed
  119. //
  120. // example:
  121. // Fade out all elements with class "zork":
  122. // | dojo.query(".zork").fadeOut().play();
  123. // example:
  124. // Fade them on a delay and do something at the end:
  125. // | var fo = dojo.query(".zork").fadeOut();
  126. // | dojo.connect(fo, "onEnd", function(){ /*...*/ });
  127. // | fo.play();
  128. // example:
  129. // Using `auto`:
  130. // | dojo.query("li").fadeOut({ auto:true }).filter(filterFn).forEach(doit);
  131. //
  132. return this._anim(dojo, "fadeOut", args); // dojo.Animation|dojo.NodeList
  133. },
  134. animateProperty: function(args){
  135. // summary:
  136. // Animate all elements of this NodeList across the properties specified.
  137. // syntax identical to `dojo.animateProperty`
  138. //
  139. // returns: dojo.Animation|dojo.NodeList
  140. // A special args member `auto` can be passed to automatically play the animation.
  141. // If args.auto is present, the original dojo.NodeList will be returned for further
  142. // chaining. Otherwise the dojo.Animation instance is returned and must be .play()'ed
  143. //
  144. // example:
  145. // | dojo.query(".zork").animateProperty({
  146. // | duration: 500,
  147. // | properties: {
  148. // | color: { start: "black", end: "white" },
  149. // | left: { end: 300 }
  150. // | }
  151. // | }).play();
  152. //
  153. // example:
  154. // | dojo.query(".grue").animateProperty({
  155. // | auto:true,
  156. // | properties: {
  157. // | height:240
  158. // | }
  159. // | }).onclick(handler);
  160. return this._anim(dojo, "animateProperty", args); // dojo.Animation|dojo.NodeList
  161. },
  162. anim: function( /*Object*/ properties,
  163. /*Integer?*/ duration,
  164. /*Function?*/ easing,
  165. /*Function?*/ onEnd,
  166. /*Integer?*/ delay){
  167. // summary:
  168. // Animate one or more CSS properties for all nodes in this list.
  169. // The returned animation object will already be playing when it
  170. // is returned. See the docs for `dojo.anim` for full details.
  171. // properties: Object
  172. // the properties to animate. does NOT support the `auto` parameter like other
  173. // NodeList-fx methods.
  174. // duration: Integer?
  175. // Optional. The time to run the animations for
  176. // easing: Function?
  177. // Optional. The easing function to use.
  178. // onEnd: Function?
  179. // A function to be called when the animation ends
  180. // delay:
  181. // how long to delay playing the returned animation
  182. // example:
  183. // Another way to fade out:
  184. // | dojo.query(".thinger").anim({ opacity: 0 });
  185. // example:
  186. // animate all elements with the "thigner" class to a width of 500
  187. // pixels over half a second
  188. // | dojo.query(".thinger").anim({ width: 500 }, 700);
  189. var canim = dojo.fx.combine(
  190. this.map(function(item){
  191. return dojo.animateProperty({
  192. node: item,
  193. properties: properties,
  194. duration: duration||350,
  195. easing: easing
  196. });
  197. })
  198. );
  199. if(onEnd){
  200. dojo.connect(canim, "onEnd", onEnd);
  201. }
  202. return canim.play(delay||0); // dojo.Animation
  203. }
  204. });
  205. }