-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_delegate.html
47 lines (40 loc) · 1.2 KB
/
test_delegate.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
<!doctype html>
<html>
<head>
<title>Test Page</title>
</head>
<body class="yui3-skin-sam">
<p id="x">Treasure</p>
<script src="http://yui.yahooapis.com/3.8.1/build/yui/yui.js"></script>
<script src="event.js"></script>
<script src="event-delegate.js"></script>
<script>
YUI({
filter: 'raw'
}).use('eventx-delegate', function (Y) {
function C(name) {
this.name = name;
Y.EventTarget.call(this);
}
Y.extend(C, Y.EventTarget);
Y.EventTarget.configure(C, null, { emitFacade: true });
var c = new C("Little C"),
bigC = new C("Big C"),
ultraC = new C("Ultra C"),
lateralC = new C("Lateral C");
c.addTarget(bigC); // Should get event second
c.addTarget(lateralC); // Should get event third
bigC.addTarget(ultraC); // Should get event fourth
bigC.addTarget(lateralC); // Should NOT get event a second time
ultraC.addTarget(lateralC); // Should NOT get event a second time
lateralC.delegate('test', function (e) {
console.log('Delegated from Lateral C, heard ' + this.name, e, this);
}, function (e) {
console.log('Testing ' + e.data.currentTarget.name);
return /^(?:Little|Big)/.test(e.data.currentTarget.name);
}, { name: 'Overridden' });
c.fire('test');
});
</script>
</body>
</html>