-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_dom_delegate.html
80 lines (66 loc) · 2.52 KB
/
test_dom_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
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
<!doctype html>
<html>
<head>
<title>Test Page</title>
</head>
<body class="yui3-skin-sam">
<p>
<button id="unsub">Unsubscribe all</button>
</p>
<h3>Y.Event.delegate('click', prevent, '#links', '.x') - Prevent links except FB</h3>
<ul id="links">
<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.Event.delegate('click', incrementThenDetach, 'body', 'button.increment')</h3>
<button class="increment">Now helping #<span>0</span></button>
<h3>override <code>this</code> and pass sub args</h3>
<ul id="buttons">
<li><button>My name is <span>button</span></button></li>
<li>data-name='Jelly' <button data-name="Jelly">My name is <span>button</span></button></li>
<li>data-name='George' <button data-name="George">My name is <span>button</span></button></li>
<li>data-name='Angie' <button data-name="Angie">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-delegate.js"></script>
<script src="event-dom-delegate.js"></script>
<script>
YUI({
filter: 'raw'
}).use('eventx-dom-delegate', function (Y) {
var subs = [
Y.delegate("click", function (e) {
console.log("link clicked!", e);
e.preventDefault();
//e.detach();
}, '#links', '.x'),
Y.delegate('click', function (e) {
var counter = this.getElementsByTagName('span')[0];
counter.innerHTML = (+counter.innerHTML) + 1;
e.detach();
}, document.getElementsByTagName('body')[0], '.increment'),
/*
Y.delegate('click', function (e) {
var currentTarget = e.currentTarget,
name = currentTarget.getAttribute('data-name') || this.tagName;
currentTarget.getElementsByTagName('span')[0].innerHTML = name;
}, '#buttons', 'button'),
*/
Y.delegate('click', function (e, bang, lastName) {
var currentTarget = e.currentTarget,
name = currentTarget.getAttribute('data-name') || this.tagName;
currentTarget.getElementsByTagName('span')[0].innerHTML =
name + ' ' + lastName + (bang ? '!' : ' :(');
}, '#buttons', 'button', { tagName: 'Fred' }, true, 'Good')
];
Y.on('click', function () {
new Y.CustomEvent.Subscription(subs).detach();
}, '#unsub');
});
</script>
</body>
</html>