-
Notifications
You must be signed in to change notification settings - Fork 334
/
test.html
166 lines (134 loc) · 4.01 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>
YUI Raphael Sandbox
</title>
<style>
.buttons {
position: absolute;
top:0px; right:0px;
}
</style>
</head>
<body class=" yui-skin-sam">
<div id="rcanvas"></div>
<div class="buttons">
<button id="hide">Hide</button><br/>
<button id="show">Show</button>
<hr/>
<button id="animate">Animate</button><br/>
<button id="rotate">Rotate</button><br/>
<button id="yellow">Yellow</button><br/>
<button id="creep">Creep</button>
<hr/>
<button id="whatColor">What Color?</button>
<hr/>
<button id="remove">Remove</button><br/>
<button id="clear">Clear</button>
<br/>
<div id='log'></div>
</div>
<script type="text/javascript" src="http://yui.yahooapis.com/combo?3.2.0/build/yui/yui-debug.js"></script>
<script type="text/javascript" src="../build_tmp/gallery-raphael-debug.js"></script>
<script>
YUI({debug: true, useConsole: true}).use('gallery-raphael', function(Y) {
var log = Y.one('#log');
function alert(s) {
log.set('innerHTML', s);
}
var plugins = [
'r-test-plugin-canvas.js',
'r-test-plugin-element.js'
];
Y.Raphael({type:'raw'}).use(plugins, function(Raphael) {
// use Raphael just like normal
var paper = Raphael('rcanvas', 600, 800),
rect, circ, ellipse, img, group, redText;
paper.setSize(600, 799);
// create SVG objects normally as well
rect = paper.rect(0,0,100,200);
rect.attr({fill: 'cyan', stroke: '#000', 'stroke-width': 1});
circ = paper.circle(200, 200, 80);
circ.attr({fill: 'red', stroke: '#333', 'stroke-width': 5});
ellipse = paper.ellipse(20, 40, 400, 30);
ellipse.attr({fill: 'yellow'});
ellipse.$node.on('mouseover', function() {
rect.animate({
"20%": {cx: 20, r: 20, easing: ">"},
"50%": {cx: 70, r: 120},
"100%": {cx: 10, r: 10}
}, 2000);
});
img = paper.image('../../../../../../../Pictures/gi_christ.jpg', 300,300,150,100)
img.node.onclick = function() {
alert('manual onclick');
}
// but now each has a .$node property that is a Y.Node wrapped around the SVG HTMLElement
circ.$node.on('click', function() {
// and each object Raphael creates is an EventTarget, so we can fire events now
circ.fire('bam');
});
// listening for circle events
circ.on('bam', function() {
alert('it worked');
});
// use .$node as a normal Y.Node for event handling
rect.$node.on('mouseover', function() {
circ.attr('fill', 'blue').attr('stroke', '#123432').attr('stroke-width', 1);
});
rect.$node.on('mouseout', function() {
circ.attr({fill: 'red', stroke: '#333', 'stroke-width': 5});
});
group = paper.set();
group.push(circ, rect, ellipse, img);
group.attr({fill: 'cyan', stroke: '#000', 'stroke-width': 1});
redText = paper.redtext(300,100, 'red text');
Y.one('#clear').on('click', function() {
paper.clear();
});
Y.one('#remove').on('click', function() {
group.pop().remove();
});
Y.one('#hide').on('click', function() {
circ.hide();
});
Y.one('#show').on('click', function() {
circ.show();
});
Y.one('#rotate').on('click', function() {
group.rotate(45);
ellipse.rotate(10);
});
Y.one('#creep').on('click', function() {
group.translate(10, 1);
img.translate(-10, -33);
});
Y.one('#animate').on('click', function() {
var c = circ;
c.animate({cx: 20, r: 20}, 2000);
c.animate({cx: 20, r: 20}, 2000, "bounce");
c.animate({
"20%": {cx: 20, r: 20, easing: ">"},
"50%": {cx: 70, r: 120},
"100%": {cx: 10, r: 10}
}, 2000);
});
Y.one('#whatColor').on('click', function() {
var stroke = Raphael.getRGB(circ.attr("fill")).hex;
alert(stroke);
});
Y.one('#yellow').on('click', function() {
Y.Array.each(group, function(it) {
it.yellow();
});
});
var angle = Raphael.angle(10, 10, 50, 50);
alert(angle);
});
});
</script>
</body>
</html>