1 | define(["dojo/_base/lang", "dojo/dom", "dojo/_base/window", "dojo/_base/html", "dojo/dom-geometry", |
---|
2 | "dojo/dom-construct", "dojo/dom-attr", "dojo/_base/fx", "dojo/fx", "./_base", "dojo/fx/easing", "dojo/_base/connect"], |
---|
3 | function(lang, dom, winUtil, htmlUtil, domGeom, domConstruct, domAttr, baseFx, coreFx, fxExt, easingUtil, connectUtil){ |
---|
4 | var dojoxFx = lang.getObject("dojox.fx"); |
---|
5 | lang.mixin(dojoxFx,{ |
---|
6 | _split: function(/*Object*/ args){ |
---|
7 | // summary: |
---|
8 | // Split a node into rectangular pieces and animate them. |
---|
9 | // description: |
---|
10 | // Returns an animation that will split the node into a grid |
---|
11 | // of pieces that move independently. |
---|
12 | // args: |
---|
13 | // - args.crop: Boolean - If true, pieces will only be visible inside node's boundries |
---|
14 | // - args.rows: Integer - The number of horizontal pieces (default is 3) |
---|
15 | // - args.columns: Integer - The number of vertical pieces (default is 3) |
---|
16 | // - args.pieceAnimation: Function(piece, x, y, coords) - Returns either the dojo.Animation |
---|
17 | // or an array of dojo.Animation objects for the piece at location (x, y) in the node's grid; |
---|
18 | // coords is the result of dojo.coords(args.node, true); |
---|
19 | |
---|
20 | args.rows = args.rows || 3; |
---|
21 | args.columns = args.columns || 3; |
---|
22 | args.duration = args.duration || 1000; |
---|
23 | |
---|
24 | var node = args.node = dom.byId(args.node), |
---|
25 | parentNode = node.parentNode, |
---|
26 | pNode = parentNode, |
---|
27 | body = winUtil.body(), |
---|
28 | _pos = "position" |
---|
29 | ; |
---|
30 | |
---|
31 | while(pNode && pNode != body && htmlUtil.style(pNode, _pos) == "static"){ |
---|
32 | pNode = pNode.parentNode; |
---|
33 | } |
---|
34 | |
---|
35 | var pCoords = pNode != body ? domGeom.position(pNode, true) : { x: 0, y: 0 }, |
---|
36 | coords = domGeom.position(node, true), |
---|
37 | nodeHeight = htmlUtil.style(node, "height"), |
---|
38 | nodeWidth = htmlUtil.style(node, "width"), |
---|
39 | hBorder = htmlUtil.style(node, "borderLeftWidth") + htmlUtil.style(node, "borderRightWidth"), |
---|
40 | vBorder = htmlUtil.style(node, "borderTopWidth") + htmlUtil.style(node, "borderBottomWidth"), |
---|
41 | pieceHeight = Math.ceil(nodeHeight / args.rows), |
---|
42 | pieceWidth = Math.ceil(nodeWidth / args.columns), |
---|
43 | container = domConstruct.create(node.tagName, { |
---|
44 | style: { |
---|
45 | position: "absolute", |
---|
46 | padding: 0, |
---|
47 | margin: 0, |
---|
48 | border:"none", |
---|
49 | top: coords.y - pCoords.y + "px", |
---|
50 | left: coords.x - pCoords.x + "px", |
---|
51 | height: nodeHeight + vBorder + "px", |
---|
52 | width: nodeWidth + hBorder + "px", |
---|
53 | background: "none", |
---|
54 | overflow: args.crop ? "hidden" : "visible", |
---|
55 | zIndex: htmlUtil.style(node, "zIndex") |
---|
56 | } |
---|
57 | }, node, "after"), |
---|
58 | animations = [], |
---|
59 | pieceHelper = domConstruct.create(node.tagName, { |
---|
60 | style: { |
---|
61 | position: "absolute", |
---|
62 | border: "none", |
---|
63 | padding: 0, |
---|
64 | margin: 0, |
---|
65 | height: pieceHeight + hBorder + "px", |
---|
66 | width: pieceWidth + vBorder + "px", |
---|
67 | overflow: "hidden" |
---|
68 | } |
---|
69 | }); |
---|
70 | |
---|
71 | // Create the pieces and their animations |
---|
72 | for(var y = 0, ly = args.rows; y < ly; y++){ |
---|
73 | for(var x = 0, lx = args.columns; x < lx; x++){ |
---|
74 | // Create the piece |
---|
75 | var piece = lang.clone(pieceHelper), |
---|
76 | pieceContents = lang.clone(node), |
---|
77 | pTop = y * pieceHeight, |
---|
78 | pLeft = x * pieceWidth |
---|
79 | ; |
---|
80 | |
---|
81 | // IE hack |
---|
82 | pieceContents.style.filter = ""; |
---|
83 | |
---|
84 | // removing the id attribute from the cloned nodes |
---|
85 | domAttr.remove(pieceContents, "id"); |
---|
86 | |
---|
87 | htmlUtil.style(piece, { |
---|
88 | border: "none", |
---|
89 | overflow: "hidden", |
---|
90 | top: pTop + "px", |
---|
91 | left: pLeft + "px" |
---|
92 | }); |
---|
93 | htmlUtil.style(pieceContents, { |
---|
94 | position: "static", |
---|
95 | opacity: "1", |
---|
96 | marginTop: -pTop + "px", |
---|
97 | marginLeft: -pLeft + "px" |
---|
98 | }); |
---|
99 | piece.appendChild(pieceContents); |
---|
100 | container.appendChild(piece); |
---|
101 | |
---|
102 | var pieceAnimation = args.pieceAnimation(piece, x, y, coords); |
---|
103 | if(lang.isArray(pieceAnimation)){ |
---|
104 | // if pieceAnimation is an array, append its elements |
---|
105 | animations = animations.concat(pieceAnimation); |
---|
106 | }else{ |
---|
107 | // otherwise, append it |
---|
108 | animations.push(pieceAnimation); |
---|
109 | } |
---|
110 | } |
---|
111 | } |
---|
112 | var anim = coreFx.combine(animations); |
---|
113 | connectUtil.connect(anim, "onEnd", anim, function(){ |
---|
114 | container.parentNode.removeChild(container); |
---|
115 | }); |
---|
116 | if(args.onPlay){ |
---|
117 | connectUtil.connect(anim, "onPlay", anim, args.onPlay); |
---|
118 | } |
---|
119 | if(args.onEnd){ |
---|
120 | connectUtil.connect(anim, "onEnd", anim, args.onEnd); |
---|
121 | } |
---|
122 | return anim; // dojo.Animation |
---|
123 | }, |
---|
124 | |
---|
125 | explode: function(/*Object*/ args){ |
---|
126 | // summary: |
---|
127 | // Explode a node into rectangular pieces |
---|
128 | // description: |
---|
129 | // Returns an animation that will split the node into a grid |
---|
130 | // of pieces that fly away from the center. |
---|
131 | // args: |
---|
132 | // - args.rows: Integer - The number of horizontal pieces (default is 3) |
---|
133 | // - args.columns: Integer - The number of vertical pieces (default is 3) |
---|
134 | // - args.random: Float - If set, pieces fly to random distances, for random durations, |
---|
135 | // and in slightly random directions. The value defines how much |
---|
136 | // randomness is introduced. |
---|
137 | // - args.distance: Float - Multiplier for the distance the pieces fly (even when random) |
---|
138 | // - args.fade: Boolean - If true, pieces fade out while in motion (default is true) |
---|
139 | // - args.fadeEasing: Function - If args.fade is true, the fade animations use this easing function |
---|
140 | // - args.unhide: Boolean - If true, the animation is reversed |
---|
141 | // - args.sync: Boolean - If args.unhide is true, all the pieces converge at the same time |
---|
142 | // (default is true) |
---|
143 | |
---|
144 | var node = args.node = dom.byId(args.node); |
---|
145 | args.rows = args.rows || 3; |
---|
146 | args.columns = args.columns || 3; |
---|
147 | args.distance = args.distance || 1; |
---|
148 | args.duration = args.duration || 1000; |
---|
149 | args.random = args.random || 0; |
---|
150 | if(!args.fade){ |
---|
151 | args.fade = true; |
---|
152 | } |
---|
153 | if(typeof args.sync == "undefined"){ |
---|
154 | args.sync = true; |
---|
155 | } |
---|
156 | args.random = Math.abs(args.random); |
---|
157 | |
---|
158 | // Returns the animation object for each piece |
---|
159 | args.pieceAnimation = function(piece, x, y, coords){ |
---|
160 | var pieceHeight = coords.h / args.rows, |
---|
161 | pieceWidth = coords.w / args.columns, |
---|
162 | distance = args.distance * 2, |
---|
163 | duration = args.duration, |
---|
164 | ps = piece.style, |
---|
165 | startTop = parseInt(ps.top), |
---|
166 | startLeft = parseInt(ps.left), |
---|
167 | delay = 0, |
---|
168 | randomX = 0, |
---|
169 | randomY = 0; |
---|
170 | |
---|
171 | if(args.random){ |
---|
172 | var seed = (Math.random() * args.random) + Math.max(1 - args.random, 0); |
---|
173 | distance *= seed; |
---|
174 | duration *= seed; |
---|
175 | // To syncronize, give each piece an appropriate delay so they end together |
---|
176 | delay = ((args.unhide && args.sync) || (!args.unhide && !args.sync)) ? (args.duration - duration) : 0; |
---|
177 | // Slightly randomize the direction of each piece |
---|
178 | randomX = Math.random() - 0.5; |
---|
179 | randomY = Math.random() - 0.5; |
---|
180 | } |
---|
181 | |
---|
182 | var distanceY = ((coords.h - pieceHeight) / 2 - pieceHeight * y), |
---|
183 | distanceX = ((coords.w - pieceWidth) / 2 - pieceWidth * x), |
---|
184 | distanceXY = Math.sqrt(Math.pow(distanceX, 2) + Math.pow(distanceY, 2)), |
---|
185 | endTop = parseInt(startTop - distanceY * distance + distanceXY * randomY), |
---|
186 | endLeft = parseInt(startLeft - distanceX * distance + distanceXY * randomX) |
---|
187 | ; |
---|
188 | |
---|
189 | // Create the animation objects for the piece |
---|
190 | // These are separate anim objects so they can have different curves |
---|
191 | var pieceSlide = baseFx.animateProperty({ |
---|
192 | node: piece, |
---|
193 | duration: duration, |
---|
194 | delay: delay, |
---|
195 | easing: (args.easing || (args.unhide ? easingUtil.sinOut : easingUtil.circOut)), |
---|
196 | beforeBegin: (args.unhide ? function(){ |
---|
197 | if(args.fade){ |
---|
198 | htmlUtil.style(piece, { opacity: "0"}); |
---|
199 | } |
---|
200 | ps.top = endTop + "px"; |
---|
201 | ps.left = endLeft + "px"; |
---|
202 | } : undefined), |
---|
203 | properties: { |
---|
204 | top: (args.unhide ? { start: endTop, end: startTop } : { start: startTop, end: endTop }), |
---|
205 | left: (args.unhide ? { start: endLeft, end: startLeft } : { start: startLeft, end: endLeft }) |
---|
206 | } |
---|
207 | }); |
---|
208 | if(args.fade){ |
---|
209 | var pieceFade = baseFx.animateProperty({ |
---|
210 | node: piece, |
---|
211 | duration: duration, |
---|
212 | delay: delay, |
---|
213 | easing: (args.fadeEasing || easingUtil.quadOut), |
---|
214 | properties: { |
---|
215 | opacity: (args.unhide ? { start: "0", end: "1" } : { start: "1", end: "0" }) |
---|
216 | } |
---|
217 | }); |
---|
218 | |
---|
219 | // return both animations as an array |
---|
220 | return (args.unhide ? [pieceFade, pieceSlide] : [pieceSlide, pieceFade]); |
---|
221 | }else{ |
---|
222 | // Otherwise return only the slide animation |
---|
223 | return pieceSlide; |
---|
224 | } |
---|
225 | }; |
---|
226 | |
---|
227 | var anim = dojoxFx._split(args); |
---|
228 | if(args.unhide){ |
---|
229 | connectUtil.connect(anim, "onEnd", null, function(){ |
---|
230 | htmlUtil.style(node, {opacity: "1" }); |
---|
231 | }); |
---|
232 | }else{ |
---|
233 | connectUtil.connect(anim, "onPlay", null, function(){ |
---|
234 | htmlUtil.style(node, { opacity: "0" }); |
---|
235 | }); |
---|
236 | } |
---|
237 | return anim; // dojo.Animation |
---|
238 | }, |
---|
239 | |
---|
240 | converge: function(/*Object*/ args){ |
---|
241 | args.unhide = true; |
---|
242 | return dojoxFx.explode(args); |
---|
243 | }, |
---|
244 | |
---|
245 | disintegrate: function(/*Object*/ args){ |
---|
246 | // summary: |
---|
247 | // Split a node into rectangular pieces and let them fall |
---|
248 | // description: |
---|
249 | // Returns an animation that will split the node into a grid |
---|
250 | // of pieces that drop. |
---|
251 | // args: |
---|
252 | // - args.rows: Integer - The number of horizontal pieces (default is 5) |
---|
253 | // - args.columns: Integer - The number of vertical pieces (default is 5) |
---|
254 | // - args.interval: Float - The number of milliseconds between each piece's animation |
---|
255 | // - args.distance: Float - The number of the node's heights to drop (default is 1.5) |
---|
256 | // - args.fade: Boolean - If true, pieces fade out while in motion (default is true) |
---|
257 | // - args.random: Float - If set, pieces fall in random order. The value defines how much |
---|
258 | // randomness is introduced. |
---|
259 | // - args.reverseOrder: Boolean - If true, pieces animate in reversed order |
---|
260 | // - args.unhide: Boolean - If true, the peices fall from above and land in place |
---|
261 | var node = args.node = dom.byId(args.node); |
---|
262 | |
---|
263 | args.rows = args.rows || 5; |
---|
264 | args.columns = args.columns || 5; |
---|
265 | args.duration = args.duration || 1500; |
---|
266 | args.interval = args.interval || args.duration / (args.rows + args.columns * 2); |
---|
267 | args.distance = args.distance || 1.5; |
---|
268 | args.random = args.random || 0; |
---|
269 | if(typeof args.fade == "undefined"){ |
---|
270 | args.fade = true; |
---|
271 | } |
---|
272 | |
---|
273 | var random = Math.abs(args.random), |
---|
274 | duration = args.duration - (args.rows + args.columns) * args.interval; |
---|
275 | |
---|
276 | // Returns the animation object for each piece |
---|
277 | args.pieceAnimation = function(piece, x, y, coords){ |
---|
278 | |
---|
279 | var randomDelay = Math.random() * (args.rows + args.columns) * args.interval, |
---|
280 | ps = piece.style, |
---|
281 | |
---|
282 | // If distance is negative, start from the top right instead of bottom left |
---|
283 | uniformDelay = (args.reverseOrder || args.distance < 0) ? |
---|
284 | ((x + y) * args.interval) : |
---|
285 | (((args.rows + args.columns) - (x + y)) * args.interval), |
---|
286 | delay = randomDelay * random + Math.max(1 - random, 0) * uniformDelay, |
---|
287 | // Create the animation object for the piece |
---|
288 | properties = {} |
---|
289 | ; |
---|
290 | if(args.unhide){ |
---|
291 | properties.top = { |
---|
292 | start: (parseInt(ps.top) - coords.h * args.distance), |
---|
293 | end: parseInt(ps.top) |
---|
294 | }; |
---|
295 | if(args.fade){ |
---|
296 | properties.opacity = {start: "0", end: "1"}; |
---|
297 | } |
---|
298 | }else{ |
---|
299 | properties.top = {end: (parseInt(ps.top) + coords.h * args.distance)}; |
---|
300 | if(args.fade){ |
---|
301 | properties.opacity = {end: "0"}; |
---|
302 | } |
---|
303 | } |
---|
304 | var pieceAnimation = baseFx.animateProperty({ |
---|
305 | node: piece, |
---|
306 | duration: duration, |
---|
307 | delay: delay, |
---|
308 | easing: (args.easing || (args.unhide ? easingUtil.sinIn : easingUtil.circIn)), |
---|
309 | properties: properties, |
---|
310 | beforeBegin: (args.unhide ? function(){ |
---|
311 | if(args.fade){ |
---|
312 | htmlUtil.style(piece, { opacity: "0" }); |
---|
313 | } |
---|
314 | ps.top = properties.top.start + "px"; |
---|
315 | } : undefined) |
---|
316 | }); |
---|
317 | |
---|
318 | return pieceAnimation; |
---|
319 | }; |
---|
320 | |
---|
321 | var anim = dojoxFx._split(args); |
---|
322 | if(args.unhide){ |
---|
323 | connectUtil.connect(anim, "onEnd", anim, function(){ |
---|
324 | htmlUtil.style(node, { opacity: "1" }); |
---|
325 | }); |
---|
326 | }else{ |
---|
327 | connectUtil.connect(anim, "onPlay", anim, function(){ |
---|
328 | htmlUtil.style(node, { opacity: "0" }); |
---|
329 | }); |
---|
330 | } |
---|
331 | return anim; // dojo.Animation |
---|
332 | }, |
---|
333 | |
---|
334 | build: function(/*Object*/ args){ |
---|
335 | args.unhide = true; |
---|
336 | return dojoxFx.disintegrate(args); |
---|
337 | }, |
---|
338 | |
---|
339 | shear: function(/*Object*/ args){ |
---|
340 | // summary: |
---|
341 | // Split a node into rectangular pieces and slide them in alternating directions |
---|
342 | // description: |
---|
343 | // Returns an animation that will split the node into a grid |
---|
344 | // of pieces that slide in alternating directions. |
---|
345 | // args: |
---|
346 | // - args.rows: Integer - The number of horizontal pieces (default is 6) |
---|
347 | // - args.columns: Integer - The number of vertical pieces (default is 6) |
---|
348 | // - args.interval: Float - The number of milliseconds between each piece's animation (default is 0) |
---|
349 | // - args.distance: Float - The multiple of the node's dimensions to slide (default is 1) |
---|
350 | // - args.fade: Boolean - If true, pieces fade out while in motion (default is true) |
---|
351 | // - args.random: Float - If true, pieces have a random delay. The value defines how much |
---|
352 | // randomness is introduced |
---|
353 | // - args.reverseOrder: Boolean - If true, pieces animate in reversed order |
---|
354 | // - args.unhide: Boolean - If true, the animation is reversed |
---|
355 | |
---|
356 | var node = args.node = dom.byId(args.node); |
---|
357 | |
---|
358 | args.rows = args.rows || 6; |
---|
359 | args.columns = args.columns || 6; |
---|
360 | args.duration = args.duration || 1000; |
---|
361 | args.interval = args.interval || 0; |
---|
362 | args.distance = args.distance || 1; |
---|
363 | args.random = args.random || 0; |
---|
364 | if(typeof(args.fade) == "undefined"){ |
---|
365 | args.fade = true; |
---|
366 | } |
---|
367 | var random = Math.abs(args.random), |
---|
368 | duration = (args.duration - (args.rows + args.columns) * Math.abs(args.interval)) |
---|
369 | ; |
---|
370 | |
---|
371 | // Returns the animation object for each piece |
---|
372 | args.pieceAnimation = function(piece, x, y, coords){ |
---|
373 | |
---|
374 | // Since x an y start at 0, the opposite is true... |
---|
375 | var colIsOdd = !(x % 2), |
---|
376 | rowIsOdd = !(y % 2), |
---|
377 | randomDelay = Math.random() * duration, |
---|
378 | uniformDelay = (args.reverseOrder) ? |
---|
379 | (((args.rows + args.columns) - (x + y)) * args.interval) : |
---|
380 | ((x + y) * args.interval), |
---|
381 | delay = randomDelay * random + Math.max(1 - random, 0) * uniformDelay, |
---|
382 | properties = {}, |
---|
383 | ps = piece.style |
---|
384 | ; |
---|
385 | |
---|
386 | if(args.fade){ |
---|
387 | properties.opacity = (args.unhide ? { start: "0", end: "1" } : { end: "0" }); |
---|
388 | } |
---|
389 | |
---|
390 | // If we have only rows or columns, ignore the other dimension |
---|
391 | if(args.columns == 1){ |
---|
392 | colIsOdd = rowIsOdd; |
---|
393 | }else if(args.rows == 1){ |
---|
394 | rowIsOdd = !colIsOdd; |
---|
395 | } |
---|
396 | |
---|
397 | // Determine the piece's direction |
---|
398 | var left = parseInt(ps.left), |
---|
399 | top = parseInt(ps.top), |
---|
400 | distanceX = args.distance*coords.w, |
---|
401 | distanceY = args.distance*coords.h |
---|
402 | ; |
---|
403 | if(args.unhide){ |
---|
404 | if(colIsOdd == rowIsOdd){ |
---|
405 | properties.left = colIsOdd ? {start: (left - distanceX), end: left} : {start: (left + distanceX), end: left}; |
---|
406 | }else{ |
---|
407 | properties.top = colIsOdd ? {start: (top + distanceY), end: top} : {start: (top - distanceY), end: top}; |
---|
408 | } |
---|
409 | }else{ |
---|
410 | if(colIsOdd == rowIsOdd){ |
---|
411 | properties.left = colIsOdd ? {end: (left - distanceX)} : {end: (left + distanceX)}; |
---|
412 | }else{ |
---|
413 | properties.top = colIsOdd ? {end: (top + distanceY)} : {end: (top - distanceY)}; |
---|
414 | } |
---|
415 | } |
---|
416 | |
---|
417 | // Create the animation object for the piece |
---|
418 | var pieceAnimation = baseFx.animateProperty({ |
---|
419 | node: piece, |
---|
420 | duration: duration, |
---|
421 | delay: delay, |
---|
422 | easing: (args.easing || easingUtil.sinInOut), |
---|
423 | properties: properties, |
---|
424 | beforeBegin: (args.unhide ? function(){ |
---|
425 | if(args.fade){ |
---|
426 | ps.opacity = "0"; |
---|
427 | } |
---|
428 | if(colIsOdd == rowIsOdd){ |
---|
429 | ps.left = properties.left.start + "px"; |
---|
430 | }else{ |
---|
431 | ps.top = properties.top.start + "px"; |
---|
432 | } |
---|
433 | } : undefined) |
---|
434 | }); |
---|
435 | |
---|
436 | return pieceAnimation; |
---|
437 | }; |
---|
438 | |
---|
439 | var anim = dojoxFx._split(args); |
---|
440 | if(args.unhide){ |
---|
441 | connectUtil.connect(anim, "onEnd", anim, function(){ |
---|
442 | htmlUtil.style(node, { opacity: "1" }); |
---|
443 | }); |
---|
444 | }else{ |
---|
445 | connectUtil.connect(anim, "onPlay", anim, function(){ |
---|
446 | htmlUtil.style(node, { opacity: "0" }); |
---|
447 | }); |
---|
448 | } |
---|
449 | return anim; // dojo.Animation |
---|
450 | }, |
---|
451 | |
---|
452 | unShear: function(/*Object*/ args){ |
---|
453 | args.unhide = true; |
---|
454 | return dojoxFx.shear(args); |
---|
455 | }, |
---|
456 | |
---|
457 | pinwheel: function(/*Object*/ args){ |
---|
458 | // summary: |
---|
459 | // Split a node into rectangular pieces and wipe them in alternating directions |
---|
460 | // description: |
---|
461 | // Returns an animation that will split the node into a grid |
---|
462 | // of pieces that wipe in alternating directions. |
---|
463 | // args: |
---|
464 | // - args.rows: Integer - The number of horizontal pieces (default is 4) |
---|
465 | // - args.columns: Integer - The number of vertical pieces (default is 4) |
---|
466 | // - args.interval: Float - The number of milliseconds between each piece's animation (default is 0) |
---|
467 | // - args.distance: Float - The percentage of the piece's dimensions the piece should wipe |
---|
468 | // - args.fade: Boolean - If true, pieces fade out while in motion (default is true) |
---|
469 | // - args.random: Float - If true, pieces have a random delay. The value defines how much |
---|
470 | // randomness is introduced. |
---|
471 | // - args.unhide: Boolean - If true, the animation is reversed |
---|
472 | |
---|
473 | var node = args.node = dom.byId(args.node); |
---|
474 | |
---|
475 | args.rows = args.rows || 4; |
---|
476 | args.columns = args.columns || 4; |
---|
477 | args.duration = args.duration || 1000; |
---|
478 | args.interval = args.interval || 0; |
---|
479 | args.distance = args.distance || 1; |
---|
480 | args.random = args.random || 0; |
---|
481 | if(typeof args.fade == "undefined"){ |
---|
482 | args.fade = true; |
---|
483 | } |
---|
484 | var duration = (args.duration - (args.rows + args.columns) * Math.abs(args.interval)); |
---|
485 | |
---|
486 | // Returns the animation object for each piece |
---|
487 | args.pieceAnimation = function(piece, x, y, coords){ |
---|
488 | var pieceHeight = coords.h / args.rows, |
---|
489 | pieceWidth = coords.w / args.columns, |
---|
490 | |
---|
491 | // because x an y start at 0, the opposite is true... |
---|
492 | colIsOdd = !(x % 2), |
---|
493 | rowIsOdd = !(y % 2), |
---|
494 | |
---|
495 | randomDelay = Math.random() * duration, |
---|
496 | uniformDelay = (args.interval < 0) ? |
---|
497 | (((args.rows + args.columns) - (x + y)) * args.interval * -1) : |
---|
498 | ((x + y) * args.interval), |
---|
499 | delay = randomDelay * args.random + Math.max(1 - args.random, 0) * uniformDelay, |
---|
500 | properties = {}, |
---|
501 | ps = piece.style |
---|
502 | ; |
---|
503 | |
---|
504 | if(args.fade){ |
---|
505 | properties.opacity = (args.unhide ? {start: 0, end: 1} : {end:0}); |
---|
506 | } |
---|
507 | |
---|
508 | // If we have only rows or columns, ignore the other dimension |
---|
509 | if(args.columns == 1){ |
---|
510 | colIsOdd = !rowIsOdd; |
---|
511 | }else if(args.rows == 1){ |
---|
512 | rowIsOdd = colIsOdd; |
---|
513 | } |
---|
514 | |
---|
515 | // Determine the piece's direction |
---|
516 | var left = parseInt(ps.left), |
---|
517 | top = parseInt(ps.top) |
---|
518 | ; |
---|
519 | if(colIsOdd){ |
---|
520 | if(rowIsOdd){ |
---|
521 | properties.top = args.unhide ? |
---|
522 | { start: top + pieceHeight * args.distance, end: top} : |
---|
523 | { start: top, end: top + pieceHeight * args.distance} ; |
---|
524 | }else{ |
---|
525 | properties.left = args.unhide ? |
---|
526 | { start: left + pieceWidth * args.distance, end: left } : |
---|
527 | { start: left, end: left + pieceWidth * args.distance } ; |
---|
528 | } |
---|
529 | } |
---|
530 | if(colIsOdd != rowIsOdd){ |
---|
531 | properties.width = args.unhide ? |
---|
532 | { start: pieceWidth * (1 - args.distance), end: pieceWidth } : |
---|
533 | { start: pieceWidth, end: pieceWidth * (1 - args.distance) } ; |
---|
534 | }else{ |
---|
535 | properties.height = args.unhide ? |
---|
536 | { start: pieceHeight * (1 - args.distance), end: pieceHeight } : |
---|
537 | { start: pieceHeight, end: pieceHeight * (1 - args.distance) } ; |
---|
538 | } |
---|
539 | |
---|
540 | // Create the animation object for the piece |
---|
541 | var pieceAnimation = baseFx.animateProperty({ |
---|
542 | node: piece, |
---|
543 | duration: duration, |
---|
544 | delay: delay, |
---|
545 | easing: (args.easing || easingUtil.sinInOut), |
---|
546 | properties: properties, |
---|
547 | beforeBegin: (args.unhide ? function(){ |
---|
548 | if(args.fade){ |
---|
549 | htmlUtil.style(piece, "opacity", 0); |
---|
550 | } |
---|
551 | if(colIsOdd){ |
---|
552 | if(rowIsOdd){ |
---|
553 | ps.top = (top + pieceHeight * (1 - args.distance)) + "px"; |
---|
554 | }else{ |
---|
555 | ps.left = (left + pieceWidth * (1 - args.distance)) + "px"; |
---|
556 | } |
---|
557 | }else{ |
---|
558 | ps.left = left + "px"; |
---|
559 | ps.top = top + "px"; |
---|
560 | } |
---|
561 | if(colIsOdd != rowIsOdd){ |
---|
562 | ps.width = (pieceWidth * (1 - args.distance)) + "px"; |
---|
563 | }else{ |
---|
564 | ps.height = (pieceHeight * (1 - args.distance)) + "px"; |
---|
565 | } |
---|
566 | } : undefined) |
---|
567 | }); |
---|
568 | |
---|
569 | return pieceAnimation; |
---|
570 | }; |
---|
571 | |
---|
572 | var anim = dojoxFx._split(args); |
---|
573 | if(args.unhide){ |
---|
574 | connectUtil.connect(anim, "onEnd", anim, function(){ |
---|
575 | htmlUtil.style(node, { opacity: "1" }); |
---|
576 | }); |
---|
577 | }else{ |
---|
578 | connectUtil.connect(anim, "play", anim, function(){ |
---|
579 | htmlUtil.style(node, { opacity: "0" }); |
---|
580 | }); |
---|
581 | } |
---|
582 | return anim; // dojo.Animation |
---|
583 | }, |
---|
584 | |
---|
585 | unPinwheel: function(/*Object*/ args){ |
---|
586 | args.unhide = true; |
---|
587 | return dojoxFx.pinwheel(args); // dojo.Animation |
---|
588 | }, |
---|
589 | |
---|
590 | blockFadeOut: function(/*Object*/ args){ |
---|
591 | // summary: |
---|
592 | // Split a node into rectangular pieces and fade them |
---|
593 | // description: |
---|
594 | // Returns an animation that will split the node into a grid |
---|
595 | // of pieces that fade in or out. |
---|
596 | // args: |
---|
597 | // - args.rows: Integer - The number of horizontal pieces (default is 5) |
---|
598 | // - args.columns: Integer - The number of vertical pieces (default is 5) |
---|
599 | // - args.interval: Float - The number of milliseconds between each piece's animation (default is 0) |
---|
600 | // - args.random: Float - If true, pieces have a random delay. The value defines how much |
---|
601 | // randomness is introduced |
---|
602 | // - args.reverseOrder: Boolean - If true, pieces animate in reversed order |
---|
603 | // - args.unhide: Boolean - If true, the animation is reversed |
---|
604 | |
---|
605 | var node = args.node = dom.byId(args.node); |
---|
606 | |
---|
607 | args.rows = args.rows || 5; |
---|
608 | args.columns = args.columns || 5; |
---|
609 | args.duration = args.duration || 1000; |
---|
610 | args.interval = args.interval || args.duration / (args.rows + args.columns * 2); |
---|
611 | args.random = args.random || 0; |
---|
612 | var random = Math.abs(args.random), |
---|
613 | duration = args.duration - (args.rows + args.columns) * args.interval |
---|
614 | ; |
---|
615 | |
---|
616 | // Returns the animation object for each piece |
---|
617 | args.pieceAnimation = function(piece, x, y, coords){ |
---|
618 | var randomDelay = Math.random() * args.duration, |
---|
619 | uniformDelay = (args.reverseOrder) ? |
---|
620 | (((args.rows + args.columns) - (x + y)) * Math.abs(args.interval)) : |
---|
621 | ((x + y) * args.interval), |
---|
622 | delay = randomDelay * random + Math.max(1 - random, 0) * uniformDelay, |
---|
623 | // Create the animation object for the piece |
---|
624 | pieceAnimation = baseFx.animateProperty({ |
---|
625 | node: piece, |
---|
626 | duration: duration, |
---|
627 | delay: delay, |
---|
628 | easing: (args.easing || easingUtil.sinInOut), |
---|
629 | properties: { |
---|
630 | opacity: (args.unhide ? {start: "0", end: "1"} : {start: "1", end: "0"}) |
---|
631 | }, |
---|
632 | beforeBegin: (args.unhide ? function(){ htmlUtil.style(piece, { opacity: "0" });} : function(){ piece.style.filter = ""; }) |
---|
633 | }); |
---|
634 | |
---|
635 | return pieceAnimation; |
---|
636 | }; |
---|
637 | var anim = dojoxFx._split(args); |
---|
638 | if(args.unhide){ |
---|
639 | connectUtil.connect(anim, "onEnd", anim, function(){ |
---|
640 | htmlUtil.style(node, { opacity: "1" }); |
---|
641 | }); |
---|
642 | }else{ |
---|
643 | connectUtil.connect(anim, "onPlay", anim, function(){ |
---|
644 | htmlUtil.style(node, { opacity: "0" }); |
---|
645 | }); |
---|
646 | } |
---|
647 | return anim; // dojo.Animation |
---|
648 | }, |
---|
649 | |
---|
650 | blockFadeIn: function(/*Object*/ args){ |
---|
651 | args.unhide = true; |
---|
652 | return dojoxFx.blockFadeOut(args); // dojo.Animation |
---|
653 | } |
---|
654 | }); |
---|
655 | return fxExt; |
---|
656 | }); |
---|