1 | define(["../_base/lang","../_base/declare","../_base/fx", "../_base/connect"], |
---|
2 | function(lang, declare, baseFx, connectUtil) { |
---|
3 | // module: |
---|
4 | // dojo/fx/Toggler |
---|
5 | // summary: |
---|
6 | // TODOC |
---|
7 | |
---|
8 | return declare("dojo.fx.Toggler", null, { |
---|
9 | // summary: |
---|
10 | // A simple `dojo.Animation` toggler API. |
---|
11 | // |
---|
12 | // description: |
---|
13 | // class constructor for an animation toggler. It accepts a packed |
---|
14 | // set of arguments about what type of animation to use in each |
---|
15 | // direction, duration, etc. All available members are mixed into |
---|
16 | // these animations from the constructor (for example, `node`, |
---|
17 | // `showDuration`, `hideDuration`). |
---|
18 | // |
---|
19 | // example: |
---|
20 | // | var t = new dojo.fx.Toggler({ |
---|
21 | // | node: "nodeId", |
---|
22 | // | showDuration: 500, |
---|
23 | // | // hideDuration will default to "200" |
---|
24 | // | showFunc: dojo.fx.wipeIn, |
---|
25 | // | // hideFunc will default to "fadeOut" |
---|
26 | // | }); |
---|
27 | // | t.show(100); // delay showing for 100ms |
---|
28 | // | // ...time passes... |
---|
29 | // | t.hide(); |
---|
30 | |
---|
31 | // node: DomNode |
---|
32 | // the node to target for the showing and hiding animations |
---|
33 | node: null, |
---|
34 | |
---|
35 | // showFunc: Function |
---|
36 | // The function that returns the `dojo.Animation` to show the node |
---|
37 | showFunc: baseFx.fadeIn, |
---|
38 | |
---|
39 | // hideFunc: Function |
---|
40 | // The function that returns the `dojo.Animation` to hide the node |
---|
41 | hideFunc: baseFx.fadeOut, |
---|
42 | |
---|
43 | // showDuration: |
---|
44 | // Time in milliseconds to run the show Animation |
---|
45 | showDuration: 200, |
---|
46 | |
---|
47 | // hideDuration: |
---|
48 | // Time in milliseconds to run the hide Animation |
---|
49 | hideDuration: 200, |
---|
50 | |
---|
51 | // FIXME: need a policy for where the toggler should "be" the next |
---|
52 | // time show/hide are called if we're stopped somewhere in the |
---|
53 | // middle. |
---|
54 | // FIXME: also would be nice to specify individual showArgs/hideArgs mixed into |
---|
55 | // each animation individually. |
---|
56 | // FIXME: also would be nice to have events from the animations exposed/bridged |
---|
57 | |
---|
58 | /*===== |
---|
59 | _showArgs: null, |
---|
60 | _showAnim: null, |
---|
61 | |
---|
62 | _hideArgs: null, |
---|
63 | _hideAnim: null, |
---|
64 | |
---|
65 | _isShowing: false, |
---|
66 | _isHiding: false, |
---|
67 | =====*/ |
---|
68 | |
---|
69 | constructor: function(args){ |
---|
70 | var _t = this; |
---|
71 | |
---|
72 | lang.mixin(_t, args); |
---|
73 | _t.node = args.node; |
---|
74 | _t._showArgs = lang.mixin({}, args); |
---|
75 | _t._showArgs.node = _t.node; |
---|
76 | _t._showArgs.duration = _t.showDuration; |
---|
77 | _t.showAnim = _t.showFunc(_t._showArgs); |
---|
78 | |
---|
79 | _t._hideArgs = lang.mixin({}, args); |
---|
80 | _t._hideArgs.node = _t.node; |
---|
81 | _t._hideArgs.duration = _t.hideDuration; |
---|
82 | _t.hideAnim = _t.hideFunc(_t._hideArgs); |
---|
83 | |
---|
84 | connectUtil.connect(_t.showAnim, "beforeBegin", lang.hitch(_t.hideAnim, "stop", true)); |
---|
85 | connectUtil.connect(_t.hideAnim, "beforeBegin", lang.hitch(_t.showAnim, "stop", true)); |
---|
86 | }, |
---|
87 | |
---|
88 | show: function(delay){ |
---|
89 | // summary: Toggle the node to showing |
---|
90 | // delay: Integer? |
---|
91 | // Ammount of time to stall playing the show animation |
---|
92 | return this.showAnim.play(delay || 0); |
---|
93 | }, |
---|
94 | |
---|
95 | hide: function(delay){ |
---|
96 | // summary: Toggle the node to hidden |
---|
97 | // delay: Integer? |
---|
98 | // Ammount of time to stall playing the hide animation |
---|
99 | return this.hideAnim.play(delay || 0); |
---|
100 | } |
---|
101 | }); |
---|
102 | |
---|
103 | }); |
---|