source: Dev/branches/rest-dojo-ui/client/dojo/tests/fx.html @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 13.3 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2        "http://www.w3.org/TR/html4/strict.dtd">
3<html>
4        <head>
5                <title>Testing dojo.fx</title>
6                <script type="text/javascript" src="../dojo.js" data-dojo-config="isDebug:true"></script>
7                <script type="text/javascript">
8                        require(["dojo", "doh", "dojo/fx", "dojo/fx/easing", "dojo/domReady!"], function(dojo, doh){
9                                doh.register("t",
10                                        [
11                                                function slideTo(t){
12                                                        var s = dojo.fx.slideTo({
13                                                                node: "foo",
14                                                                duration: 500,
15                                                                left: 500,
16                                                                top: 50
17                                                        }).play();
18                                                        var d = new doh.Deferred();
19                                                        dojo.connect(s, "onEnd", function(){
20                                                                doh.is(dojo.style("foo", "left"), 500);
21                                                                doh.is(dojo.style("foo", "top"), 50);
22                                                                with(dojo.byId("foo").style){
23                                                                        position = left = top = "";
24                                                                }
25                                                                d.callback(true);
26                                                        });
27                                                        s.play();
28                                                        return d;
29                                                },
30
31                                                function wipeOut(t){
32                                                        dojo.byId("foo").style.height = "";
33                                                        var d = new doh.Deferred();
34                                                        var s = dojo.fx.wipeOut({
35                                                                node: "foo",
36                                                                onEnd: function(){
37                                                                        doh.t(dojo.style("foo", "height") < 5);
38                                                                        d.callback(true);
39                                                                }
40                                                        }).play();
41                                                        return d;
42                                                },
43                                               
44                                                function wipeIn(t){
45                                                        var d = new doh.Deferred();
46                                                        setTimeout(function(){
47                                                                dojo.fx.wipeIn({
48                                                                        node: "foo",
49                                                                        onEnd: function(){
50                                                                                console.debug(dojo.style("foo", "height"));
51                                                                                doh.t(dojo.style("foo", "height") > 10);
52                                                                                d.callback(true);
53                                                                        }
54                                                                }).play();
55                                                        }, 10);
56                                                        return d;
57                                                },
58
59                                                {
60                                                        name: "chain",
61                                                        timeout: 1500,
62                                                        runTest: function(t){
63                                                                dojo.byId("foo").style.height = "0px";
64                                                                var d = new doh.Deferred();
65                                                                var w = dojo.fx.wipeIn({
66                                                                        node: "foo",
67                                                                        duration: 500
68                                                                });
69                                                                var f = dojo.fadeOut({
70                                                                        node: "foo",
71                                                                        duration: 500
72                                                                });
73                                                                var a = dojo.fx.chain([w,f]);
74                                                                dojo.connect(a, "onEnd", function(){
75                                                                        doh.t((w.status()=="stopped"&&f.status()=="stopped"));
76                                                                        d.callback(true);
77                                                                });
78                                                                a.play();
79                                                                return d;
80                                                        }
81                                                },
82                                               
83                                                {
84                                                        name: "combine",
85                                                        timeout: 1500,
86                                                        runTest: function(t){
87                                                                dojo.byId("foo").style.height = "0px";
88                                                                var d = new doh.Deferred();
89                                                                var w = dojo.fx.wipeIn({
90                                                                        node: "foo",
91                                                                        duration: 500
92                                                                });
93                                                                var f = dojo.fadeIn({
94                                                                        node: "foo",
95                                                                        duration: 1000
96                                                                });
97                                                                var a = dojo.fx.combine([w,f]);
98                                                                dojo.connect(a, "onEnd", function(){
99                                                                        doh.t((w.status()=="stopped"&&f.status()=="stopped"));
100                                                                        d.callback(true);
101                                                                });
102                                                                a.play();
103                                                                return d;
104                                                        }
105                                                },
106                                                {
107                                                        name:"combineBeforeBegin",
108                                                        timeout:1500,
109                                                        runTest: function(t){
110                                                                var d = new doh.Deferred();
111                                                                var a = dojo.fadeOut({ node:"foo2", duration:400 });
112                                                                var b = dojo.fadeIn({ node:"foo2", duration:400 });
113                                                                var chain = dojo.fx.combine([a,b]);
114                                                                dojo.connect(chain,"beforeBegin",dojo.hitch(d,"callback",true));
115                                                                chain.play();
116                                                                return d;
117                                                        }
118                                                       
119                                                },
120                                                {
121                                                        name:"delayTest",
122                                                        timeout:2000,
123                                                        runTest:function(t){
124                                                                var d = new doh.Deferred();
125                                                                var delay = 100;
126                                                                var _anims = [];
127                                                                var nodes = ["a","b","c","d"];
128                                                                dojo.forEach(nodes,function(n){
129                                                                        _anims.push(dojo.fadeOut({ node:n, duration:100, delay: delay += 100 }));
130                                                                });
131                                                                var a = dojo.fx.combine(_anims);
132                                                                var timer = (new Date()).getTime();
133                                                                dojo.connect(a,"onEnd",function(){
134                                                                        console.warn("delayTest running time:", (new Date()).getTime() - timer, "ms, expected:", a.duration, "ms");
135                                                                        d.callback(true);
136                                                                });
137                                                                a.play();
138                                                                return d;       
139                                                        }
140                                                },
141                                                {
142                                                        name:"delayTestChain",
143                                                        timeout:2200,
144                                                        runTest:function(t){
145                                                                var d = new doh.Deferred();
146                                                                var delay = 100;
147                                                                var _anims = [];
148                                                                var nodes = ["a","b","c","d"];
149                                                                dojo.forEach(nodes,function(n){
150                                                                        _anims.push(dojo.fadeIn({ node:n, duration:100, delay: delay += 100 }));
151                                                                });
152                                                                var a = dojo.fx.chain(_anims);
153                                                                var timer = (new Date()).getTime();
154                                                                dojo.connect(a,"onEnd",function(){
155                                                                        console.warn("delayTestChain running time:", (new Date()).getTime() - timer, "ms, expected:", a.duration, "ms");
156                                                                        d.callback(true);
157                                                                });
158                                                                a.play();
159                                                                return d;
160                                                        }
161                                                },
162                                                {
163                                                        name:"combineOnEnd",
164                                                        timeout:1500,
165                                                        runTest: function(t){
166                                                                var d = new doh.Deferred();
167                                                                var a = dojo.fadeOut({ node:"foo2", duration:400 });
168                                                                var b = dojo.fadeIn({ node:"foo2", duration:400 });
169                                                                var combine = dojo.fx.combine([a,b]);
170                                                                dojo.connect(combine,"onEnd",dojo.hitch(d,"callback",true));
171                                                                combine.play();
172                                                                return d;
173                                                        }
174                                                       
175                                                },
176                                                {
177                                                        name:"combineOnPlay",
178                                                        timeout:1500,
179                                                        runTest: function(t){
180                                                                var d = new doh.Deferred();
181                                                                var a = dojo.fadeOut({ node:"foo2", duration:400 });
182                                                                var b = dojo.fadeIn({ node:"foo2", duration:400 });
183                                                                var combine = dojo.fx.combine([a,b]);
184                                                                dojo.connect(combine,"onPlay",dojo.hitch(d,"callback",true));
185                                                                combine.play();
186                                                                return d;
187                                                        }
188                                                       
189                                                },
190                                                {
191                                                        name:"chainOnEnd",
192                                                        timeout:1500,
193                                                        runTest: function(t){
194                                                                var d = new doh.Deferred();
195                                                                var a = dojo.fadeOut({ node:"foo2", duration:400 });
196                                                                var b = dojo.fadeIn({ node:"foo2", duration:400 });
197                                                                var chain = dojo.fx.chain([a,b]);
198                                                                dojo.connect(chain,"onEnd",dojo.hitch(d,"callback",true));
199                                                                chain.play();
200                                                                return d;
201                                                        }
202                                                       
203                                                },
204                                                {
205                                                        name:"chainOnPlay",
206                                                        timeout:1500,
207                                                        runTest: function(t){
208
209                                                                var d = new doh.Deferred();
210                                                                var a = dojo.fadeOut({ node:"foo2", duration:200 });
211                                                                var b = dojo.fadeIn({ node:"foo2", duration:200 });
212                                                                var chain = dojo.fx.chain([a,b]);
213                                                                dojo.connect(chain,"onPlay",dojo.hitch(d,"callback",true));
214                                                                chain.play();
215                                                                return d;
216                                                        }
217                                                       
218                                                },
219                                               
220                                                {
221                                                        name:"stopDelay",
222                                                        timeout:1500,
223                                                        runTest: function(t){
224                                                               
225                                                                var d = new doh.Deferred();
226                                                                var a = dojo.fadeOut({ node: "foo2", delay:400 });
227                                                                dojo.connect(a, "onPlay", dojo.hitch(d, "errback", true));
228                                                                a.play();
229                                                                a.stop();
230                                                                setTimeout(function(){
231                                                                        d.callback(true);
232                                                                }, 500);
233                                                                return d;
234                                                        }
235                                                },
236                                               
237                                                {
238                                                        name:"stopDelayPassed",
239                                                        timeout:1500,
240                                                        runTest: function(t){
241                                                       
242                                                                var d = new doh.Deferred();
243                                                                var b = dojo.fadeIn({ node: "foo2" });
244                                                                dojo.connect(b, "onPlay", dojo.hitch(d, "errback", true));
245                                                                b.play(400);
246                                                                b.stop();
247                                                                setTimeout(function(){
248                                                                        d.callback(true);
249                                                                }, 600);
250                                                                return d;
251                                                        }
252                                                       
253                                                },
254                                               
255                                                function Toggler(){
256                                                        var d = new doh.Deferred();
257                                                        var t = new dojo.fx.Toggler({
258                                                                node: "foo",
259                                                                hideDuration: 100,
260                                                                hideFunc: dojo.fx.wipeOut,
261                                                                showFunc: dojo.fx.wipeIn
262                                                        });
263                                                        t.hide();
264                                                        setTimeout(function(){
265                                                                var sa = t.show();
266                                                                dojo.connect(sa, "onEnd", dojo.hitch(d, "callback", true));
267                                                        }, 50);
268                                                        return d;
269                                                },
270                                               
271                                                function combineChain(t){
272                                                        // test combining two chained() animations
273                                                        var anim1 = dojo.fx.chain([
274                                                                dojo.fadeIn({ node:"chained" }),
275                                                                dojo.fadeOut({ node:"chained" })
276                                                        ]);
277                                                        var anim2 = dojo.fx.chain([
278                                                                dojo.fadeOut({ node:"chainedtoo" }),
279                                                                dojo.fadeIn({ node:"chainedtoo" })
280                                                        ]);
281                                                       
282                                                        var anim = dojo.fx.combine([anim1, anim2]);
283
284                                                        var d = new doh.Deferred();
285                                                        dojo.connect(anim, "onEnd", dojo.hitch(d, "callback", true));
286                                                        anim.play();
287                                                },
288                                               
289                                                function chainCombine(t){
290                                                        // test chaining two combined() animations
291                                                        var anim1 = dojo.fx.combine([
292                                                                dojo.fadeIn({ node:"chained" }),
293                                                                dojo.fadeOut({ node:"chainedtoo" })
294                                                        ]);
295                                                        var anim2 = dojo.fx.combine([
296                                                                dojo.fadeOut({ node:"chained" }),
297                                                                dojo.fadeIn({ node:"chainedtoo" })
298                                                        ]);
299                                                       
300                                                        var anim = dojo.fx.chain([anim1, anim2]);
301
302                                                        var d = new doh.Deferred();
303                                                        dojo.connect(anim, "onEnd", dojo.hitch(d, "callback", true));
304                                                        anim.play();
305
306                                                },
307                                               
308                                                function easingNames(t){
309                                                        for(var i in dojo.fx.easing){
310                                                                t.assertTrue(dojo.isFunction(dojo.fx.easing[i]));
311                                                        }
312                                                },
313                                               
314                                                function easingReturns(t){
315                                                        for(var i in dojo.fx.easing){
316                                                                t.assertTrue(!isNaN(dojo.fx.easing[i](0.5)));
317                                                        }
318                                                },
319                                               
320                                                {
321                                                        name:"onendStatus-chain",
322                                                        timeout:1500,
323                                                        runTest: function(t){
324                                                                var d = new doh.Deferred;
325                                                               
326                                                                var a1 = dojo.fadeOut({ node:"a1" });
327                                                                var a2 = dojo.fadeOut({ node:"a2" });
328                                                               
329                                                                var anim = dojo.fx.chain([a1, a2]);
330                                                                dojo.connect(anim, "onEnd", function(){
331                                                                        t.is("stopped", a1.status());
332                                                                        t.is("stopped", a2.status());
333                                                                        t.is("stopped", anim.status());
334                                                                        d.callback(true);
335                                                                });
336                                                               
337                                                                anim.play();
338                                                               
339                                                                return d;
340                                                        }
341                                                },     
342                                                {
343                                                        name:"onendStatus-combine",
344                                                        timeout:1500,
345                                                        runTest: function(t){
346                                                                var d = new doh.Deferred;
347
348                                                                var a1 = dojo.fadeOut({ node:"a1" });
349                                                                var a2 = dojo.fadeOut({ node:"a2" });
350
351                                                                var anim = dojo.fx.combine([a1, a2]);
352                                                                dojo.connect(anim, "onEnd", function(){
353                                                                        t.is("stopped", a1.status());
354                                                                        t.is("stopped", a2.status());
355                                                                        setTimeout(function(){
356                                                                                t.is("stopped", anim.status());
357                                                                                d.callback(true);       
358                                                                        }, 10);
359                                                                });
360
361                                                                anim.play();
362                                                                return d;
363                                                        }
364                                                },
365                                                {
366                                                        name: "wipeOut onStop",
367                                                        timeout: 1500,
368                                                        runTest: function(t){
369                                                                dojo.byId("foo").style.height = "auto";
370                                                                dojo.byId("foo").style.overflow = "visible";
371                                                                var d = new doh.Deferred();
372                                                                var w = dojo.fx.wipeOut({
373                                                                        node: "foo",
374                                                                        duration: 1000
375                                                                });
376                                                                dojo.connect(w, "onStop", function(){
377                                                                        doh.t(dojo.byId("foo").style.overflow == "visible");
378                                                                        d.callback(true);
379                                                                });
380                                                                w.play();
381                                                                setTimeout(function(){ w.stop(); }, 100);
382                                                                return d;
383                                                        }
384                                                },
385                                                {
386                                                        name: "wipeIn onStop",
387                                                        timeout: 1500,
388                                                        runTest: function(t){
389                                                                dojo.byId("foo").style.height = "0px";
390                                                                dojo.byId("foo").style.overflow = "visible";
391                                                                var d = new doh.Deferred();
392                                                                var w = dojo.fx.wipeIn({
393                                                                        node: "foo",
394                                                                        duration: 1000
395                                                                });
396                                                                dojo.connect(w, "onStop", function(){
397                                                                        doh.t(dojo.byId("foo").style.overflow == "visible");
398                                                                        d.callback(true);
399                                                                });
400                                                                w.play();
401                                                                setTimeout(function(){ w.stop(); }, 100);
402                                                                return d;
403                                                        }
404                                                }
405                                        ]
406                                );
407                                doh.run();
408                        });
409                </script>
410                <style type="text/css">
411                        @import "../resources/dojo.css";
412
413                        body {
414                                text-shadow: 0px 0px;
415                                margin: 1em;
416                                background-color: #DEDEDE;
417                        }
418
419                        .box {
420                                color: #292929;
421                                /* color: #424242; */
422                                /* text-align: left; */
423                                width: 300px;
424                                border: 1px solid #BABABA;
425                                background-color: white;
426                                padding-left: 10px;
427                                padding-right: 10px;
428                                margin-left: 10px;
429                                margin-bottom: 1em;
430                                -o-border-radius: 10px;
431                                -moz-border-radius: 12px;
432                                -webkit-border-radius: 10px;
433                                -webkit-box-shadow: 0px 3px 7px #adadad;
434                                /* -opera-border-radius: 10px; */
435                                border-radius: 10px;
436                                -moz-box-sizing: border-box;
437                                -opera-sizing: border-box;
438                                -webkit-box-sizing: border-box;
439                                -khtml-box-sizing: border-box;
440                                box-sizing: border-box;
441                                overflow: hidden;
442                                /* position: absolute; */
443                        }
444                </style>
445        </head>
446        <body>
447                <div class="box" id="a">a</div><div class="box" id="b">b</div>
448                <div class="box" id="c">c</div><div class="box" id="d">d</div>
449       
450                <div id="foo" class="box">
451                        <p>
452                        Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
453                        semper sagittis velit. Cras in mi. Duis porta mauris ut ligula.
454                        Proin porta rutrum lacus. Etiam consequat scelerisque quam. Nulla
455                        facilisi. Maecenas luctus venenatis nulla. In sit amet dui non mi
456                        semper iaculis. Sed molestie tortor at ipsum. Morbi dictum rutrum
457                        magna. Sed vitae risus.
458                        </p>
459                        <p>
460                        Aliquam vitae enim. Duis scelerisque metus auctor est venenatis
461                        imperdiet. Fusce dignissim porta augue. Nulla vestibulum. Integer
462                        lorem nunc, ullamcorper a, commodo ac, malesuada sed, dolor. Aenean
463                        id mi in massa bibendum suscipit. Integer eros. Nullam suscipit
464                        mauris. In pellentesque. Mauris ipsum est, pharetra semper,
465                        pharetra in, viverra quis, tellus. Etiam purus. Quisque egestas,
466                        tortor ac cursus lacinia, felis leo adipiscing nisi, et rhoncus
467                        elit dolor eget eros. Fusce ut quam. Suspendisse eleifend leo vitae
468                        ligula. Nulla facilisi. Nulla rutrum, erat vitae lacinia dictum,
469                        pede purus imperdiet lacus, ut semper velit ante id metus. Praesent
470                        massa dolor, porttitor sed, pulvinar in, consequat ut, leo. Nullam
471                        nec est. Aenean id risus blandit tortor pharetra congue.
472                        Suspendisse pulvinar.
473                        </p>
474                </div>
475                <div id="foo2">foo2</div>
476               
477                <div>
478                        <p id="chained">foo</p><p id="chainedtoo">bar</p>
479                </div>
480               
481                <p id="a1">p</p><p id="a2">p</p>
482               
483        </body>
484</html>
Note: See TracBrowser for help on using the repository browser.