Wipe.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // wrapped by build app
  2. define("dojox/widget/rotator/Wipe", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.widget.rotator.Wipe");
  4. (function(d){
  5. // Constants used to identify which clip edge is being wiped. The values are
  6. // the index of the clip array that is changed during the animation.
  7. var DOWN = 2,
  8. RIGHT = 3,
  9. UP = 0,
  10. LEFT = 1;
  11. function _clipArray(/*int*/type, /*int*/w, /*int*/h, /*number*/x){
  12. // summary:
  13. // Returns an array containing the down, right, up, and
  14. // left clip region based on the type. If "x" is specified,
  15. // then it is applied to the appropriate clipping edge.
  16. var a = [0, w, 0, 0]; // default to the top edge
  17. if(type == RIGHT){
  18. a = [0, w, h, w];
  19. }else if(type == UP){
  20. a = [h, w, h, 0];
  21. }else if(type == LEFT){
  22. a = [0, 0, h, 0];
  23. }
  24. if(x != null){
  25. a[type] = type == DOWN || type == LEFT ? x : (type % 2 ? w : h) - x;
  26. }
  27. return a; /*Array*/
  28. }
  29. function _setClip(/*DomNode*/n, /*int*/type, /*int*/w, /*int*/h, /*number*/x){
  30. // summary:
  31. // Sets the clip region of the node. If a type is passed in then we
  32. // return a rect(), otherwise return "auto".
  33. d.style(n, "clip", type == null ? "auto" : "rect(" + _clipArray(type, w, h, x).join("px,") + "px)");
  34. }
  35. function _wipe(/*int*/type, /*Object*/args){
  36. // summary:
  37. // Handles the preparation of the dom node and creates the dojo.Animation object.
  38. var node = args.next.node,
  39. w = args.rotatorBox.w,
  40. h = args.rotatorBox.h;
  41. d.style(node, {
  42. display: "",
  43. zIndex: (d.style(args.current.node, "zIndex") || 1) + 1
  44. });
  45. _setClip(node, type, w, h);
  46. return new d.Animation(d.mixin({ /*dojo.Animation*/
  47. node: node,
  48. curve: [0, type % 2 ? w : h],
  49. onAnimate: function(x){
  50. _setClip(node, type, w, h, parseInt(x));
  51. }
  52. }, args));
  53. }
  54. d.mixin(dojox.widget.rotator, {
  55. wipeDown: function(/*Object*/args){
  56. // summary:
  57. // Returns a dojo.Animation that wipes in the next rotator pane from the top.
  58. return _wipe(DOWN, args); /*dojo.Animation*/
  59. },
  60. wipeRight: function(/*Object*/args){
  61. // summary:
  62. // Returns a dojo.Animation that wipes in the next rotator pane from the right.
  63. return _wipe(RIGHT, args); /*dojo.Animation*/
  64. },
  65. wipeUp: function(/*Object*/args){
  66. // summary:
  67. // Returns a dojo.Animation that wipes in the next rotator pane from the bottom.
  68. return _wipe(UP, args); /*dojo.Animation*/
  69. },
  70. wipeLeft: function(/*Object*/args){
  71. // summary:
  72. // Returns a dojo.Animation that wipes in the next rotator pane from the left.
  73. return _wipe(LEFT, args); /*dojo.Animation*/
  74. }
  75. });
  76. })(dojo);
  77. });