My favorites | Sign in
Project Logo
                
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>YUI Event Bus Example</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Alex Reid">
<!-- Date: 2009-07-15 -->
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
</head>
<body>

<h1>YUI Event Bus Example</h1>

<div id="addedHandlers">
<div id="h"></div>
</div>

<button id="b">Fire a PersonListLoaded event</button><br/>
<button id="b2">Add another handler widget</button>

<script>
/***
* YUI custom event example
* @author Alex Reid
**/
(function() {
// Custom event
var PersonListLoadedEvent = new YAHOO.util.CustomEvent("PersonListLoadedEvent");
var panel = YAHOO.util.Dom.get("h");

// Handler widget (consumer)
function HandlerWidget() {
PersonListLoadedEvent.subscribe(this.onPersonListLoaded, this);
this.setText = function(t) {
this.element.innerHTML = t;
}
this.element = document.createElement("div");
this.element.id = YAHOO.util.Dom.generateId();
panel.appendChild(this.element);
this.setText("I am a new handler widget.");
}

HandlerWidget.prototype.onPersonListLoaded = function(e,b,widget) {
widget.setText("onPersonListLoaded event received");
}

// Wire up buttons to click events
YAHOO.util.Event.addListener("b", 'click', function(e) {
PersonListLoadedEvent.fire();
});

YAHOO.util.Event.addListener("b2", 'click', function(e) {
new HandlerWidget();
});

new HandlerWidget();
})();
</script>

</body>
</html>
Show details Hide details

Change log

r5 by alxsti3 on Jul 15, 2009   Diff
Added YUI version
Go to: 
Project members, sign in to write a code review

Older revisions

r4 by alxsti3 on Jul 15, 2009   Diff
Added YUI version
All revisions of this file

File info

Size: 1710 bytes, 64 lines
Hosted by Google Code