Wipe.js 2.8 KB

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