2150 |
mathias |
1 |
if(!dojo._hasResource["dojo.fx"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojo.fx"] = true;
|
|
|
3 |
dojo.provide("dojo.fx");
|
|
|
4 |
dojo.provide("dojo.fx.Toggler");
|
|
|
5 |
|
|
|
6 |
dojo.fx.chain = function(/*dojo._Animation[]*/ animations){
|
|
|
7 |
// summary: Chain a list of dojo._Animation s to run in sequence
|
|
|
8 |
// example:
|
|
|
9 |
// | dojo.fx.chain([
|
|
|
10 |
// | dojo.fadeIn({ node:node }),
|
|
|
11 |
// | dojo.fadeOut({ node:otherNode })
|
|
|
12 |
// | ]).play();
|
|
|
13 |
//
|
|
|
14 |
var first = animations.shift();
|
|
|
15 |
var previous = first;
|
|
|
16 |
dojo.forEach(animations, function(current){
|
|
|
17 |
dojo.connect(previous, "onEnd", current, "play");
|
|
|
18 |
previous = current;
|
|
|
19 |
});
|
|
|
20 |
return first; // dojo._Animation
|
|
|
21 |
};
|
|
|
22 |
|
|
|
23 |
dojo.fx.combine = function(/*dojo._Animation[]*/ animations){
|
|
|
24 |
// summary: Combine a list of dojo._Animation s to run in parallel
|
|
|
25 |
// example:
|
|
|
26 |
// | dojo.fx.combine([
|
|
|
27 |
// | dojo.fadeIn({ node:node }),
|
|
|
28 |
// | dojo.fadeOut({ node:otherNode })
|
|
|
29 |
// | ]).play();
|
|
|
30 |
var ctr = new dojo._Animation({ curve: [0, 1] });
|
|
|
31 |
if(!animations.length){ return ctr; }
|
|
|
32 |
// animations.sort(function(a, b){ return a.duration-b.duration; });
|
|
|
33 |
ctr.duration = animations[0].duration;
|
|
|
34 |
dojo.forEach(animations, function(current){
|
|
|
35 |
dojo.forEach([ "play", "pause", "stop" ],
|
|
|
36 |
function(e){
|
|
|
37 |
if(current[e]){
|
|
|
38 |
dojo.connect(ctr, e, current, e);
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
);
|
|
|
42 |
});
|
|
|
43 |
return ctr; // dojo._Animation
|
|
|
44 |
};
|
|
|
45 |
|
|
|
46 |
dojo.declare("dojo.fx.Toggler", null, {
|
|
|
47 |
// summary:
|
|
|
48 |
// class constructor for an animation toggler. It accepts a packed
|
|
|
49 |
// set of arguments about what type of animation to use in each
|
|
|
50 |
// direction, duration, etc.
|
|
|
51 |
//
|
|
|
52 |
// example:
|
|
|
53 |
// | var t = new dojo.fx.Toggler({
|
|
|
54 |
// | node: "nodeId",
|
|
|
55 |
// | showDuration: 500,
|
|
|
56 |
// | // hideDuration will default to "200"
|
|
|
57 |
// | showFunc: dojo.wipeIn,
|
|
|
58 |
// | // hideFunc will default to "fadeOut"
|
|
|
59 |
// | });
|
|
|
60 |
// | t.show(100); // delay showing for 100ms
|
|
|
61 |
// | // ...time passes...
|
|
|
62 |
// | t.hide();
|
|
|
63 |
|
|
|
64 |
// FIXME: need a policy for where the toggler should "be" the next
|
|
|
65 |
// time show/hide are called if we're stopped somewhere in the
|
|
|
66 |
// middle.
|
|
|
67 |
|
|
|
68 |
constructor: function(args){
|
|
|
69 |
var _t = this;
|
|
|
70 |
|
|
|
71 |
dojo.mixin(_t, args);
|
|
|
72 |
_t.node = args.node;
|
|
|
73 |
_t._showArgs = dojo.mixin({}, args);
|
|
|
74 |
_t._showArgs.node = _t.node;
|
|
|
75 |
_t._showArgs.duration = _t.showDuration;
|
|
|
76 |
_t.showAnim = _t.showFunc(_t._showArgs);
|
|
|
77 |
|
|
|
78 |
_t._hideArgs = dojo.mixin({}, args);
|
|
|
79 |
_t._hideArgs.node = _t.node;
|
|
|
80 |
_t._hideArgs.duration = _t.hideDuration;
|
|
|
81 |
_t.hideAnim = _t.hideFunc(_t._hideArgs);
|
|
|
82 |
|
|
|
83 |
dojo.connect(_t.showAnim, "beforeBegin", dojo.hitch(_t.hideAnim, "stop", true));
|
|
|
84 |
dojo.connect(_t.hideAnim, "beforeBegin", dojo.hitch(_t.showAnim, "stop", true));
|
|
|
85 |
},
|
|
|
86 |
|
|
|
87 |
// node: DomNode
|
|
|
88 |
// the node to toggle
|
|
|
89 |
node: null,
|
|
|
90 |
|
|
|
91 |
// showFunc: Function
|
|
|
92 |
// The function that returns the dojo._Animation to show the node
|
|
|
93 |
showFunc: dojo.fadeIn,
|
|
|
94 |
|
|
|
95 |
// hideFunc: Function
|
|
|
96 |
// The function that returns the dojo._Animation to hide the node
|
|
|
97 |
hideFunc: dojo.fadeOut,
|
|
|
98 |
|
|
|
99 |
// showDuration:
|
|
|
100 |
// Time in milliseconds to run the show Animation
|
|
|
101 |
showDuration: 200,
|
|
|
102 |
|
|
|
103 |
// hideDuration:
|
|
|
104 |
// Time in milliseconds to run the hide Animation
|
|
|
105 |
hideDuration: 200,
|
|
|
106 |
|
|
|
107 |
/*=====
|
|
|
108 |
_showArgs: null,
|
|
|
109 |
_showAnim: null,
|
|
|
110 |
|
|
|
111 |
_hideArgs: null,
|
|
|
112 |
_hideAnim: null,
|
|
|
113 |
|
|
|
114 |
_isShowing: false,
|
|
|
115 |
_isHiding: false,
|
|
|
116 |
=====*/
|
|
|
117 |
|
|
|
118 |
show: function(delay){
|
|
|
119 |
// summary: Toggle the node to showing
|
|
|
120 |
return this.showAnim.play(delay || 0);
|
|
|
121 |
},
|
|
|
122 |
|
|
|
123 |
hide: function(delay){
|
|
|
124 |
// summary: Toggle the node to hidden
|
|
|
125 |
return this.hideAnim.play(delay || 0);
|
|
|
126 |
}
|
|
|
127 |
});
|
|
|
128 |
|
|
|
129 |
dojo.fx.wipeIn = function(/*Object*/ args){
|
|
|
130 |
// summary
|
|
|
131 |
// Returns an animation that will expand the
|
|
|
132 |
// node defined in 'args' object from it's current height to
|
|
|
133 |
// it's natural height (with no scrollbar).
|
|
|
134 |
// Node must have no margin/border/padding.
|
|
|
135 |
args.node = dojo.byId(args.node);
|
|
|
136 |
var node = args.node, s = node.style;
|
|
|
137 |
|
|
|
138 |
var anim = dojo.animateProperty(dojo.mixin({
|
|
|
139 |
properties: {
|
|
|
140 |
height: {
|
|
|
141 |
// wrapped in functions so we wait till the last second to query (in case value has changed)
|
|
|
142 |
start: function(){
|
|
|
143 |
// start at current [computed] height, but use 1px rather than 0
|
|
|
144 |
// because 0 causes IE to display the whole panel
|
|
|
145 |
s.overflow="hidden";
|
|
|
146 |
if(s.visibility=="hidden"||s.display=="none"){
|
|
|
147 |
s.height="1px";
|
|
|
148 |
s.display="";
|
|
|
149 |
s.visibility="";
|
|
|
150 |
return 1;
|
|
|
151 |
}else{
|
|
|
152 |
var height = dojo.style(node, "height");
|
|
|
153 |
return Math.max(height, 1);
|
|
|
154 |
}
|
|
|
155 |
},
|
|
|
156 |
end: function(){
|
|
|
157 |
return node.scrollHeight;
|
|
|
158 |
}
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
}, args));
|
|
|
162 |
|
|
|
163 |
dojo.connect(anim, "onEnd", function(){
|
|
|
164 |
s.height = "auto";
|
|
|
165 |
});
|
|
|
166 |
|
|
|
167 |
return anim; // dojo._Animation
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
dojo.fx.wipeOut = function(/*Object*/ args){
|
|
|
171 |
// summary
|
|
|
172 |
// Returns an animation that will shrink node defined in "args"
|
|
|
173 |
// from it's current height to 1px, and then hide it.
|
|
|
174 |
var node = args.node = dojo.byId(args.node);
|
|
|
175 |
var s = node.style;
|
|
|
176 |
|
|
|
177 |
var anim = dojo.animateProperty(dojo.mixin({
|
|
|
178 |
properties: {
|
|
|
179 |
height: {
|
|
|
180 |
end: 1 // 0 causes IE to display the whole panel
|
|
|
181 |
}
|
|
|
182 |
}
|
|
|
183 |
}, args));
|
|
|
184 |
|
|
|
185 |
dojo.connect(anim, "beforeBegin", function(){
|
|
|
186 |
s.overflow = "hidden";
|
|
|
187 |
s.display = "";
|
|
|
188 |
});
|
|
|
189 |
dojo.connect(anim, "onEnd", function(){
|
|
|
190 |
s.height = "auto";
|
|
|
191 |
s.display = "none";
|
|
|
192 |
});
|
|
|
193 |
|
|
|
194 |
return anim; // dojo._Animation
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
dojo.fx.slideTo = function(/*Object?*/ args){
|
|
|
198 |
// summary
|
|
|
199 |
// Returns an animation that will slide "node"
|
|
|
200 |
// defined in args Object from its current position to
|
|
|
201 |
// the position defined by (args.left, args.top).
|
|
|
202 |
// example:
|
|
|
203 |
// | dojo.fx.slideTo({ node: node, left:"40", top:"50", unit:"px" }).play()
|
|
|
204 |
|
|
|
205 |
var node = (args.node = dojo.byId(args.node));
|
|
|
206 |
|
|
|
207 |
var top = null;
|
|
|
208 |
var left = null;
|
|
|
209 |
|
|
|
210 |
var init = (function(n){
|
|
|
211 |
return function(){
|
|
|
212 |
var cs = dojo.getComputedStyle(n);
|
|
|
213 |
var pos = cs.position;
|
|
|
214 |
top = (pos == 'absolute' ? n.offsetTop : parseInt(cs.top) || 0);
|
|
|
215 |
left = (pos == 'absolute' ? n.offsetLeft : parseInt(cs.left) || 0);
|
|
|
216 |
if(pos != 'absolute' && pos != 'relative'){
|
|
|
217 |
var ret = dojo.coords(n, true);
|
|
|
218 |
top = ret.y;
|
|
|
219 |
left = ret.x;
|
|
|
220 |
n.style.position="absolute";
|
|
|
221 |
n.style.top=top+"px";
|
|
|
222 |
n.style.left=left+"px";
|
|
|
223 |
}
|
|
|
224 |
};
|
|
|
225 |
})(node);
|
|
|
226 |
init();
|
|
|
227 |
|
|
|
228 |
var anim = dojo.animateProperty(dojo.mixin({
|
|
|
229 |
properties: {
|
|
|
230 |
top: { end: args.top||0 },
|
|
|
231 |
left: { end: args.left||0 }
|
|
|
232 |
}
|
|
|
233 |
}, args));
|
|
|
234 |
dojo.connect(anim, "beforeBegin", anim, init);
|
|
|
235 |
|
|
|
236 |
return anim; // dojo._Animation
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
}
|