NodeList-fx.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. define("dojo/NodeList-fx", ["./_base/NodeList", "./_base/lang", "./_base/connect", "./_base/fx", "./fx"],
  2. function(NodeList, lang, connectLib, baseFx, coreFx) {
  3. // module:
  4. // dojo/NodeList-fx
  5. // summary:
  6. // TODOC
  7. /*=====
  8. dojo["NodeList-fx"] = {
  9. // summary: Adds dojo.fx animation support to dojo.query() by extending the NodeList class
  10. // with additional FX functions. NodeList is the array-like object used to hold query results.
  11. };
  12. // doc alias helpers:
  13. NodeList = dojo.NodeList;
  14. =====*/
  15. lang.extend(NodeList, {
  16. _anim: function(obj, method, args){
  17. args = args||{};
  18. var a = coreFx.combine(
  19. this.map(function(item){
  20. var tmpArgs = { node: item };
  21. lang.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(coreFx, "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(coreFx, "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(coreFx, "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(baseFx, "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(baseFx, "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. // args: Object?
  140. // Additional dojo.Animation arguments to mix into this set with the addition of
  141. // an `auto` parameter.
  142. //
  143. // returns: dojo.Animation|dojo.NodeList
  144. // A special args member `auto` can be passed to automatically play the animation.
  145. // If args.auto is present, the original dojo.NodeList will be returned for further
  146. // chaining. Otherwise the dojo.Animation instance is returned and must be .play()'ed
  147. //
  148. // example:
  149. // | dojo.query(".zork").animateProperty({
  150. // | duration: 500,
  151. // | properties: {
  152. // | color: { start: "black", end: "white" },
  153. // | left: { end: 300 }
  154. // | }
  155. // | }).play();
  156. //
  157. // example:
  158. // | dojo.query(".grue").animateProperty({
  159. // | auto:true,
  160. // | properties: {
  161. // | height:240
  162. // | }
  163. // | }).onclick(handler);
  164. return this._anim(baseFx, "animateProperty", args); // dojo.Animation|dojo.NodeList
  165. },
  166. anim: function( /*Object*/ properties,
  167. /*Integer?*/ duration,
  168. /*Function?*/ easing,
  169. /*Function?*/ onEnd,
  170. /*Integer?*/ delay){
  171. // summary:
  172. // Animate one or more CSS properties for all nodes in this list.
  173. // The returned animation object will already be playing when it
  174. // is returned. See the docs for `dojo.anim` for full details.
  175. // properties: Object
  176. // the properties to animate. does NOT support the `auto` parameter like other
  177. // NodeList-fx methods.
  178. // duration: Integer?
  179. // Optional. The time to run the animations for
  180. // easing: Function?
  181. // Optional. The easing function to use.
  182. // onEnd: Function?
  183. // A function to be called when the animation ends
  184. // delay:
  185. // how long to delay playing the returned animation
  186. // example:
  187. // Another way to fade out:
  188. // | dojo.query(".thinger").anim({ opacity: 0 });
  189. // example:
  190. // animate all elements with the "thigner" class to a width of 500
  191. // pixels over half a second
  192. // | dojo.query(".thinger").anim({ width: 500 }, 700);
  193. var canim = coreFx.combine(
  194. this.map(function(item){
  195. return baseFx.animateProperty({
  196. node: item,
  197. properties: properties,
  198. duration: duration||350,
  199. easing: easing
  200. });
  201. })
  202. );
  203. if(onEnd){
  204. connectLib.connect(canim, "onEnd", onEnd);
  205. }
  206. return canim.play(delay||0); // dojo.Animation
  207. }
  208. });
  209. return NodeList;
  210. });