-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_dom.html
100 lines (85 loc) · 2.92 KB
/
test_dom.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
<!doctype html>
<html>
<head>
<title>Test Page</title>
</head>
<body class="yui3-skin-sam">
<h3>Y.on('click', prevent, '.x') - Prevent links except FB</h3>
<ul>
<li><a href="http://yahoo.com" class="x">Yahoo</a></li>
<li><a href="http://google.com" class="x">Google</a></li>
<li><a href="http://facebook.com" class="y">Facebook</a></li>
<li><a href="http://twitter.com" class="x">Twitter</a></li>
</ul>
<h3>Y.on('click', incrementThenDetach, 'button.increment')</h3>
<button id="increment">Now helping #<span>0</span></button>
<h3>override <code>this</code> and pass sub args</h3>
<ul>
<li>All defaults <button id="name">My name is <span>button</span></button></li>
<li>this: { tagName: 'Fred' } <button id="thisOverride">My name is <span>button</span></button></li>
<li>args: 'Fred', true <button id="args">My name is <span>button</span></button></li>
<li>this: { tagName: 'Angie' }, args: true, 'Good' <button id="thisAndArgs">My name is <span>button</span></button></li>
</ul>
<script src="http://yui.yahooapis.com/3.8.1/build/yui/yui.js"></script>
<script src="event.js"></script>
<script src="event-dom.js"></script>
<script>
YUI({
filter: 'raw'
}).use('eventx-dom', function (Y) {
Y.on("click", function (e) {
console.log("Link node clicked!", e);
e.preventDefault();
//e.detach();
}, '.x');
Y.on('click', function (e) {
var counter = this.getElementsByTagName('span')[0];
counter.innerHTML = (+counter.innerHTML) + 1;
e.detach();
}, document.getElementById('increment'));
Y.on('click', function (e) {
e.currentTarget.getElementsByTagName('span')[0].innerHTML =
this.tagName;
}, '#name');
Y.on('click', function (e) {
e.currentTarget.getElementsByTagName('span')[0].innerHTML =
this.tagName;
}, '#thisOverride', { tagName: 'Fred' });
Y.on('click', function (e, name, bool) {
e.currentTarget.getElementsByTagName('span')[0].innerHTML =
name + (bool ? '!' : ' :(');
}, '#args', null, 'Fred', true);
Y.on('click', function (e, bool, lastName) {
e.currentTarget.getElementsByTagName('span')[0].innerHTML =
this.tagName + ' ' + lastName + (bool ? '!' : ' :(');
}, '#thisAndArgs', { tagName: 'Angie' }, true, 'Good');
Y.on('test', function (data) {
console.log('custom event from Y: ', data);
});
Y.publish({
foo: {
emitFacade: true,
defaultFn: function (e) {
console.log('foo defaultFn. Should be an EventFacade ->', e);
}
},
bar: {
fire: function (target, type, e) {
this._super.fire.apply(this, arguments);
console.log('after the after() subs on bar. Should be undefined ->', e);
}
}
});
Y.on('bar', function (e) {
console.log('on("bar"). Should be undefined ->', e);
});
Y.after('bar', function (e) {
console.log('after("bar"). Should be undefined ->', e);
});
Y.fire('test', { payload: 'Hi there' })
.fire('foo')
.fire('bar');
});
</script>
</body>
</html>