4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js">Ext.require('Ext.util.DelayedTask', function() {
20 Ext.util.Event = Ext.extend(Object, (function() {
21 function createBuffered(handler, listener, o, scope) {
22 listener.task = new Ext.util.DelayedTask();
24 listener.task.delay(o.buffer, handler, scope, Ext.Array.toArray(arguments));
28 function createDelayed(handler, listener, o, scope) {
30 var task = new Ext.util.DelayedTask();
31 if (!listener.tasks) {
34 listener.tasks.push(task);
35 task.delay(o.delay || 10, handler, scope, Ext.Array.toArray(arguments));
39 function createSingle(handler, listener, o, scope) {
41 listener.ev.removeListener(listener.fn, scope);
42 return handler.apply(scope, arguments);
49 constructor: function(observable, name) {
51 this.observable = observable;
55 addListener: function(fn, scope, options) {
58 scope = scope || me.observable;
63 sourceClass: Ext.getClassName(this.observable),
64 sourceMethod: "addListener",
65 msg: "The specified callback function is undefined"
70 if (!me.isListening(fn, scope)) {
71 listener = me.createListener(fn, scope, options);
73 // if we are currently firing this event, don't disturb the listener loop
74 me.listeners = me.listeners.slice(0);
76 me.listeners.push(listener);
80 createListener: function(fn, scope, o) {
82 scope = scope || this.observable;
92 // The order is important. The 'single' wrapper must be wrapped by the 'buffer' and 'delayed' wrapper
93 // because the event removal that the single listener does destroys the listener's DelayedTask(s)
95 handler = createSingle(handler, listener, o, scope);
98 handler = createDelayed(handler, listener, o, scope);
101 handler = createBuffered(handler, listener, o, scope);
104 listener.fireFn = handler;
108 findListener: function(fn, scope) {
109 var listeners = this.listeners,
110 i = listeners.length,
115 listener = listeners[i];
118 if (listener.fn == fn && (s == scope || s == this.observable)) {
127 isListening: function(fn, scope) {
128 return this.findListener(fn, scope) !== -1;
131 removeListener: function(fn, scope) {
136 index = me.findListener(fn, scope);
138 listener = me.listeners[index];
141 me.listeners = me.listeners.slice(0);
144 // cancel and remove a buffered handler that hasn't fired yet
146 listener.task.cancel();
147 delete listener.task;
150 // cancel and remove all delayed handlers that haven't fired yet
151 k = listener.tasks && listener.tasks.length;
154 listener.tasks[k].cancel();
156 delete listener.tasks;
159 // remove this listener from the listeners array
160 me.listeners.splice(index, 1);
167 // Iterate to stop any buffered/delayed events
168 clearListeners: function() {
169 var listeners = this.listeners,
170 i = listeners.length;
173 this.removeListener(listeners[i].fn, listeners[i].scope);
179 listeners = me.listeners,
180 count = listeners.length,
187 for (i = 0; i < count; i++) {
188 listener = listeners[i];
189 args = arguments.length ? Array.prototype.slice.call(arguments, 0) : [];
191 args.push(listener.o);
193 if (listener && listener.fireFn.apply(listener.scope || me.observable, args) === false) {
194 return (me.firing = false);