PanFade.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. // wrapped by build app
  2. define("dojox/widget/rotator/PanFade", ["dijit","dojo","dojox","dojo/require!dojo/fx"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.widget.rotator.PanFade");
  4. dojo.require("dojo.fx");
  5. (function(d){
  6. // Constants used to identify which edge the pane pans in from.
  7. var DOWN = 0,
  8. RIGHT = 1,
  9. UP = 2,
  10. LEFT = 3;
  11. function _pan(/*int*/type, /*Object*/args){
  12. // summary:
  13. // Handles the preparation of the dom node and creates the dojo.Animation object.
  14. var j = {
  15. node: args.current.node,
  16. duration: args.duration,
  17. easing: args.easing
  18. },
  19. k = {
  20. node: args.next.node,
  21. duration: args.duration,
  22. easing: args.easing
  23. },
  24. r = args.rotatorBox,
  25. m = type % 2,
  26. a = m ? "left" : "top",
  27. s = (m ? r.w : r.h) * (type < 2 ? -1 : 1),
  28. p = {},
  29. q = {};
  30. d.style(k.node, {
  31. display: "",
  32. opacity: 0
  33. });
  34. p[a] = {
  35. start: 0,
  36. end: -s
  37. };
  38. q[a] = {
  39. start: s,
  40. end: 0
  41. };
  42. return d.fx.combine([ /*dojo.Animation*/
  43. d.animateProperty(d.mixin({ properties: p }, j)),
  44. d.fadeOut(j),
  45. d.animateProperty(d.mixin({ properties: q }, k)),
  46. d.fadeIn(k)
  47. ]);
  48. }
  49. function _setZindex(/*DomNode*/n, /*int*/z){
  50. // summary:
  51. // Helper function for continuously panning.
  52. d.style(n, "zIndex", z);
  53. }
  54. d.mixin(dojox.widget.rotator, {
  55. panFade: function(/*Object*/args){
  56. // summary:
  57. // Returns a dojo.Animation that either pans left or right to the next pane.
  58. // The actual direction depends on the order of the panes.
  59. //
  60. // If panning forward from index 1 to 3, it will perform a pan left. If panning
  61. // backwards from 5 to 1, then it will perform a pan right.
  62. //
  63. // If the parameter "continuous" is set to true, it will return an animation
  64. // chain of several pan animations of each intermediate pane panning. For
  65. // example, if you pan forward from 1 to 3, it will return an animation panning
  66. // left from 1 to 2 and then 2 to 3.
  67. //
  68. // If an easing is specified, it will be applied to each pan transition. For
  69. // example, if you are panning from pane 1 to pane 5 and you set the easing to
  70. // "dojo.fx.easing.elasticInOut", then it will "wobble" 5 times, once for each
  71. // pan transition.
  72. //
  73. // If the parameter "wrap" is set to true, it will pan to the next pane using
  74. // the shortest distance in the array of panes. For example, if there are 6
  75. // panes, then panning from 5 to 1 will pan forward (left) from pane 5 to 6 and
  76. // 6 to 1. If the distance is the same either going forward or backwards, then
  77. // it will always pan forward (left).
  78. //
  79. // A continuous pan will use the target pane's duration to pan all intermediate
  80. // panes. To use the target's pane duration for each intermediate pane, then
  81. // set the "quick" parameter to "false".
  82. var w = args.wrap,
  83. p = args.rotator.panes,
  84. len = p.length,
  85. z = len,
  86. j = args.current.idx,
  87. k = args.next.idx,
  88. nw = Math.abs(k - j),
  89. ww = Math.abs((len - Math.max(j, k)) + Math.min(j, k)) % len,
  90. _forward = j < k,
  91. _dir = LEFT,
  92. _pans = [],
  93. _nodes = [],
  94. _duration = args.duration;
  95. // default to pan left, but check if we should pan right.
  96. // need to take into account wrapping.
  97. if((!w && !_forward) || (w && (_forward && nw > ww || !_forward && nw < ww))){
  98. _dir = RIGHT;
  99. }
  100. if(args.continuous){
  101. // if continuous pans are quick, then divide the duration by the number of panes
  102. if(args.quick){
  103. _duration = Math.round(_duration / (w ? Math.min(ww, nw) : nw));
  104. }
  105. // set the current pane's z-index
  106. _setZindex(p[j].node, z--);
  107. var f = (_dir == LEFT);
  108. // loop and set z-indexes and get all pan animations
  109. while(1){
  110. // set the current pane
  111. var i = j;
  112. // increment/decrement the next pane's index
  113. if(f){
  114. if(++j >= len){
  115. j = 0;
  116. }
  117. }else{
  118. if(--j < 0){
  119. j = len - 1;
  120. }
  121. }
  122. var x = p[i],
  123. y = p[j];
  124. // set next pane's z-index
  125. _setZindex(y.node, z--);
  126. // build the pan animation
  127. _pans.push(_pan(_dir, d.mixin({
  128. easing: function(m){ return m; } // continuous gets a linear easing by default
  129. }, args, {
  130. current: x,
  131. next: y,
  132. duration: _duration
  133. })));
  134. // if we're done, then break out of the loop
  135. if((f && j == k) || (!f && j == k)){
  136. break;
  137. }
  138. // this must come after the break... we don't want the last pane to get it's
  139. // styles reset.
  140. _nodes.push(y.node);
  141. }
  142. // build the chained animation of all pan animations
  143. var _anim = d.fx.chain(_pans),
  144. // clean up styles when the chained animation finishes
  145. h = d.connect(_anim, "onEnd", function(){
  146. d.disconnect(h);
  147. d.forEach(_nodes, function(q){
  148. d.style(q, {
  149. display: "none",
  150. left: 0,
  151. opacity: 1,
  152. top: 0,
  153. zIndex: 0
  154. });
  155. });
  156. });
  157. return _anim;
  158. }
  159. // we're not continuous, so just return a normal pan animation
  160. return _pan(_dir, args); /*dojo.Animation*/
  161. },
  162. panFadeDown: function(/*Object*/args){
  163. // summary:
  164. // Returns a dojo.Animation that pans in the next rotator pane from the top.
  165. return _pan(DOWN, args); /*dojo.Animation*/
  166. },
  167. panFadeRight: function(/*Object*/args){
  168. // summary:
  169. // Returns a dojo.Animation that pans in the next rotator pane from the right.
  170. return _pan(RIGHT, args); /*dojo.Animation*/
  171. },
  172. panFadeUp: function(/*Object*/args){
  173. // summary:
  174. // Returns a dojo.Animation that pans in the next rotator pane from the bottom.
  175. return _pan(UP, args); /*dojo.Animation*/
  176. },
  177. panFadeLeft: function(/*Object*/args){
  178. // summary:
  179. // Returns a dojo.Animation that pans in the next rotator pane from the left.
  180. return _pan(LEFT, args); /*dojo.Animation*/
  181. }
  182. });
  183. })(dojo);
  184. });