1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
5 <title>Rico 3.0 - Events</title>
7 <script src="LoadRicoClient.js" type="text/javascript"></script>
8 <link href="../demo.css" type="text/css" rel="stylesheet" />
10 <script type='text/javascript'>
11 Rico.TestClass=function(name,msg) {
12 this.initialize(name,msg);
15 Rico.TestClass.prototype = {
16 initialize: function(name,msg) {
18 this.addBtn=document.getElementById('add'+name);
19 this.remBtn=document.getElementById('rem'+name);
20 this.tstBtn=document.getElementById('tst'+name);
21 Rico.eventBind(this.addBtn, 'click', Rico.eventHandle(this,'addClick'));
22 Rico.eventBind(this.remBtn, 'click', Rico.eventHandle(this,'remClick'));
23 this.tstHandle=Rico.eventHandle(this,'tstClick');
24 this.isAttached=false;
26 addClick: function(e) {
27 if (this.isAttached) {
28 alert('already attached!');
30 Rico.eventBind(this.tstBtn, 'click', this.tstHandle);
34 remClick: function(e) {
35 if (this.isAttached) {
36 Rico.eventUnbind(this.tstBtn, 'click', this.tstHandle);
37 this.isAttached=false;
39 alert('not attached!');
42 tstClick: function(e) {
43 var elem=Rico.eventElement(e);
44 var loc=Rico.eventClient(e);
45 alert(this.msg+'\nElement '+elem.id+' clicked at '+loc.x+','+loc.y);
49 Rico.onLoad(function() {
50 var a=new Rico.TestClass('A','i am A king');
51 var b=new Rico.TestClass('B','i am the queen B');
59 <div id='explanation'>
61 <script type='text/javascript'>
62 document.write(Rico.Lib+' '+Rico.LibVersion);
66 <p>In this example, the "Add" button adds an event to the "Test" button.
67 Conversely, the "Remove" button removes that event from the "Test" button.
72 <button id='addA'>Add event to A</button>
73 <button id='remA'>Remove event from A</button>
74 <button id='tstA'>Test A</button>
78 <button id='addB'>Add event to B</button>
79 <button id='remB'>Remove event from B</button>
80 <button id='tstB'>Test B</button>