Debian Codegraph @

dojox/gfx/tests/svgweb/test_fx_shapes.html

raw symbols SCIP
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html lang="en">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5 <title>Animate rectangles</title>
6 <!--<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/dojo.xd.js"></script>-->
7 <!-- SVGWEB { -->
8 <meta name="svg.render.forceflash" content="true"/>
9 <script src="svgweb/src/svg.js" data-path="svgweb/src"></script>
10 <script src="../../../../dojo/dojo.js" data-dojo-config="isDebug:true,forceGfxRenderer:'svg'" type="text/javascript"></script>
11 <!-- } -->
12 <script type="text/javascript" charset="utf-8">
13 dojo.require("dojox.gfx");
14 dojo.require("dojo.fx");
15 dojo.require("dojo.fx.easing");
16 dojo.require("dojox.fx.easing");
17
18 var WIDTH = 600, HEIGHT = 400,
19 BAR_GAP = 20, BAR_WIDTH = 76,
20 BAR_FILL = "red", BAR_STROKE = "black",
21 CHAIN_DURATION = 250, COMBINE_DURATION = 1000;
22
23 var surface, rects = [];
24
25 var enable = function(enabled){
26 // enable/disable controls on the page
27 dojo.query("input, select, button, textarea").attr("disabled", !enabled);
28 };
29
30 var empty = {};
31 var populateSelect = function(from, select){
32 var module = dojo.getObject(from);
33 for(var name in module){
34 if(name in empty){ continue; }
35 var fun = module[name];
36 if(dojo.isFunction(fun)){
37 dojo.create("option", {
38 value: from + "." + name,
39 selected: name == "backOut",
40 innerHTML: from + "." + name
41 }, select);
42 }
43 }
44 };
45
46 var animate = function(){
47 // disable controls
48 enable(false);
49
50 // get old heights
51 var oldHeights = dojo.map(rects, function(rect){ return rect.getShape().height; });
52
53 // generate new heights (can't be 0 on IE/VML!)
54 var newHeights = dojo.map(rects, function(){ return 1 + Math.random() * (HEIGHT - 1); });
55
56 // get parameters
57 var duration = dojo.byId("chain").checked ? CHAIN_DURATION : COMBINE_DURATION,
58 easing = dojo.getObject(dojo.byId("easing").value);
59
60 // create animations between heights
61 var animations = dojo.map(rects, function(rect, i){
62 // create animation
63 var anim = new dojo._Animation({
64 duration: duration,
65 easing: easing,
66 curve: [oldHeights[i], newHeights[i]]
67 });
68 // update the rectangle on every tick
69 dojo.connect(anim, "onAnimate", function(height){
70 var shape = rect.getShape();
71 shape.y = HEIGHT - height;
72 shape.height = height;
73 rect.setShape(shape);
74 });
75 return anim;
76 });
77 // combine all animations
78 var masterAnimation = dojo.byId("chain").checked ?
79 dojo.fx.chain(animations) : dojo.fx.combine(animations);
80 // enable controls when they are done
81 dojo.connect(masterAnimation, "onEnd", function(){ enable(true); });
82 // start the animation
83 masterAnimation.play();
84 }
85
86 var init = function(){
87 // create surface
88 surface = dojox.gfx.createSurface(dojo.byId("surface"), 600, 400);
89
90 /* SVGWEB { */
91 surface.whenLoaded(function() {
92 // create rectangles
93 for(var w = BAR_GAP; w < WIDTH - BAR_WIDTH; w += BAR_WIDTH + BAR_GAP){
94 rects.push(surface.createRect({
95 x: w, y: HEIGHT, width: BAR_WIDTH, height: 1
96 }).setFill(BAR_FILL).setStroke(BAR_STROKE));
97 }
98 // IE/VML doesn't allow height to be 0!
99
100 // prepare and enable controls
101 populateSelect("dojo.fx.easing", "easing");
102 if(dojox.fx.easing !== dojo.fx.easing){
103 populateSelect("dojox.fx.easing", "easing");
104 }
105 dojo.attr("chain", "checked", false);
106 dojo.connect(dojo.byId("animate"), "onclick", animate);
107 enable(true);
108 });
109 /* } */
110 };
111
112 dojo.addOnLoad(init);
113 </script>
114 </head>
115 <body>
116 <p>
117 <button id="animate" disabled="disabled">Animate!</button>&nbsp;
118 <label>Easing:&nbsp;<select id="easing" disabled="disabled"></select></label>&nbsp;
119 <label><input id="chain" type="checkbox" disabled="disabled">&nbsp;Chain (otherwise Combine)</label>
120 </p>
121 <div id="surface" style="width: 600px; height: 400px; border:1px solid #000;"></div>
122 </body>
123 </html>