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