source: cows/branches/cows-vis/cows/pylons/project_templates/cows_server/+package+/public/js/yui/api/event-custom.js.html @ 5259

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/branches/cows-vis/cows/pylons/project_templates/cows_server/+package+/public/js/yui/api/event-custom.js.html@5259
Revision 5259, 87.1 KB checked in by domlowe, 11 years ago (diff)

adding yui javascript

Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2<html>
3<head>
4        <title>API: event   event-custom.js  (YUI Library)</title>
5        <link rel="stylesheet" type="text/css" href="assets/api.css">
6    <script type="text/javascript" src="assets/api-js"></script>
7    <script type="text/javascript" src="assets/ac-js"></script>
8</head>
9
10<body id="yahoo-com">
11
12<div id="doc3" class="yui-t2">
13
14        <div id="hd">
15        <a href="http://developer.yahoo.com/yui/"><h1>Yahoo! UI Library</h1></a>
16        <h3>event&nbsp; <span class="subtitle">3.0.0pr1</span></h3>
17        <p>
18        <a href="./index.html">Yahoo! UI Library</a> 
19            &gt; <a href="./module_event.html">event</a>
20               
21                 &gt; event-custom.js (source view)
22            </p>
23
24
25        </div>
26
27        <div id="bd">
28                <div id="yui-main">
29                        <div class="yui-b">
30            <form name="yui-classopts-form">
31    <span id="classopts"><input type="checkbox" name="showprivate" id="showprivate" /> <label for="showprivate">Show Private</label></span>
32    <span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> <label for="showprotected">Show Protected</label></span>
33    <span id="classopts"><input type="checkbox" name="showdeprecated" id="showdeprecated" /> <label for="showdeprecated">Show Deprecated</label></span>
34            </form>
35
36                    <div id="srcout">
37                        <style>
38                            #doc3 #classopts { display:none; }
39                        </style>
40<div class="highlight" ><pre><span class="c">/*</span>
41<span class="c"> * YUI Custom Events</span>
42<span class="c"> * @submodule event-custom</span>
43<span class="c"> * @module event</span>
44<span class="c"> */</span>
45<span class="nx">YUI</span><span class="o">.</span><span class="nx">add</span><span class="o">(</span><span class="s2">&quot;event-custom&quot;</span><span class="o">,</span> <span class="k">function</span><span class="o">(</span><span class="nx">Y</span><span class="o">)</span> <span class="o">{</span>
46
47    <span class="k">var</span> <span class="nx">onsubscribeType</span> <span class="o">=</span> <span class="s2">&quot;_event:onsub&quot;</span><span class="o">,</span>
48
49        <span class="nx">AFTER</span> <span class="o">=</span> <span class="s1">&#39;after&#39;</span><span class="o">,</span> 
50
51        <span class="nx">CONFIGS</span> <span class="o">=</span> <span class="o">[</span>
52
53            <span class="s1">&#39;broadcast&#39;</span><span class="o">,</span>
54
55            <span class="s1">&#39;bubbles&#39;</span><span class="o">,</span>
56
57            <span class="s1">&#39;context&#39;</span><span class="o">,</span>
58
59            <span class="s1">&#39;configured&#39;</span><span class="o">,</span>
60
61            <span class="s1">&#39;currentTarget&#39;</span><span class="o">,</span>
62
63            <span class="s1">&#39;defaultFn&#39;</span><span class="o">,</span>
64
65            <span class="s1">&#39;details&#39;</span><span class="o">,</span>
66
67            <span class="s1">&#39;emitFacade&#39;</span><span class="o">,</span>
68
69            <span class="s1">&#39;fireOnce&#39;</span><span class="o">,</span>
70
71            <span class="s1">&#39;host&#39;</span><span class="o">,</span>
72
73            <span class="s1">&#39;preventable&#39;</span><span class="o">,</span>
74
75            <span class="s1">&#39;preventedFn&#39;</span><span class="o">,</span>
76
77            <span class="s1">&#39;queuable&#39;</span><span class="o">,</span>
78
79            <span class="s1">&#39;silent&#39;</span><span class="o">,</span>
80
81            <span class="s1">&#39;stoppedFn&#39;</span><span class="o">,</span>
82
83            <span class="s1">&#39;target&#39;</span><span class="o">,</span>
84
85            <span class="s1">&#39;type&#39;</span>
86
87        <span class="o">];</span>
88
89    <span class="c">/**</span>
90<span class="c">     * Return value from all subscribe operations</span>
91<span class="c">     * @class Event.Handle</span>
92<span class="c">     * @constructor</span>
93<span class="c">     * @param evt {Event.Custom} the custom event</span>
94<span class="c">     * @param sub {Event.Subscriber} the subscriber</span>
95<span class="c">     */</span>
96    <span class="nx">Y</span><span class="o">.</span><span class="nx">EventHandle</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">evt</span><span class="o">,</span> <span class="nx">sub</span><span class="o">)</span> <span class="o">{</span>
97
98        <span class="c">/**</span>
99<span class="c">         * The custom event</span>
100<span class="c">         * @type Event.Custom</span>
101<span class="c">         */</span>
102        <span class="k">this</span><span class="o">.</span><span class="nx">evt</span> <span class="o">=</span> <span class="nx">evt</span><span class="o">;</span>
103
104        <span class="c">/**</span>
105<span class="c">         * The subscriber object</span>
106<span class="c">         * @type Event.Subscriber</span>
107<span class="c">         */</span>
108        <span class="k">this</span><span class="o">.</span><span class="nx">sub</span> <span class="o">=</span> <span class="nx">sub</span><span class="o">;</span>
109    <span class="o">};</span>
110
111    <span class="nx">Y</span><span class="o">.</span><span class="nx">EventHandle</span><span class="o">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="o">{</span>
112        <span class="c">/**</span>
113<span class="c">         * Detaches this subscriber</span>
114<span class="c">         * @method detach</span>
115<span class="c">         */</span>
116        <span class="nx">detach</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
117            <span class="k">this</span><span class="o">.</span><span class="nx">evt</span><span class="o">.</span><span class="nx">_delete</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">sub</span><span class="o">);</span>
118        <span class="o">}</span>
119    <span class="o">};</span>
120
121    <span class="c">/**</span>
122<span class="c">     * The Event.Custom class lets you define events for your application</span>
123<span class="c">     * that can be subscribed to by one or more independent component.</span>
124<span class="c">     *</span>
125<span class="c">     * @param {String}  type The type of event, which is passed to the callback</span>
126<span class="c">     *                  when the event fires</span>
127<span class="c">     * @param {Object}  context The context the event will fire from.  &quot;this&quot; will</span>
128<span class="c">     *                  refer to this object in the callback.  Default value: </span>
129<span class="c">     *                  the window object.  The listener can override this.</span>
130<span class="c">     * @param {boolean} silent pass true to prevent the event from writing to</span>
131<span class="c">     *                  the debug system</span>
132<span class="c">     * @class Event.Custom</span>
133<span class="c">     * @constructor</span>
134<span class="c">     */</span>
135    <span class="nx">Y</span><span class="o">.</span><span class="nx">CustomEvent</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">type</span><span class="o">,</span> <span class="nx">o</span><span class="o">)</span> <span class="o">{</span>
136
137        <span class="c">// if (arguments.length &gt; 2) {</span>
138<span class="c">// this.log(&#39;CustomEvent context and silent are now in the config&#39;, &#39;warn&#39;, &#39;Event&#39;);</span>
139<span class="c"></span>        <span class="c">// }</span>
140<span class="c"></span>
141        <span class="nx">o</span> <span class="o">=</span> <span class="nx">o</span> <span class="o">||</span> <span class="o">{};</span>
142
143        <span class="k">this</span><span class="o">.</span><span class="nx">id</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">stamp</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
144
145        <span class="c">/**</span>
146<span class="c">         * The type of event, returned to subscribers when the event fires</span>
147<span class="c">         * @property type</span>
148<span class="c">         * @type string</span>
149<span class="c">         */</span>
150        <span class="k">this</span><span class="o">.</span><span class="nx">type</span> <span class="o">=</span> <span class="nx">type</span><span class="o">;</span>
151
152        <span class="c">/**</span>
153<span class="c">         * The context the the event will fire from by default.  Defaults to the YUI</span>
154<span class="c">         * instance.</span>
155<span class="c">         * @property context</span>
156<span class="c">         * @type object</span>
157<span class="c">         */</span>
158        <span class="k">this</span><span class="o">.</span><span class="nx">context</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">;</span>
159
160        <span class="k">this</span><span class="o">.</span><span class="nx">logSystem</span> <span class="o">=</span> <span class="o">(</span><span class="nx">type</span> <span class="o">==</span> <span class="s2">&quot;yui:log&quot;</span><span class="o">);</span>
161
162        <span class="c">/**</span>
163<span class="c">         * If 0, this event does not broadcast.  If 1, the YUI instance is notified</span>
164<span class="c">         * every time this event fires.  If 2, the YUI instance and the YUI global</span>
165<span class="c">         * (if event is enabled on the global) are notified every time this event</span>
166<span class="c">         * fires.</span>
167<span class="c">         * @property broadcast</span>
168<span class="c">         * @type int</span>
169<span class="c">         */</span>
170        <span class="k">this</span><span class="o">.</span><span class="nx">broadcast</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
171
172        <span class="c">/**</span>
173<span class="c">         * By default all custom events are logged in the debug build, set silent</span>
174<span class="c">         * to true to disable debug outpu for this event.</span>
175<span class="c">         * @property silent</span>
176<span class="c">         * @type boolean</span>
177<span class="c">         */</span>
178        <span class="k">this</span><span class="o">.</span><span class="nx">silent</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">logSystem</span><span class="o">;</span>
179
180        <span class="c">// this.queuable = !(this.logSystem);</span>
181<span class="c"></span>        <span class="k">this</span><span class="o">.</span><span class="nx">queuable</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>
182
183        <span class="c">/**</span>
184<span class="c">         * The subscribers to this event</span>
185<span class="c">         * @property subscribers</span>
186<span class="c">         * @type Event.Subscriber{}</span>
187<span class="c">         */</span>
188        <span class="k">this</span><span class="o">.</span><span class="nx">subscribers</span> <span class="o">=</span> <span class="o">{};</span>
189
190        <span class="c">/*</span>
191<span class="c">         * The publisher has configured this event</span>
192<span class="c">         * @property configured</span>
193<span class="c">         * @type boolean</span>
194<span class="c">         * @default true</span>
195<span class="c">         */</span>
196        <span class="c">// this.configured = true;</span>
197<span class="c"></span>
198        <span class="c">/**</span>
199<span class="c">         * &#39;After&#39; subscribers</span>
200<span class="c">         * @property afters</span>
201<span class="c">         * @type Event.Subscriber{}</span>
202<span class="c">         */</span>
203        <span class="k">this</span><span class="o">.</span><span class="nx">afters</span> <span class="o">=</span> <span class="o">{};</span>
204
205        <span class="c">/**</span>
206<span class="c">         * This event has fired if true</span>
207<span class="c">         *</span>
208<span class="c">         * @property fired</span>
209<span class="c">         * @type boolean</span>
210<span class="c">         * @default false;</span>
211<span class="c">         */</span>
212        <span class="k">this</span><span class="o">.</span><span class="nx">fired</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>
213
214        <span class="c">/**</span>
215<span class="c">         * This event should only fire one time if true, and if</span>
216<span class="c">         * it has fired, any new subscribers should be notified</span>
217<span class="c">         * immediately.</span>
218<span class="c">         *</span>
219<span class="c">         * @property fireOnce</span>
220<span class="c">         * @type boolean</span>
221<span class="c">         * @default false;</span>
222<span class="c">         */</span>
223        <span class="k">this</span><span class="o">.</span><span class="nx">fireOnce</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>
224
225        <span class="c">/**</span>
226<span class="c">         * Flag for stopPropagation that is modified during fire()</span>
227<span class="c">         * 1 means to stop propagation to bubble targets.  2 means</span>
228<span class="c">         * to also stop additional subscribers on this target.</span>
229<span class="c">         * @property stopped</span>
230<span class="c">         * @type int</span>
231<span class="c">         */</span>
232        <span class="k">this</span><span class="o">.</span><span class="nx">stopped</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
233
234        <span class="c">/**</span>
235<span class="c">         * Flag for preventDefault that is modified during fire().</span>
236<span class="c">         * if it is not 0, the default behavior for this event</span>
237<span class="c">         * @property prevented</span>
238<span class="c">         * @type int</span>
239<span class="c">         */</span>
240        <span class="k">this</span><span class="o">.</span><span class="nx">prevented</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
241
242        <span class="c">/**</span>
243<span class="c">         * Specifies the host for this custom event.  This is used</span>
244<span class="c">         * to enable event bubbling</span>
245<span class="c">         * @property host</span>
246<span class="c">         * @type Event.Target</span>
247<span class="c">         */</span>
248        <span class="k">this</span><span class="o">.</span><span class="nx">host</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
249
250        <span class="c">/**</span>
251<span class="c">         * The default function to execute after event listeners</span>
252<span class="c">         * have fire, but only if the default action was not</span>
253<span class="c">         * prevented.</span>
254<span class="c">         * @property defaultFn</span>
255<span class="c">         * @type Function</span>
256<span class="c">         */</span>
257        <span class="k">this</span><span class="o">.</span><span class="nx">defaultFn</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
258
259        <span class="c">/**</span>
260<span class="c">         * The function to execute if a subscriber calls</span>
261<span class="c">         * stopPropagation or stopImmediatePropagation</span>
262<span class="c">         * @property stoppedFn</span>
263<span class="c">         * @type Function</span>
264<span class="c">         */</span>
265        <span class="k">this</span><span class="o">.</span><span class="nx">stoppedFn</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
266
267        <span class="c">/**</span>
268<span class="c">         * The function to execute if a subscriber calls</span>
269<span class="c">         * preventDefault</span>
270<span class="c">         * @property preventedFn</span>
271<span class="c">         * @type Function</span>
272<span class="c">         */</span>
273        <span class="k">this</span><span class="o">.</span><span class="nx">preventedFn</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
274
275        <span class="c">/**</span>
276<span class="c">         * Specifies whether or not this event&#39;s default function</span>
277<span class="c">         * can be cancelled by a subscriber by executing preventDefault() </span>
278<span class="c">         * on the event facade </span>
279<span class="c">         * @property preventable </span>
280<span class="c">         * @type boolean </span>
281<span class="c">         * @default true</span>
282<span class="c">         */</span>
283        <span class="k">this</span><span class="o">.</span><span class="nx">preventable</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
284
285        <span class="c">/**</span>
286<span class="c">         * Specifies whether or not a subscriber can stop the event propagation</span>
287<span class="c">         * via stopPropagation(), stopImmediatePropagation(), or halt()</span>
288<span class="c">         * @property bubbles</span>
289<span class="c">         * @type boolean</span>
290<span class="c">         * @default true</span>
291<span class="c">         */</span>
292        <span class="k">this</span><span class="o">.</span><span class="nx">bubbles</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
293
294        <span class="k">this</span><span class="o">.</span><span class="nx">emitFacade</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>
295
296        <span class="k">this</span><span class="o">.</span><span class="nx">applyConfig</span><span class="o">(</span><span class="nx">o</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>
297
298        <span class="k">this</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;Creating &quot;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">type</span><span class="o">);</span>
299
300        <span class="c">// Only add subscribe events for events that are not generated by </span>
301<span class="c"></span>        <span class="c">// Event.Custom</span>
302<span class="c"></span>        <span class="k">if</span> <span class="o">(</span><span class="nx">type</span> <span class="o">!==</span> <span class="nx">onsubscribeType</span><span class="o">)</span> <span class="o">{</span>
303
304            <span class="c">/**</span>
305<span class="c">             * Custom events provide a custom event that fires whenever there is</span>
306<span class="c">             * a new subscriber to the event.  This provides an opportunity to</span>
307<span class="c">             * handle the case where there is a non-repeating event that has</span>
308<span class="c">             * already fired has a new subscriber.  </span>
309<span class="c">             *</span>
310<span class="c">             * @event subscribeEvent</span>
311<span class="c">             * @type Y.Event.Custom</span>
312<span class="c">             * @param {Function} fn The function to execute</span>
313<span class="c">             * @param {Object}   obj An object to be passed along when the event </span>
314<span class="c">             *                       fires</span>
315<span class="c">             * @param {boolean|Object}  override If true, the obj passed in becomes </span>
316<span class="c">             *                                   the execution context of the listener.</span>
317<span class="c">             *                                   if an object, that object becomes the</span>
318<span class="c">             *                                   the execution context.</span>
319<span class="c">             */</span>
320            <span class="k">this</span><span class="o">.</span><span class="nx">subscribeEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="nx">onsubscribeType</span><span class="o">,</span> <span class="o">{</span>
321                    <span class="nx">context</span><span class="o">:</span> <span class="k">this</span><span class="o">,</span>
322                    <span class="nx">silent</span><span class="o">:</span> <span class="kc">true</span>
323                <span class="o">});</span>
324        <span class="o">}</span> 
325
326    <span class="o">};</span>
327
328    <span class="nx">Y</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="o">{</span>
329
330        <span class="nx">_YUI_EVENT</span><span class="o">:</span> <span class="kc">true</span><span class="o">,</span>
331
332        <span class="c">/**</span>
333<span class="c">         * Apply configuration properties.  Only applies the CONFIG whitelist</span>
334<span class="c">         * @method applyConfig</span>
335<span class="c">         * @param o hash of properties to apply</span>
336<span class="c">         * @param force {boolean} if true, properties that exist on the event </span>
337<span class="c">         * will be overwritten.</span>
338<span class="c">         */</span>
339        <span class="nx">applyConfig</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">o</span><span class="o">,</span> <span class="nx">force</span><span class="o">)</span> <span class="o">{</span>
340            <span class="k">if</span> <span class="o">(</span><span class="nx">o</span><span class="o">)</span> <span class="o">{</span>
341                <span class="nx">Y</span><span class="o">.</span><span class="nx">mix</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">o</span><span class="o">,</span> <span class="nx">force</span><span class="o">,</span> <span class="nx">CONFIGS</span><span class="o">);</span>
342            <span class="o">}</span>
343        <span class="o">},</span>
344
345        <span class="nx">_subscribe</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">obj</span><span class="o">,</span> <span class="nx">args</span><span class="o">,</span> <span class="nx">when</span><span class="o">)</span> <span class="o">{</span>
346
347            <span class="k">if</span> <span class="o">(!</span><span class="nx">fn</span><span class="o">)</span> <span class="o">{</span>
348                <span class="nx">Y</span><span class="o">.</span><span class="nx">fail</span><span class="o">(</span><span class="s2">&quot;Invalid callback for CE: &quot;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">type</span><span class="o">);</span>
349            <span class="o">}</span>
350
351            <span class="k">var</span> <span class="nx">se</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">subscribeEvent</span><span class="o">;</span>
352            <span class="k">if</span> <span class="o">(</span><span class="nx">se</span><span class="o">)</span> <span class="o">{</span>
353                <span class="nx">se</span><span class="o">.</span><span class="nx">fire</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="nx">se</span><span class="o">,</span> <span class="nx">args</span><span class="o">);</span>
354            <span class="o">}</span>
355
356            <span class="k">var</span> <span class="nx">s</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Subscriber</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">obj</span><span class="o">,</span> <span class="nx">args</span><span class="o">,</span> <span class="nx">when</span><span class="o">);</span>
357
358
359            <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">fireOnce</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="o">.</span><span class="nx">fired</span><span class="o">)</span> <span class="o">{</span>
360
361                <span class="c">// this._notify(s);</span>
362<span class="c"></span>                <span class="c">// setTimeout(Y.bind(this._notify, this, s), 0);</span>
363<span class="c"></span>                <span class="nx">Y</span><span class="o">.</span><span class="nx">later</span><span class="o">(</span><span class="m">0</span><span class="o">,</span> <span class="k">this</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="nx">_notify</span><span class="o">,</span> <span class="nx">s</span><span class="o">);</span>
364            <span class="o">}</span>
365
366            <span class="k">if</span> <span class="o">(</span><span class="nx">when</span> <span class="o">==</span> <span class="nx">AFTER</span><span class="o">)</span> <span class="o">{</span>
367                <span class="k">this</span><span class="o">.</span><span class="nx">afters</span><span class="o">[</span><span class="nx">s</span><span class="o">.</span><span class="nx">id</span><span class="o">]</span> <span class="o">=</span> <span class="nx">s</span><span class="o">;</span>
368            <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
369                <span class="k">this</span><span class="o">.</span><span class="nx">subscribers</span><span class="o">[</span><span class="nx">s</span><span class="o">.</span><span class="nx">id</span><span class="o">]</span> <span class="o">=</span> <span class="nx">s</span><span class="o">;</span>
370            <span class="o">}</span>
371
372            <span class="k">return</span> <span class="k">new</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">EventHandle</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">s</span><span class="o">);</span>
373
374        <span class="o">},</span>
375
376        <span class="c">/**</span>
377<span class="c">         * Listen for this event</span>
378<span class="c">         * @method subscribe</span>
379<span class="c">         * @param {Function} fn        The function to execute</span>
380<span class="c">         * @param {Object}   obj       An object to be passed along when the event fires</span>
381<span class="c">         * @param args* 1..n params to provide to the listener</span>
382<span class="c">         * @return {Event.Handle} unsubscribe handle</span>
383<span class="c">         */</span>
384        <span class="nx">subscribe</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">obj</span><span class="o">)</span> <span class="o">{</span>
385            <span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="nx">_subscribe</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">obj</span><span class="o">,</span> <span class="nx">Y</span><span class="o">.</span><span class="nb">Array</span><span class="o">(</span><span class="nx">arguments</span><span class="o">,</span> <span class="m">2</span><span class="o">,</span> <span class="kc">true</span><span class="o">));</span>
386        <span class="o">},</span>
387
388        <span class="c">/**</span>
389<span class="c">         * Listen for this event after the normal subscribers have been notified and</span>
390<span class="c">         * the default behavior has been applied.  If a normal subscriber prevents the </span>
391<span class="c">         * default behavior, it also prevents after listeners from firing.</span>
392<span class="c">         * @method after</span>
393<span class="c">         * @param {Function} fn        The function to execute</span>
394<span class="c">         * @param {Object}   obj       An object to be passed along when the event fires</span>
395<span class="c">         * @param args* 1..n params to provide to the listener</span>
396<span class="c">         * @return {Event.Handle} unsubscribe handle</span>
397<span class="c">         */</span>
398        <span class="nx">after</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">obj</span><span class="o">)</span> <span class="o">{</span>
399            <span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="nx">_subscribe</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">obj</span><span class="o">,</span> <span class="nx">Y</span><span class="o">.</span><span class="nb">Array</span><span class="o">(</span><span class="nx">arguments</span><span class="o">,</span> <span class="m">2</span><span class="o">,</span> <span class="kc">true</span><span class="o">),</span> <span class="nx">AFTER</span><span class="o">);</span>
400        <span class="o">},</span>
401
402        <span class="c">/**</span>
403<span class="c">         * Unsubscribes subscribers.</span>
404<span class="c">         * @method unsubscribe</span>
405<span class="c">         * @param {Function} fn  The subscribed function to remove, if not supplied</span>
406<span class="c">         *                       all will be removed</span>
407<span class="c">         * @param {Object}   obj  The custom object passed to subscribe.  This is</span>
408<span class="c">         *                        optional, but if supplied will be used to</span>
409<span class="c">         *                        disambiguate multiple listeners that are the same</span>
410<span class="c">         *                        (e.g., you subscribe many object using a function</span>
411<span class="c">         *                        that lives on the prototype)</span>
412<span class="c">         * @return {boolean} True if the subscriber was found and detached.</span>
413<span class="c">         */</span>
414        <span class="nx">unsubscribe</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">obj</span><span class="o">)</span> <span class="o">{</span>
415
416            <span class="c">// if arg[0] typeof unsubscribe handle</span>
417<span class="c"></span>            <span class="k">if</span> <span class="o">(</span><span class="nx">fn</span> <span class="o">&amp;&amp;</span> <span class="nx">fn</span><span class="o">.</span><span class="nx">detach</span><span class="o">)</span> <span class="o">{</span>
418                <span class="k">return</span> <span class="nx">fn</span><span class="o">.</span><span class="nx">detach</span><span class="o">();</span>
419            <span class="o">}</span>
420
421            <span class="k">if</span> <span class="o">(!</span><span class="nx">fn</span><span class="o">)</span> <span class="o">{</span>
422                <span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="nx">unsubscribeAll</span><span class="o">();</span>
423            <span class="o">}</span>
424
425            <span class="k">var</span> <span class="nx">found</span> <span class="o">=</span> <span class="kc">false</span><span class="o">,</span> <span class="nx">subs</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">subscribers</span><span class="o">;</span>
426            <span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">subs</span><span class="o">)</span> <span class="o">{</span>
427                <span class="k">if</span> <span class="o">(</span><span class="nx">subs</span><span class="o">.</span><span class="nx">hasOwnProperty</span><span class="o">(</span><span class="nx">i</span><span class="o">))</span> <span class="o">{</span>
428                    <span class="k">var</span> <span class="nx">s</span> <span class="o">=</span> <span class="nx">subs</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
429                    <span class="k">if</span> <span class="o">(</span><span class="nx">s</span> <span class="o">&amp;&amp;</span> <span class="nx">s</span><span class="o">.</span><span class="nx">contains</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">obj</span><span class="o">))</span> <span class="o">{</span>
430                        <span class="k">this</span><span class="o">.</span><span class="nx">_delete</span><span class="o">(</span><span class="nx">s</span><span class="o">);</span>
431                        <span class="nx">found</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
432                    <span class="o">}</span>
433                <span class="o">}</span>
434            <span class="o">}</span>
435
436            <span class="k">return</span> <span class="nx">found</span><span class="o">;</span>
437        <span class="o">},</span>
438
439        <span class="nx">_getFacade</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">args</span><span class="o">)</span> <span class="o">{</span>
440
441            <span class="k">var</span> <span class="nx">ef</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_facade</span><span class="o">;</span>
442
443            <span class="k">if</span> <span class="o">(!</span><span class="nx">ef</span><span class="o">)</span> <span class="o">{</span>
444                <span class="nx">ef</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">Facade</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="nx">currentTarget</span><span class="o">);</span>
445            <span class="o">}</span>
446
447            <span class="c">// if the first argument is an object literal, apply the</span>
448<span class="c"></span>            <span class="c">// properties to the event facade</span>
449<span class="c"></span>            <span class="k">var</span> <span class="nx">o</span> <span class="o">=</span> <span class="nx">args</span> <span class="o">&amp;&amp;</span> <span class="nx">args</span><span class="o">[</span><span class="m">0</span><span class="o">];</span>
450            <span class="k">if</span> <span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">Lang</span><span class="o">.</span><span class="nx">isObject</span><span class="o">(</span><span class="nx">o</span><span class="o">,</span> <span class="kc">true</span><span class="o">)</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">o</span><span class="o">.</span><span class="nx">_yuifacade</span><span class="o">)</span> <span class="o">{</span>
451                <span class="nx">Y</span><span class="o">.</span><span class="nx">mix</span><span class="o">(</span><span class="nx">ef</span><span class="o">,</span> <span class="nx">o</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>
452            <span class="o">}</span>
453
454            <span class="c">// update the details field with the arguments</span>
455<span class="c"></span>            <span class="nx">ef</span><span class="o">.</span><span class="nx">details</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">details</span><span class="o">;</span>
456            <span class="nx">ef</span><span class="o">.</span><span class="nx">target</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">target</span><span class="o">;</span>
457            <span class="nx">ef</span><span class="o">.</span><span class="nx">currentTarget</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">currentTarget</span><span class="o">;</span>
458            <span class="nx">ef</span><span class="o">.</span><span class="nx">stopped</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
459            <span class="nx">ef</span><span class="o">.</span><span class="nx">prevented</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
460
461            <span class="k">this</span><span class="o">.</span><span class="nx">_facade</span> <span class="o">=</span> <span class="nx">ef</span><span class="o">;</span>
462
463            <span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="nx">_facade</span><span class="o">;</span>
464        <span class="o">},</span>
465
466        <span class="c">/**</span>
467<span class="c">         * Notify a single subscriber</span>
468<span class="c">         * @method _notify</span>
469<span class="c">         * @param s {Event.Subscriber} the subscriber</span>
470<span class="c">         * @param args {Array} the arguments array to apply to the listener</span>
471<span class="c">         * @private</span>
472<span class="c">         */</span>
473        <span class="nx">_notify</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">s</span><span class="o">,</span> <span class="nx">args</span><span class="o">,</span> <span class="nx">ef</span><span class="o">)</span> <span class="o">{</span>
474
475            <span class="k">this</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">type</span> <span class="o">+</span> <span class="s2">&quot;-&gt;&quot;</span> <span class="o">+</span> <span class="s2">&quot;: &quot;</span> <span class="o">+</span>  <span class="nx">s</span><span class="o">);</span>
476
477            <span class="k">var</span> <span class="nx">ret</span><span class="o">;</span>
478
479            <span class="c">// emit an Event.Facade if this is that sort of event</span>
480<span class="c"></span>            <span class="c">// if (this.emitFacade &amp;&amp; (!args[0] || !args[0]._yuifacade)) {</span>
481<span class="c"></span>            <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">emitFacade</span><span class="o">)</span> <span class="o">{</span>
482
483                <span class="c">// @TODO object literal support to fire makes it possible for</span>
484<span class="c"></span>                <span class="c">// config info to be passed if we wish.</span>
485<span class="c"></span>               
486                <span class="k">if</span> <span class="o">(!</span><span class="nx">ef</span><span class="o">)</span> <span class="o">{</span>
487                    <span class="nx">ef</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_getFacade</span><span class="o">(</span><span class="nx">args</span><span class="o">);</span>
488                    <span class="nx">args</span><span class="o">[</span><span class="m">0</span><span class="o">]</span> <span class="o">=</span> <span class="nx">ef</span><span class="o">;</span>
489                <span class="o">}</span>
490
491            <span class="o">}</span>
492             
493            <span class="nx">ret</span> <span class="o">=</span> <span class="nx">s</span><span class="o">.</span><span class="nx">notify</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">context</span><span class="o">,</span> <span class="nx">args</span><span class="o">);</span>
494
495            <span class="k">if</span> <span class="o">(</span><span class="kc">false</span> <span class="o">===</span> <span class="nx">ret</span> <span class="o">||</span> <span class="k">this</span><span class="o">.</span><span class="nx">stopped</span> <span class="o">&gt;</span> <span class="m">1</span><span class="o">)</span> <span class="o">{</span>
496                <span class="k">this</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">type</span> <span class="o">+</span> <span class="s2">&quot; cancelled by subscriber&quot;</span><span class="o">);</span>
497                <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
498            <span class="o">}</span>
499
500            <span class="k">return</span> <span class="kc">true</span><span class="o">;</span>
501        <span class="o">},</span>
502
503        <span class="c">/**</span>
504<span class="c">         * Logger abstraction to centralize the application of the silent flag</span>
505<span class="c">         * @method log</span>
506<span class="c">         * @param msg {string} message to log</span>
507<span class="c">         * @param cat {string} log category</span>
508<span class="c">         */</span>
509        <span class="nx">log</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">msg</span><span class="o">,</span> <span class="nx">cat</span><span class="o">)</span> <span class="o">{</span>
510            <span class="k">var</span> <span class="nx">es</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_eventstack</span><span class="o">,</span> <span class="nx">s</span> <span class="o">=</span>  <span class="nx">es</span> <span class="o">&amp;&amp;</span> <span class="nx">es</span><span class="o">.</span><span class="nx">silent</span><span class="o">;</span>
511            <span class="c">// if (!s &amp;&amp; !this.silent) {</span>
512<span class="c"></span>            <span class="k">if</span> <span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">silent</span><span class="o">)</span> <span class="o">{</span>
513                <span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="nx">msg</span><span class="o">,</span> <span class="nx">cat</span> <span class="o">||</span> <span class="s2">&quot;info&quot;</span><span class="o">,</span> <span class="s2">&quot;event&quot;</span><span class="o">);</span>
514            <span class="o">}</span>
515        <span class="o">},</span>
516
517        <span class="c">/**</span>
518<span class="c">         * Notifies the subscribers.  The callback functions will be executed</span>
519<span class="c">         * from the context specified when the event was created, and with the </span>
520<span class="c">         * following parameters:</span>
521<span class="c">         *   &lt;ul&gt;</span>
522<span class="c">         *   &lt;li&gt;The type of event&lt;/li&gt;</span>
523<span class="c">         *   &lt;li&gt;All of the arguments fire() was executed with as an array&lt;/li&gt;</span>
524<span class="c">         *   &lt;li&gt;The custom object (if any) that was passed into the subscribe() </span>
525<span class="c">         *       method&lt;/li&gt;</span>
526<span class="c">         *   &lt;/ul&gt;</span>
527<span class="c">         * @method fire </span>
528<span class="c">         * @param {Object*} arguments an arbitrary set of parameters to pass to </span>
529<span class="c">         *                            the handler.</span>
530<span class="c">         * @return {boolean} false if one of the subscribers returned false, </span>
531<span class="c">         *                   true otherwise</span>
532<span class="c">         */</span>
533        <span class="nx">fire</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
534
535            <span class="k">var</span> <span class="nx">es</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_eventstack</span><span class="o">;</span>
536
537            <span class="k">if</span> <span class="o">(</span><span class="nx">es</span><span class="o">)</span> <span class="o">{</span>
538
539                <span class="c">// var b = this.bubbles, h = this.host;</span>
540<span class="c"></span>                <span class="c">// if (b &amp;&amp; h) {</span>
541<span class="c"></span>                <span class="c">//     b = (h._yuievt.targets.length);</span>
542<span class="c"></span>                <span class="c">// }</span>
543<span class="c"></span>
544                <span class="c">// es.silent = (es.silent || this.silent);</span>
545<span class="c"></span>
546                <span class="c">// queue this event if the current item in the queue bubbles</span>
547<span class="c"></span>                <span class="c">// if (b &amp;&amp; this.queuable &amp;&amp; this.type != es.next.type) {</span>
548<span class="c"></span>                <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">queuable</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="o">.</span><span class="nx">type</span> <span class="o">!=</span> <span class="nx">es</span><span class="o">.</span><span class="nx">next</span><span class="o">.</span><span class="nx">type</span><span class="o">)</span> <span class="o">{</span>
549
550                    <span class="k">this</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;queue &#39;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">type</span><span class="o">);</span>
551
552                    <span class="nx">es</span><span class="o">.</span><span class="nx">queue</span><span class="o">.</span><span class="nx">push</span><span class="o">([</span><span class="k">this</span><span class="o">,</span> <span class="nx">arguments</span><span class="o">]);</span>
553                    <span class="k">return</span> <span class="kc">true</span><span class="o">;</span>
554                <span class="o">}</span>
555
556            <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
557
558                <span class="nx">Y</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_eventstack</span> <span class="o">=</span> <span class="o">{</span>
559                   <span class="c">// id of the first event in the stack</span>
560<span class="c"></span>                   <span class="nx">id</span><span class="o">:</span> <span class="k">this</span><span class="o">.</span><span class="nx">id</span><span class="o">,</span>
561                   <span class="nx">next</span><span class="o">:</span> <span class="k">this</span><span class="o">,</span>
562                   <span class="nx">silent</span><span class="o">:</span> <span class="k">this</span><span class="o">.</span><span class="nx">silent</span><span class="o">,</span>
563                   <span class="nx">logging</span><span class="o">:</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s1">&#39;yui:log&#39;</span><span class="o">),</span>
564                   <span class="nx">stopped</span><span class="o">:</span> <span class="m">0</span><span class="o">,</span>
565                   <span class="nx">prevented</span><span class="o">:</span> <span class="m">0</span><span class="o">,</span>
566                   <span class="nx">queue</span><span class="o">:</span> <span class="o">[]</span>
567                <span class="o">};</span>
568
569                <span class="nx">es</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_eventstack</span><span class="o">;</span>
570            <span class="o">}</span>
571
572            <span class="k">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
573
574            <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">fireOnce</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="o">.</span><span class="nx">fired</span><span class="o">)</span> <span class="o">{</span>
575
576                <span class="k">this</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;fireOnce event: &#39;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">type</span> <span class="o">+</span> <span class="s1">&#39; already fired&#39;</span><span class="o">);</span>
577
578            <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
579
580                <span class="c">// var subs = this.subscribers.slice(), len=subs.length,</span>
581<span class="c"></span>                <span class="k">var</span> <span class="nx">subs</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">merge</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">subscribers</span><span class="o">),</span> <span class="nx">s</span><span class="o">,</span>
582                           <span class="nx">args</span><span class="o">=</span><span class="nx">Y</span><span class="o">.</span><span class="nb">Array</span><span class="o">(</span><span class="nx">arguments</span><span class="o">,</span> <span class="m">0</span><span class="o">,</span> <span class="kc">true</span><span class="o">),</span> <span class="nx">i</span><span class="o">;</span>
583
584                <span class="k">this</span><span class="o">.</span><span class="nx">stopped</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
585                <span class="k">this</span><span class="o">.</span><span class="nx">prevented</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
586                <span class="k">this</span><span class="o">.</span><span class="nx">target</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">target</span> <span class="o">||</span> <span class="k">this</span><span class="o">.</span><span class="nx">host</span><span class="o">;</span>
587
588                <span class="k">this</span><span class="o">.</span><span class="nx">currentTarget</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">host</span> <span class="o">||</span> <span class="k">this</span><span class="o">.</span><span class="nx">currentTarget</span><span class="o">;</span>
589
590                <span class="k">this</span><span class="o">.</span><span class="nx">fired</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
591                <span class="k">this</span><span class="o">.</span><span class="nx">details</span> <span class="o">=</span> <span class="nx">args</span><span class="o">.</span><span class="nx">slice</span><span class="o">();</span> <span class="c">// original arguments in the details</span>
592<span class="c"></span>
593                <span class="c">// this.log(&quot;Firing &quot; + this  + &quot;, &quot; + &quot;args: &quot; + args);</span>
594<span class="c"></span>                <span class="k">this</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;Firing &quot;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">type</span><span class="o">);</span>
595
596                <span class="k">var</span> <span class="nx">hasSub</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>
597                <span class="nx">es</span><span class="o">.</span><span class="nx">lastLogState</span> <span class="o">=</span> <span class="nx">es</span><span class="o">.</span><span class="nx">logging</span><span class="o">;</span>
598
599
600                <span class="k">var</span> <span class="nx">ef</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
601                <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">emitFacade</span><span class="o">)</span> <span class="o">{</span>
602                    <span class="nx">ef</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_getFacade</span><span class="o">(</span><span class="nx">args</span><span class="o">);</span>
603                    <span class="nx">args</span><span class="o">[</span><span class="m">0</span><span class="o">]</span> <span class="o">=</span> <span class="nx">ef</span><span class="o">;</span>
604                <span class="o">}</span>
605
606                <span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="k">in</span> <span class="nx">subs</span><span class="o">)</span> <span class="o">{</span>
607                    <span class="k">if</span> <span class="o">(</span><span class="nx">subs</span><span class="o">.</span><span class="nx">hasOwnProperty</span><span class="o">(</span><span class="nx">i</span><span class="o">))</span> <span class="o">{</span>
608
609                        <span class="k">if</span> <span class="o">(!</span><span class="nx">hasSub</span><span class="o">)</span> <span class="o">{</span>
610                            <span class="nx">es</span><span class="o">.</span><span class="nx">logging</span> <span class="o">=</span> <span class="o">(</span><span class="nx">es</span><span class="o">.</span><span class="nx">logging</span> <span class="o">||</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s1">&#39;yui:log&#39;</span><span class="o">));</span>
611                            <span class="nx">hasSub</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
612                        <span class="o">}</span>
613
614                        <span class="c">// stopImmediatePropagation</span>
615<span class="c"></span>                        <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">stopped</span> <span class="o">==</span> <span class="m">2</span><span class="o">)</span> <span class="o">{</span>
616                            <span class="k">break</span><span class="o">;</span>
617                        <span class="o">}</span>
618
619                        <span class="nx">s</span> <span class="o">=</span> <span class="nx">subs</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
620                        <span class="k">if</span> <span class="o">(</span><span class="nx">s</span> <span class="o">&amp;&amp;</span> <span class="nx">s</span><span class="o">.</span><span class="nx">fn</span><span class="o">)</span> <span class="o">{</span>
621                            <span class="nx">ret</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_notify</span><span class="o">(</span><span class="nx">s</span><span class="o">,</span> <span class="nx">args</span><span class="o">,</span> <span class="nx">ef</span><span class="o">);</span>
622                            <span class="k">if</span> <span class="o">(</span><span class="kc">false</span> <span class="o">===</span> <span class="nx">ret</span><span class="o">)</span> <span class="o">{</span>
623                                <span class="k">this</span><span class="o">.</span><span class="nx">stopped</span> <span class="o">=</span> <span class="m">2</span><span class="o">;</span>
624                            <span class="o">}</span>
625                        <span class="o">}</span>
626                    <span class="o">}</span>
627                <span class="o">}</span>
628
629                <span class="nx">es</span><span class="o">.</span><span class="nx">logging</span> <span class="o">=</span> <span class="o">(</span><span class="nx">es</span><span class="o">.</span><span class="nx">lastLogState</span><span class="o">);</span>
630
631                <span class="c">// bubble if this is hosted in an event target and propagation has not been stopped</span>
632<span class="c"></span>                <span class="c">// @TODO check if we need to worry about defaultFn order</span>
633<span class="c"></span>                <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">bubbles</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="o">.</span><span class="nx">host</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">this</span><span class="o">.</span><span class="nx">stopped</span><span class="o">)</span> <span class="o">{</span>
634                    <span class="nx">es</span><span class="o">.</span><span class="nx">stopped</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
635                    <span class="nx">es</span><span class="o">.</span><span class="nx">prevented</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
636                    <span class="nx">ret</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">host</span><span class="o">.</span><span class="nx">bubble</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
637
638                    <span class="k">this</span><span class="o">.</span><span class="nx">stopped</span> <span class="o">=</span> <span class="nb">Math</span><span class="o">.</span><span class="nx">max</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">stopped</span><span class="o">,</span> <span class="nx">es</span><span class="o">.</span><span class="nx">stopped</span><span class="o">);</span>
639                    <span class="k">this</span><span class="o">.</span><span class="nx">prevented</span> <span class="o">=</span> <span class="nb">Math</span><span class="o">.</span><span class="nx">max</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">prevented</span><span class="o">,</span> <span class="nx">es</span><span class="o">.</span><span class="nx">prevented</span><span class="o">);</span>
640                <span class="o">}</span>
641
642                <span class="c">// execute the default behavior if not prevented</span>
643<span class="c"></span>                <span class="c">// @TODO need context</span>
644<span class="c"></span>                <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">defaultFn</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">this</span><span class="o">.</span><span class="nx">prevented</span><span class="o">)</span> <span class="o">{</span>
645                    <span class="k">this</span><span class="o">.</span><span class="nx">defaultFn</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">host</span> <span class="o">||</span> <span class="k">this</span><span class="o">,</span> <span class="nx">args</span><span class="o">);</span>
646                <span class="o">}</span>
647
648                <span class="c">// process after listeners.  If the default behavior was</span>
649<span class="c"></span>                <span class="c">// prevented, the after events don&#39;t fire.</span>
650<span class="c"></span>                <span class="k">if</span> <span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">prevented</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="o">.</span><span class="nx">stopped</span> <span class="o">&lt;</span> <span class="m">2</span><span class="o">)</span> <span class="o">{</span>
651                    <span class="nx">subs</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">merge</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">afters</span><span class="o">);</span>
652                    <span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="k">in</span> <span class="nx">subs</span><span class="o">)</span> <span class="o">{</span>
653                        <span class="k">if</span> <span class="o">(</span><span class="nx">subs</span><span class="o">.</span><span class="nx">hasOwnProperty</span><span class="o">(</span><span class="nx">i</span><span class="o">))</span> <span class="o">{</span>
654
655                            <span class="k">if</span> <span class="o">(!</span><span class="nx">hasSub</span><span class="o">)</span> <span class="o">{</span>
656                                <span class="nx">es</span><span class="o">.</span><span class="nx">logging</span> <span class="o">=</span> <span class="o">(</span><span class="nx">es</span><span class="o">.</span><span class="nx">logging</span> <span class="o">||</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s1">&#39;yui:log&#39;</span><span class="o">));</span>
657                                <span class="nx">hasSub</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
658                            <span class="o">}</span>
659
660                            <span class="c">// stopImmediatePropagation</span>
661<span class="c"></span>                            <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">stopped</span> <span class="o">==</span> <span class="m">2</span><span class="o">)</span> <span class="o">{</span>
662                                <span class="k">break</span><span class="o">;</span>
663                            <span class="o">}</span>
664
665                            <span class="nx">s</span> <span class="o">=</span> <span class="nx">subs</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
666                            <span class="k">if</span> <span class="o">(</span><span class="nx">s</span> <span class="o">&amp;&amp;</span> <span class="nx">s</span><span class="o">.</span><span class="nx">fn</span><span class="o">)</span> <span class="o">{</span>
667                                <span class="nx">ret</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_notify</span><span class="o">(</span><span class="nx">s</span><span class="o">,</span> <span class="nx">args</span><span class="o">,</span> <span class="nx">ef</span><span class="o">);</span>
668                                <span class="k">if</span> <span class="o">(</span><span class="kc">false</span> <span class="o">===</span> <span class="nx">ret</span><span class="o">)</span> <span class="o">{</span>
669                                    <span class="k">this</span><span class="o">.</span><span class="nx">stopped</span> <span class="o">=</span> <span class="m">2</span><span class="o">;</span>
670                                <span class="o">}</span>
671                            <span class="o">}</span>
672                        <span class="o">}</span>
673                    <span class="o">}</span>
674                <span class="o">}</span>
675            <span class="o">}</span>
676
677            <span class="k">if</span> <span class="o">(</span><span class="nx">es</span><span class="o">.</span><span class="nx">id</span> <span class="o">===</span> <span class="k">this</span><span class="o">.</span><span class="nx">id</span><span class="o">)</span> <span class="o">{</span>
678<span class="c">// console.log(&#39;clearing stack: &#39; + es.id + &#39;, &#39; + this);</span>
679<span class="c"></span>
680<span class="c">// reset propragation properties while processing the rest of the queue</span>
681<span class="c"></span>
682<span class="c">// process queued events</span>
683<span class="c"></span>                <span class="k">var</span> <span class="nx">queue</span> <span class="o">=</span> <span class="nx">es</span><span class="o">.</span><span class="nx">queue</span><span class="o">;</span>
684
685                <span class="k">while</span> <span class="o">(</span><span class="nx">queue</span><span class="o">.</span><span class="nx">length</span><span class="o">)</span> <span class="o">{</span>
686                    <span class="c">// q[0] = the event, q[1] = arguments to fire</span>
687<span class="c"></span>                    <span class="k">var</span> <span class="nx">q</span> <span class="o">=</span> <span class="nx">queue</span><span class="o">.</span><span class="nx">pop</span><span class="o">(),</span> <span class="nx">ce</span> <span class="o">=</span> <span class="nx">q</span><span class="o">[</span><span class="m">0</span><span class="o">];</span>
688
689<span class="c">// Y.log(&#39;firing queued event &#39; + ce.type + &#39;, from &#39; + this);</span>
690<span class="c"></span>                    <span class="nx">es</span><span class="o">.</span><span class="nx">stopped</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
691                    <span class="nx">es</span><span class="o">.</span><span class="nx">prevented</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
692                   
693<span class="c">// set up stack to allow the next item to be processed</span>
694<span class="c"></span>                    <span class="nx">es</span><span class="o">.</span><span class="nx">next</span> <span class="o">=</span> <span class="nx">ce</span><span class="o">;</span>
695
696                    <span class="nx">ret</span> <span class="o">=</span> <span class="nx">ce</span><span class="o">.</span><span class="nx">fire</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="nx">ce</span><span class="o">,</span> <span class="nx">q</span><span class="o">[</span><span class="m">1</span><span class="o">]);</span>
697                <span class="o">}</span>
698
699                <span class="nx">Y</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_eventstack</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
700            <span class="o">}</span> 
701
702            <span class="k">return</span> <span class="o">(</span><span class="nx">ret</span> <span class="o">!==</span> <span class="kc">false</span><span class="o">);</span>
703        <span class="o">},</span>
704
705        <span class="c">/**</span>
706<span class="c">         * Removes all listeners</span>
707<span class="c">         * @method unsubscribeAll</span>
708<span class="c">         * @return {int} The number of listeners unsubscribed</span>
709<span class="c">         */</span>
710        <span class="nx">unsubscribeAll</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
711            <span class="k">var</span> <span class="nx">subs</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">subscribers</span><span class="o">,</span> <span class="nx">i</span><span class="o">;</span>
712            <span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="k">in</span> <span class="nx">subs</span><span class="o">)</span> <span class="o">{</span>
713                <span class="k">if</span> <span class="o">(</span><span class="nx">subs</span><span class="o">.</span><span class="nx">hasOwnProperty</span><span class="o">(</span><span class="nx">i</span><span class="o">))</span> <span class="o">{</span>
714                    <span class="k">this</span><span class="o">.</span><span class="nx">_delete</span><span class="o">(</span><span class="nx">subs</span><span class="o">[</span><span class="nx">i</span><span class="o">]);</span>
715                <span class="o">}</span>
716            <span class="o">}</span>
717
718            <span class="k">this</span><span class="o">.</span><span class="nx">subscribers</span><span class="o">={};</span>
719
720            <span class="k">return</span> <span class="nx">i</span><span class="o">;</span>
721        <span class="o">},</span>
722
723        <span class="c">/**</span>
724<span class="c">         * @method _delete</span>
725<span class="c">         * @param subscriber object</span>
726<span class="c">         * @private</span>
727<span class="c">         */</span>
728        <span class="nx">_delete</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">s</span><span class="o">)</span> <span class="o">{</span>
729
730            <span class="k">if</span> <span class="o">(</span><span class="nx">s</span><span class="o">)</span> <span class="o">{</span>
731                <span class="nx">delete</span> <span class="nx">s</span><span class="o">.</span><span class="nx">fn</span><span class="o">;</span>
732                <span class="nx">delete</span> <span class="nx">s</span><span class="o">.</span><span class="nx">obj</span><span class="o">;</span>
733                <span class="nx">delete</span> <span class="k">this</span><span class="o">.</span><span class="nx">subscribers</span><span class="o">[</span><span class="nx">s</span><span class="o">.</span><span class="nx">id</span><span class="o">];</span>
734                <span class="nx">delete</span> <span class="k">this</span><span class="o">.</span><span class="nx">afters</span><span class="o">[</span><span class="nx">s</span><span class="o">.</span><span class="nx">id</span><span class="o">];</span>
735            <span class="o">}</span>
736
737        <span class="o">},</span>
738
739        <span class="c">/**</span>
740<span class="c">         * @method toString</span>
741<span class="c">         */</span>
742        <span class="nx">toString</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
743             <span class="c">// return &quot;{ CE &#39;&quot; + this.type + &quot;&#39; &quot; + &quot;id: &quot; + this.id +</span>
744<span class="c"></span>                  <span class="c">// &quot;, host: &quot; + (this.host &amp;&amp; Y.stamp(this.host) + &quot; }&quot;);</span>
745<span class="c"></span>             <span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="nx">type</span><span class="o">;</span>
746        <span class="o">},</span>
747
748        <span class="c">/**</span>
749<span class="c">         * Stop propagation to bubble targets</span>
750<span class="c">         * @method stopPropagation</span>
751<span class="c">         */</span>
752        <span class="nx">stopPropagation</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
753            <span class="k">this</span><span class="o">.</span><span class="nx">stopped</span> <span class="o">=</span> <span class="m">1</span><span class="o">;</span>
754            <span class="nx">Y</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_eventstack</span><span class="o">.</span><span class="nx">stopped</span> <span class="o">=</span> <span class="m">1</span><span class="o">;</span>
755            <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">stoppedFn</span><span class="o">)</span> <span class="o">{</span>
756                <span class="k">this</span><span class="o">.</span><span class="nx">stoppedFn</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">host</span> <span class="o">||</span> <span class="k">this</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
757            <span class="o">}</span>
758        <span class="o">},</span>
759
760        <span class="c">/**</span>
761<span class="c">         * Stops propagation to bubble targets, and prevents any remaining</span>
762<span class="c">         * subscribers on the current target from executing.</span>
763<span class="c">         * @method stopImmediatePropagation</span>
764<span class="c">         */</span>
765        <span class="nx">stopImmediatePropagation</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
766            <span class="k">this</span><span class="o">.</span><span class="nx">stopped</span> <span class="o">=</span> <span class="m">2</span><span class="o">;</span>
767            <span class="nx">Y</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_eventstack</span><span class="o">.</span><span class="nx">stopped</span> <span class="o">=</span> <span class="m">2</span><span class="o">;</span>
768            <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">stoppedFn</span><span class="o">)</span> <span class="o">{</span>
769                <span class="k">this</span><span class="o">.</span><span class="nx">stoppedFn</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">host</span> <span class="o">||</span> <span class="k">this</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
770            <span class="o">}</span>
771        <span class="o">},</span>
772
773        <span class="c">/**</span>
774<span class="c">         * Prevents the execution of this event&#39;s defaultFn</span>
775<span class="c">         * @method preventDefault</span>
776<span class="c">         */</span>
777        <span class="nx">preventDefault</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
778            <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">preventable</span><span class="o">)</span> <span class="o">{</span>
779                <span class="k">this</span><span class="o">.</span><span class="nx">prevented</span> <span class="o">=</span> <span class="m">1</span><span class="o">;</span>
780                <span class="nx">Y</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_eventstack</span><span class="o">.</span><span class="nx">prevented</span> <span class="o">=</span> <span class="m">1</span><span class="o">;</span>
781            <span class="o">}</span>
782            <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">preventedFn</span><span class="o">)</span> <span class="o">{</span>
783                <span class="k">this</span><span class="o">.</span><span class="nx">preventedFn</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">host</span> <span class="o">||</span> <span class="k">this</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
784            <span class="o">}</span>
785        <span class="o">}</span>
786
787    <span class="o">};</span>
788
789    <span class="c">/////////////////////////////////////////////////////////////////////</span>
790<span class="c"></span>
791    <span class="c">/**</span>
792<span class="c">     * Stores the subscriber information to be used when the event fires.</span>
793<span class="c">     * @param {Function} fn       The wrapped function to execute</span>
794<span class="c">     * @param {Object}   obj      An object to be passed along when the event fires</span>
795<span class="c">     * @param {Array} args        subscribe() additional arguments</span>
796<span class="c">     *</span>
797<span class="c">     * @class Event.Subscriber</span>
798<span class="c">     * @constructor</span>
799<span class="c">     */</span>
800    <span class="nx">Y</span><span class="o">.</span><span class="nx">Subscriber</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">obj</span><span class="o">,</span> <span class="nx">args</span><span class="o">)</span> <span class="o">{</span>
801
802        <span class="c">/**</span>
803<span class="c">         * The callback that will be execute when the event fires</span>
804<span class="c">         * This is wrapped by Y.bind if obj was supplied.</span>
805<span class="c">         * @property fn</span>
806<span class="c">         * @type Function</span>
807<span class="c">         */</span>
808        <span class="k">this</span><span class="o">.</span><span class="nx">fn</span> <span class="o">=</span> <span class="nx">fn</span><span class="o">;</span>
809
810        <span class="c">/**</span>
811<span class="c">         * An optional custom object that will passed to the callback when</span>
812<span class="c">         * the event fires</span>
813<span class="c">         * @property obj</span>
814<span class="c">         * @type Object</span>
815<span class="c">         */</span>
816        <span class="k">this</span><span class="o">.</span><span class="nx">obj</span> <span class="o">=</span> <span class="nx">obj</span><span class="o">;</span>
817
818        <span class="c">/**</span>
819<span class="c">         * Unique subscriber id</span>
820<span class="c">         * @property id</span>
821<span class="c">         * @type String</span>
822<span class="c">         */</span>
823        <span class="k">this</span><span class="o">.</span><span class="nx">id</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">stamp</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
824
825        <span class="c">/**</span>
826<span class="c">         * Optional additional arguments supplied to subscribe().  If present,</span>
827<span class="c">         * these will be appended to the arguments supplied to fire()</span>
828<span class="c">         * @property args</span>
829<span class="c">         * @type Array</span>
830<span class="c">         */</span>
831        <span class="c">// this.args = args;</span>
832<span class="c"></span>
833        <span class="k">var</span> <span class="nx">m</span> <span class="o">=</span> <span class="nx">fn</span><span class="o">;</span>
834       
835        <span class="k">if</span> <span class="o">(</span><span class="nx">obj</span><span class="o">)</span> <span class="o">{</span>
836            <span class="k">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="o">(</span><span class="nx">args</span><span class="o">)</span> <span class="o">?</span> <span class="nx">Y</span><span class="o">.</span><span class="nb">Array</span><span class="o">(</span><span class="nx">args</span><span class="o">)</span> <span class="o">:</span> <span class="o">[];</span>
837            <span class="nx">a</span><span class="o">.</span><span class="nx">unshift</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">obj</span><span class="o">);</span>
838            <span class="nx">m</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">bind</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="nx">Y</span><span class="o">,</span> <span class="nx">a</span><span class="o">);</span>
839        <span class="o">}</span>
840       
841        <span class="c">/**</span>
842<span class="c">         * }</span>
843<span class="c">         * fn bound to obj with additional arguments applied via Y.bind</span>
844<span class="c">         * @property wrappedFn</span>
845<span class="c">         * @type Function</span>
846<span class="c">         */</span>
847        <span class="k">this</span><span class="o">.</span><span class="nx">wrappedFn</span> <span class="o">=</span> <span class="nx">m</span><span class="o">;</span>
848
849    <span class="o">};</span>
850
851    <span class="nx">Y</span><span class="o">.</span><span class="nx">Subscriber</span><span class="o">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="o">{</span>
852
853        <span class="c">/**</span>
854<span class="c">         * Executes the subscriber.</span>
855<span class="c">         * @method notify</span>
856<span class="c">         * @param defaultContext The execution context if not overridden</span>
857<span class="c">         * by the subscriber</span>
858<span class="c">         * @param args {Array} Arguments array for the subscriber</span>
859<span class="c">         */</span>
860        <span class="nx">notify</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">defaultContext</span><span class="o">,</span> <span class="nx">args</span><span class="o">)</span> <span class="o">{</span>
861            <span class="k">var</span> <span class="nx">c</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">obj</span> <span class="o">||</span> <span class="nx">defaultContext</span><span class="o">,</span> <span class="nx">ret</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
862
863            <span class="k">try</span> <span class="o">{</span>
864                <span class="nx">ret</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">wrappedFn</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="nx">c</span><span class="o">,</span> <span class="nx">args</span><span class="o">);</span>
865            <span class="o">}</span> <span class="k">catch</span><span class="o">(</span><span class="nx">e</span><span class="o">)</span> <span class="o">{</span>
866                <span class="nx">Y</span><span class="o">.</span><span class="nx">fail</span><span class="o">(</span><span class="k">this</span> <span class="o">+</span> <span class="s1">&#39; failed: &#39;</span> <span class="o">+</span> <span class="nx">e</span><span class="o">.</span><span class="nx">message</span><span class="o">,</span> <span class="nx">e</span><span class="o">);</span>
867            <span class="o">}</span>
868
869            <span class="k">return</span> <span class="nx">ret</span><span class="o">;</span>
870        <span class="o">},</span>
871
872        <span class="c">/**</span>
873<span class="c">         * Returns true if the fn and obj match this objects properties.</span>
874<span class="c">         * Used by the unsubscribe method to match the right subscriber.</span>
875<span class="c">         *</span>
876<span class="c">         * @method contains</span>
877<span class="c">         * @param {Function} fn the function to execute</span>
878<span class="c">         * @param {Object} obj an object to be passed along when the event fires</span>
879<span class="c">         * @return {boolean} true if the supplied arguments match this </span>
880<span class="c">         *                   subscriber&#39;s signature.</span>
881<span class="c">         */</span>
882        <span class="nx">contains</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">obj</span><span class="o">)</span> <span class="o">{</span>
883            <span class="k">if</span> <span class="o">(</span><span class="nx">obj</span><span class="o">)</span> <span class="o">{</span>
884                <span class="k">return</span> <span class="o">((</span><span class="k">this</span><span class="o">.</span><span class="nx">fn</span> <span class="o">==</span> <span class="nx">fn</span><span class="o">)</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="o">.</span><span class="nx">obj</span> <span class="o">==</span> <span class="nx">obj</span><span class="o">);</span>
885            <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
886                <span class="k">return</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">fn</span> <span class="o">==</span> <span class="nx">fn</span><span class="o">);</span>
887            <span class="o">}</span>
888        <span class="o">},</span>
889
890        <span class="c">/**</span>
891<span class="c">         * @method toString</span>
892<span class="c">         */</span>
893        <span class="nx">toString</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
894            <span class="k">return</span> <span class="s2">&quot;Subscriber &quot;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">id</span><span class="o">;</span>
895        <span class="o">}</span>
896    <span class="o">};</span>
897
898<span class="o">},</span> <span class="s2">&quot;3.0.0&quot;</span><span class="o">);</span>
899</pre></div>
900                    </div>
901                        </div>
902                </div>
903                <div class="yui-b">
904            <div class="nav">
905
906                    <div class="module">
907                        <h4>Modules</h4>
908                        <ul class="content">
909
910                                <li class=""><a href="module_anim.html">anim</a></li>
911
912                                <li class=""><a href="module_attribute.html">attribute</a></li>
913
914                                <li class=""><a href="module_base.html">base</a></li>
915
916                                <li class=""><a href="module_cookie.html">cookie</a></li>
917
918                                <li class=""><a href="module_dd.html">dd</a></li>
919
920                                <li class=""><a href="module_dd-plugin.html">dd-plugin</a></li>
921
922                                <li class=""><a href="module_dom.html">dom</a></li>
923
924                                <li class=""><a href="module_dump.html">dump</a></li>
925
926                                <li class="selected"><a href="module_event.html">event</a></li>
927
928                                <li class=""><a href="module_io.html">io</a></li>
929
930                                <li class=""><a href="module_json.html">json</a></li>
931
932                                <li class=""><a href="module_node.html">node</a></li>
933
934                                <li class=""><a href="module_oop.html">oop</a></li>
935
936                                <li class=""><a href="module_queue.html">queue</a></li>
937
938                                <li class=""><a href="module_substitute.html">substitute</a></li>
939
940                                <li class=""><a href="module_yui.html">yui</a></li>
941                        </ul>
942                    </div>
943
944                    <div class="module">
945                        <h4>Classes</h4>
946                        <ul class="content">
947                                <li class=""><a href="Do.html">Do</a></li>
948                                <li class=""><a href="Do.AlterArgs.html">Do.AlterArgs</a></li>
949                                <li class=""><a href="Do.AlterReturn.html">Do.AlterReturn</a></li>
950                                <li class=""><a href="Do.Error.html">Do.Error</a></li>
951                                <li class=""><a href="Do.Method.html">Do.Method</a></li>
952                                <li class=""><a href="Event.html">Event</a></li>
953                                <li class=""><a href="Event.Custom.html">Event.Custom</a></li>
954                                <li class=""><a href="Event.Facade.html">Event.Facade</a></li>
955                                <li class=""><a href="Event.Handle.html">Event.Handle</a></li>
956                                <li class=""><a href="Event.Subscriber.html">Event.Subscriber</a></li>
957                                <li class=""><a href="Event.Target.html">Event.Target</a></li>
958                        </ul>
959                    </div>
960
961                    <div class="module">
962                        <h4>Files</h4>
963                        <ul class="content">       
964                                <li class="selected"><a href="event-custom.js.html">event-custom.js</a></li>
965                                <li class=""><a href="event-do.js.html">event-do.js</a></li>
966                                <li class=""><a href="event-dom.js.html">event-dom.js</a></li>
967                                <li class=""><a href="event-facade.js.html">event-facade.js</a></li>
968                                <li class=""><a href="event-ready.js.html">event-ready.js</a></li>
969                                <li class=""><a href="event-target.js.html">event-target.js</a></li>
970                                <li class=""><a href="event.js.html">event.js</a></li>
971                        </ul>
972                    </div>
973
974
975
976
977
978            </div>
979                </div>
980        </div>
981        <div id="ft">
982        <hr />
983        Copyright &copy; 2008 Yahoo! Inc. All rights reserved.
984        </div>
985</div>
986</body>
987</html>
Note: See TracBrowser for help on using the repository browser.