-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_node.html
106 lines (88 loc) · 3.18 KB
/
test_node.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
<!doctype html>
<html>
<head>
<title>Test Page</title>
</head>
<body class="yui3-skin-sam">
<h3>Y.all('.x').on('click', prevent) - 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>node.on('click', incrementThenDetach)</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 src="event-node.js"></script>
<script>
YUI({
filter: 'raw'
}).use('eventx-node', function (Y) {
var links = Y.all('.x'),
increment = Y.one('#increment');
links.on("click", function (e) {
console.log('link(url=' + this.get('href') + ') clicked!', e);
e.preventDefault();
// This shouldn't do anything because the 'test' custom event was
// subscribed to the NodeList, not the link node
this.fire('test');
});
increment.on('click', function (e) {
var counter = this.one('span')._node;
counter.innerHTML = (+counter.innerHTML) + 1;
e.detach();
this.fire('test')
.fire('foo')
.fire('bar');
});
Y.one('#name').on('click', function (e) {
e.currentTarget.one('span')._node.innerHTML = this.get('tagName');
});
Y.one('#thisOverride').on('click', function (e) {
e.currentTarget.one('span')._node.innerHTML = this.tagName;
}, { tagName: 'Fred' });
Y.one('#args').on('click', function (e, name, bool) {
this.one('span')._node.innerHTML = name + (bool ? '!' : ' :(');
}, null, 'Fred', true);
Y.one('#thisAndArgs').on('click', function (e, bool, lastName) {
e.currentTarget.one('span')._node.innerHTML =
this.tagName + ' ' + lastName + (bool ? '!' : ' :(');
}, { tagName: 'Angie' }, true, 'Good');
// Custom events on Node and NodeList
links.on('test', function (e) {
console.log('test custom event from the .x links nodelist: ', e);
});
increment.on('test', function (e) {
console.log('test custom event from the #increment node: ', e);
});
increment.publish({
foo: { defaultFn: function (e) { console.log('foo defaultFn', e); } },
bar: {
fire: function (target, e) {
this._super.fire.apply(this, arguments);
console.log('after the after() subs on bar', e);
}
}
});
increment.on('bar', function (e) {
console.log('on("bar")', e);
});
increment.after('bar', function (e) {
console.log('after("bar")', e);
});
// Just to make sure firing custom events works for NodeLists
links.fire('test', { payload: 'Hi there' });
});
</script>
</body>
</html>