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