Also apply the __toString fix to UserInfo
[cacert-mgr.git] / external / ZendFramework-1.9.5 / externals / dojo / demos / mojo / src / drop.js
1 dojo.provide("demos.mojo.src.drop");
2 // adds gravity effect to mojoDemo
3 dojo.require("dojo.fx");
4 dojo.require("dojo.fx.easing");
5 dojo.require("dijit._base.place");
6 (function(){
7
8 var mojo = {};
9 var nodes;
10 var _coords = [];
11 var cb = null;
12
13 dojo.mixin(mojo, {
14 drop: {
15 _calcPositions: function(e){
16 // store or return the current calculated positions of each ball
17 var c = [];
18 nodes.forEach(function(n){
19 c.push(dojo.coords(n));
20 });
21
22 if(e){
23 _coords = c; // with luck maybe in this limited scope, but this is bad.
24 }
25 return c; // Array
26 },
27 dropNodes: function(){
28 // summary: drop all the nodes using the bounce easing function
29
30 _coords = mojo.drop._calcPositions(); // store positions for later
31 // ball is 310px, so the bottom edges are height - 310 roughly.
32 var t = dijit.getViewport().h - 310;
33 dojo.style(dojo.body(),"overflow","hidden");
34
35 var _anims = [];
36 nodes.forEach(function(n,idx){
37 // we want to keep the left: attribute in tact, so pass it along
38 var l = _coords[idx].l;
39 _anims.push(dojo.fx.slideTo({
40 top:t, left:l, node:n,
41 duration:1000,
42 easing:dojo.fx.easing.bounceOut
43 }));
44 });
45 // play the _anims as one animation
46 dojo.fx.combine(_anims).play();
47 },
48 floatNodes: function(){
49 // summary: reset all the nodes to the orig. positions
50 var _anims = [];
51 nodes.forEach(function(n,idx){
52 // push each slide animation in _anims, based on it's stored coords
53 var t = _coords[idx].t;
54 var l = _coords[idx].l;
55 _anims.push(dojo.fx.slideTo({
56 top: t, left:l, node:n,
57 duration:500
58 }));
59 });
60 // play the anim, and set overflow:auto on body
61 var _anim = dojo.fx.combine(_anims);
62 var con = dojo.connect(_anim,"onEnd",function(){
63 dojo.style(dojo.body(), "overflow", "visible");
64 });
65 _anim.play();
66 }
67 }
68 })
69
70 var _toggleGravity = function(e){
71 // drop or float the nodes based on the state of the checkbox
72 mojo.drop[(cb.checked ? "dropNodes" : "floatNodes")]();
73 };
74
75 dojo.addOnLoad(function(){
76 // convenience:
77 nodes = dojo.query("#container > div");
78
79 // setup the "gravity toggler"
80 cb = dojo.byId("gravity");
81 cb.checked = false;
82 // FIXME: ie7 fires onchange after blur() ... ugh
83 dojo.connect(cb,"onchange",_toggleGravity);
84
85 // just in case, because our nodes are absolutely positioned:
86 dojo.connect(window,"onresize",mojo.drop,"_calcPositions");
87
88 // lets make the logo drag/snap-able, too.
89 new dojo.dnd.Moveable("logoImg");
90 dojo.style("logoImg","cursor","move");
91 });
92
93 })();