source: cows/branches/cows-vis/cows/pylons/project_templates/cows_server/+package+/public/js/yui/api/event-dom.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-dom.js.html@5259
Revision 5259, 99.2 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-dom.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-dom.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"> * The YUI DOM event system</span>
42<span class="c"> * @submodule event-dom</span>
43<span class="c"> * @module event</span>
44<span class="c"> */</span>
45<span class="o">(</span><span class="k">function</span><span class="o">()</span> <span class="o">{</span>
46
47    <span class="k">var</span> <span class="nx">add</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">el</span><span class="o">,</span> <span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">,</span> <span class="nx">capture</span><span class="o">)</span> <span class="o">{</span>
48        <span class="k">if</span> <span class="o">(</span><span class="nx">el</span><span class="o">.</span><span class="nx">addEventListener</span><span class="o">)</span> <span class="o">{</span>
49                <span class="nx">el</span><span class="o">.</span><span class="nx">addEventListener</span><span class="o">(</span><span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">,</span> <span class="o">!!</span><span class="nx">capture</span><span class="o">);</span>
50        <span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="nx">el</span><span class="o">.</span><span class="nx">attachEvent</span><span class="o">)</span> <span class="o">{</span>
51                <span class="nx">el</span><span class="o">.</span><span class="nx">attachEvent</span><span class="o">(</span><span class="s2">&quot;on&quot;</span> <span class="o">+</span> <span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">);</span>
52        <span class="o">}</span> 
53    <span class="o">},</span>
54
55    <span class="nx">remove</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">el</span><span class="o">,</span> <span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">,</span> <span class="nx">capture</span><span class="o">)</span> <span class="o">{</span>
56        <span class="k">if</span> <span class="o">(</span><span class="nx">el</span><span class="o">.</span><span class="nx">removeEventListener</span><span class="o">)</span> <span class="o">{</span>
57                <span class="nx">el</span><span class="o">.</span><span class="nx">removeEventListener</span><span class="o">(</span><span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">,</span> <span class="o">!!</span><span class="nx">capture</span><span class="o">);</span>
58        <span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="nx">el</span><span class="o">.</span><span class="nx">detachEvent</span><span class="o">)</span> <span class="o">{</span>
59                <span class="nx">el</span><span class="o">.</span><span class="nx">detachEvent</span><span class="o">(</span><span class="s2">&quot;on&quot;</span> <span class="o">+</span> <span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">);</span>
60        <span class="o">}</span>
61    <span class="o">},</span>
62
63    <span class="nx">onLoad</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
64        <span class="nx">YUI</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">windowLoaded</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
65        <span class="nx">remove</span><span class="o">(</span><span class="nb">window</span><span class="o">,</span> <span class="s2">&quot;load&quot;</span><span class="o">,</span> <span class="nx">onLoad</span><span class="o">);</span>
66    <span class="o">};</span>
67
68    <span class="nx">add</span><span class="o">(</span><span class="nb">window</span><span class="o">,</span> <span class="s2">&quot;load&quot;</span><span class="o">,</span> <span class="nx">onLoad</span><span class="o">);</span>
69
70<span class="nx">YUI</span><span class="o">.</span><span class="nx">add</span><span class="o">(</span><span class="s2">&quot;event-dom&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>
71
72    <span class="c">/*</span>
73<span class="c">     * The Event Utility provides utilities for managing DOM Events and tools</span>
74<span class="c">     * for building event systems</span>
75<span class="c">     *</span>
76<span class="c">     * @module event</span>
77<span class="c">     * @title Event Utility</span>
78<span class="c">     */</span>
79
80    <span class="c">/**</span>
81<span class="c">     * The event utility provides functions to add and remove event listeners,</span>
82<span class="c">     * event cleansing.  It also tries to automatically remove listeners it</span>
83<span class="c">     * registers during the unload event.</span>
84<span class="c">     *</span>
85<span class="c">     * @class Event</span>
86<span class="c">     * @static</span>
87<span class="c">     */</span>
88        <span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
89
90            <span class="c">/**</span>
91<span class="c">             * True after the onload event has fired</span>
92<span class="c">             * @property loadComplete</span>
93<span class="c">             * @type boolean</span>
94<span class="c">             * @static</span>
95<span class="c">             * @private</span>
96<span class="c">             */</span>
97            <span class="k">var</span> <span class="nx">loadComplete</span> <span class="o">=</span>  <span class="kc">false</span><span class="o">;</span>
98
99            <span class="c">/**</span>
100<span class="c">             * The number of times to poll after window.onload.  This number is</span>
101<span class="c">             * increased if additional late-bound handlers are requested after</span>
102<span class="c">             * the page load.</span>
103<span class="c">             * @property _retryCount</span>
104<span class="c">             * @static</span>
105<span class="c">             * @private</span>
106<span class="c">             */</span>
107            <span class="k">var</span> <span class="nx">_retryCount</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
108
109            <span class="c">/**</span>
110<span class="c">             * onAvailable listeners</span>
111<span class="c">             * @property _avail</span>
112<span class="c">             * @static</span>
113<span class="c">             * @private</span>
114<span class="c">             */</span>
115            <span class="k">var</span> <span class="nx">_avail</span> <span class="o">=</span> <span class="o">[];</span>
116
117            <span class="c">/**</span>
118<span class="c">             * Custom event wrappers for DOM events.  Key is </span>
119<span class="c">             * &#39;event:&#39; + Element uid stamp + event type</span>
120<span class="c">             * @property _wrappers</span>
121<span class="c">             * @type Y.Event.Custom</span>
122<span class="c">             * @static</span>
123<span class="c">             * @private</span>
124<span class="c">             */</span>
125            <span class="k">var</span> <span class="nx">_wrappers</span> <span class="o">=</span> <span class="o">{};</span>
126
127            <span class="k">var</span> <span class="nx">_windowLoadKey</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
128
129            <span class="c">/**</span>
130<span class="c">             * Custom event wrapper map DOM events.  Key is </span>
131<span class="c">             * Element uid stamp.  Each item is a hash of custom event</span>
132<span class="c">             * wrappers as provided in the _wrappers collection.  This</span>
133<span class="c">             * provides the infrastructure for getListeners.</span>
134<span class="c">             * @property _el_events</span>
135<span class="c">             * @static</span>
136<span class="c">             * @private</span>
137<span class="c">             */</span>
138            <span class="k">var</span> <span class="nx">_el_events</span> <span class="o">=</span> <span class="o">{};</span>
139
140            <span class="k">return</span> <span class="o">{</span>
141
142                <span class="c">/**</span>
143<span class="c">                 * The number of times we should look for elements that are not</span>
144<span class="c">                 * in the DOM at the time the event is requested after the document</span>
145<span class="c">                 * has been loaded.  The default is 2000@amp;20 ms, so it will poll</span>
146<span class="c">                 * for 40 seconds or until all outstanding handlers are bound</span>
147<span class="c">                 * (whichever comes first).</span>
148<span class="c">                 * @property POLL_RETRYS</span>
149<span class="c">                 * @type int</span>
150<span class="c">                 * @static</span>
151<span class="c">                 * @final</span>
152<span class="c">                 */</span>
153                <span class="nx">POLL_RETRYS</span><span class="o">:</span> <span class="m">2000</span><span class="o">,</span>
154
155                <span class="c">/**</span>
156<span class="c">                 * The poll interval in milliseconds</span>
157<span class="c">                 * @property POLL_INTERVAL</span>
158<span class="c">                 * @type int</span>
159<span class="c">                 * @static</span>
160<span class="c">                 * @final</span>
161<span class="c">                 */</span>
162                <span class="nx">POLL_INTERVAL</span><span class="o">:</span> <span class="m">20</span><span class="o">,</span>
163
164                <span class="c">/**</span>
165<span class="c">                 * addListener/removeListener can throw errors in unexpected scenarios.</span>
166<span class="c">                 * These errors are suppressed, the method returns false, and this property</span>
167<span class="c">                 * is set</span>
168<span class="c">                 * @property lastError</span>
169<span class="c">                 * @static</span>
170<span class="c">                 * @type Error</span>
171<span class="c">                 */</span>
172                <span class="nx">lastError</span><span class="o">:</span> <span class="kc">null</span><span class="o">,</span>
173
174
175                <span class="c">/**</span>
176<span class="c">                 * poll handle</span>
177<span class="c">                 * @property _interval</span>
178<span class="c">                 * @static</span>
179<span class="c">                 * @private</span>
180<span class="c">                 */</span>
181                <span class="nx">_interval</span><span class="o">:</span> <span class="kc">null</span><span class="o">,</span>
182
183                <span class="c">/**</span>
184<span class="c">                 * document readystate poll handle</span>
185<span class="c">                 * @property _dri</span>
186<span class="c">                 * @static</span>
187<span class="c">                 * @private</span>
188<span class="c">                 */</span>
189                 <span class="nx">_dri</span><span class="o">:</span> <span class="kc">null</span><span class="o">,</span>
190
191                <span class="c">/**</span>
192<span class="c">                 * True when the document is initially usable</span>
193<span class="c">                 * @property DOMReady</span>
194<span class="c">                 * @type boolean</span>
195<span class="c">                 * @static</span>
196<span class="c">                 */</span>
197                <span class="nx">DOMReady</span><span class="o">:</span> <span class="kc">false</span><span class="o">,</span>
198
199                <span class="c">/**</span>
200<span class="c">                 * @method startInterval</span>
201<span class="c">                 * @static</span>
202<span class="c">                 * @private</span>
203<span class="c">                 */</span>
204                <span class="nx">startInterval</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
205                    <span class="k">if</span> <span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">_interval</span><span class="o">)</span> <span class="o">{</span>
206<span class="k">this</span><span class="o">.</span><span class="nx">_interval</span> <span class="o">=</span> <span class="nx">setInterval</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="k">this</span><span class="o">.</span><span class="nx">_tryPreloadAttach</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">POLL_INTERVAL</span><span class="o">);</span>
207                    <span class="o">}</span>
208                <span class="o">},</span>
209
210                <span class="c">/**</span>
211<span class="c">                 * Executes the supplied callback when the item with the supplied</span>
212<span class="c">                 * id is found.  This is meant to be used to execute behavior as</span>
213<span class="c">                 * soon as possible as the page loads.  If you use this after the</span>
214<span class="c">                 * initial page load it will poll for a fixed time for the element.</span>
215<span class="c">                 * The number of times it will poll and the frequency are</span>
216<span class="c">                 * configurable.  By default it will poll for 10 seconds.</span>
217<span class="c">                 *</span>
218<span class="c">                 * &lt;p&gt;The callback is executed with a single parameter:</span>
219<span class="c">                 * the custom object parameter, if provided.&lt;/p&gt;</span>
220<span class="c">                 *</span>
221<span class="c">                 * @method onAvailable</span>
222<span class="c">                 *</span>
223<span class="c">                 * @param {string||string[]}   id the id of the element, or an array</span>
224<span class="c">                 * of ids to look for.</span>
225<span class="c">                 * @param {function} fn what to execute when the element is found.</span>
226<span class="c">                 * @param {object}   p_obj an optional object to be passed back as</span>
227<span class="c">                 *                   a parameter to fn.</span>
228<span class="c">                 * @param {boolean|object}  p_override If set to true, fn will execute</span>
229<span class="c">                 *                   in the context of p_obj, if set to an object it</span>
230<span class="c">                 *                   will execute in the context of that object</span>
231<span class="c">                 * @param checkContent {boolean} check child node readiness (onContentReady)</span>
232<span class="c">                 * @static</span>
233<span class="c">                 * @deprecated This will be replaced with a special Y.on custom event</span>
234<span class="c">                 */</span>
235                <span class="c">// @TODO fix arguments</span>
236<span class="c"></span>                <span class="nx">onAvailable</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">id</span><span class="o">,</span> <span class="nx">fn</span><span class="o">,</span> <span class="nx">p_obj</span><span class="o">,</span> <span class="nx">p_override</span><span class="o">,</span> <span class="nx">checkContent</span><span class="o">)</span> <span class="o">{</span>
237
238                    <span class="c">// var a = (Y.Lang.isString(id)) ? [id] : id;</span>
239<span class="c"></span>                    <span class="k">var</span> <span class="nx">a</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">id</span><span class="o">);</span>
240
241                    <span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">;</span> <span class="nx">i</span><span class="o">&lt;</span><span class="nx">a</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span><span class="o">=</span><span class="nx">i</span><span class="o">+</span><span class="m">1</span><span class="o">)</span> <span class="o">{</span>
242                        <span class="nx">_avail</span><span class="o">.</span><span class="nx">push</span><span class="o">({</span> <span class="nx">id</span><span class="o">:</span>         <span class="nx">a</span><span class="o">[</span><span class="nx">i</span><span class="o">],</span> 
243                                      <span class="nx">fn</span><span class="o">:</span>         <span class="nx">fn</span><span class="o">,</span> 
244                                      <span class="nx">obj</span><span class="o">:</span>        <span class="nx">p_obj</span><span class="o">,</span> 
245                                      <span class="nx">override</span><span class="o">:</span>   <span class="nx">p_override</span><span class="o">,</span> 
246                                      <span class="nx">checkReady</span><span class="o">:</span> <span class="nx">checkContent</span> <span class="o">});</span>
247                    <span class="o">}</span>
248                    <span class="nx">_retryCount</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">POLL_RETRYS</span><span class="o">;</span>
249                    <span class="c">// this.startInterval();</span>
250<span class="c"></span>                    <span class="c">// this._tryPreloadAttach();</span>
251<span class="c"></span>
252                    <span class="c">// We want the first test to be immediate, but async</span>
253<span class="c"></span>                    <span class="nx">setTimeout</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="k">this</span><span class="o">.</span><span class="nx">_tryPreloadAttach</span><span class="o">,</span> <span class="k">this</span><span class="o">),</span> <span class="m">0</span><span class="o">);</span>
254                <span class="o">},</span>
255
256                <span class="c">/**</span>
257<span class="c">                 * Works the same way as onAvailable, but additionally checks the</span>
258<span class="c">                 * state of sibling elements to determine if the content of the</span>
259<span class="c">                 * available element is safe to modify.</span>
260<span class="c">                 *</span>
261<span class="c">                 * &lt;p&gt;The callback is executed with a single parameter:</span>
262<span class="c">                 * the custom object parameter, if provided.&lt;/p&gt;</span>
263<span class="c">                 *</span>
264<span class="c">                 * @method onContentReady</span>
265<span class="c">                 *</span>
266<span class="c">                 * @param {string}   id the id of the element to look for.</span>
267<span class="c">                 * @param {function} fn what to execute when the element is ready.</span>
268<span class="c">                 * @param {object}   p_obj an optional object to be passed back as</span>
269<span class="c">                 *                   a parameter to fn.</span>
270<span class="c">                 * @param {boolean|object}  p_override If set to true, fn will execute</span>
271<span class="c">                 *                   in the context of p_obj.  If an object, fn will</span>
272<span class="c">                 *                   exectute in the context of that object</span>
273<span class="c">                 *</span>
274<span class="c">                 * @static</span>
275<span class="c">                 * @deprecated This will be replaced with a special Y.on custom event</span>
276<span class="c">                 */</span>
277                <span class="c">// @TODO fix arguments</span>
278<span class="c"></span>                <span class="nx">onContentReady</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">id</span><span class="o">,</span> <span class="nx">fn</span><span class="o">,</span> <span class="nx">p_obj</span><span class="o">,</span> <span class="nx">p_override</span><span class="o">)</span> <span class="o">{</span>
279                    <span class="k">this</span><span class="o">.</span><span class="nx">onAvailable</span><span class="o">(</span><span class="nx">id</span><span class="o">,</span> <span class="nx">fn</span><span class="o">,</span> <span class="nx">p_obj</span><span class="o">,</span> <span class="nx">p_override</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>
280                <span class="o">},</span>
281
282                <span class="c">/**</span>
283<span class="c">                 * Executes the supplied callback when the DOM is first usable.  This</span>
284<span class="c">                 * will execute immediately if called after the DOMReady event has</span>
285<span class="c">                 * fired.   @todo the DOMContentReady event does not fire when the</span>
286<span class="c">                 * script is dynamically injected into the page.  This means the</span>
287<span class="c">                 * DOMReady custom event will never fire in FireFox or Opera when the</span>
288<span class="c">                 * library is injected.  It _will_ fire in Safari, and the IE </span>
289<span class="c">                 * implementation would allow for us to fire it if the defered script</span>
290<span class="c">                 * is not available.  We want this to behave the same in all browsers.</span>
291<span class="c">                 * Is there a way to identify when the script has been injected </span>
292<span class="c">                 * instead of included inline?  Is there a way to know whether the </span>
293<span class="c">                 * window onload event has fired without having had a listener attached </span>
294<span class="c">                 * to it when it did so?</span>
295<span class="c">                 *</span>
296<span class="c">                 * &lt;p&gt;The callback is a Event.Custom, so the signature is:&lt;/p&gt;</span>
297<span class="c">                 * &lt;p&gt;type &amp;lt;string&amp;gt;, args &amp;lt;array&amp;gt;, customobject &amp;lt;object&amp;gt;&lt;/p&gt;</span>
298<span class="c">                 * &lt;p&gt;For DOMReady events, there are no fire argments, so the</span>
299<span class="c">                 * signature is:&lt;/p&gt;</span>
300<span class="c">                 * &lt;p&gt;&quot;DOMReady&quot;, [], obj&lt;/p&gt;</span>
301<span class="c">                 *</span>
302<span class="c">                 *</span>
303<span class="c">                 * @method onDOMReady</span>
304<span class="c">                 *</span>
305<span class="c">                 * @param {function} fn what to execute when the element is found.</span>
306<span class="c">                 * @optional context execution context</span>
307<span class="c">                 * @optional args 1..n arguments to send to the listener</span>
308<span class="c">                 *</span>
309<span class="c">                 * @static</span>
310<span class="c">                 * @deprecated Use Y.on(&#39;event:ready&#39;);</span>
311<span class="c">                 */</span>
312                <span class="nx">onDOMReady</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="o">{</span>
313                    <span class="c">// var ev = Y.Event.DOMReadyEvent;</span>
314<span class="c"></span>                    <span class="c">// ev.subscribe.apply(ev, arguments);</span>
315<span class="c"></span>                    <span class="k">var</span> <span class="nx">a</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>
316                    <span class="nx">a</span><span class="o">.</span><span class="nx">unshift</span><span class="o">(</span><span class="s1">&#39;event:ready&#39;</span><span class="o">);</span>
317                    <span class="nx">Y</span><span class="o">.</span><span class="nx">on</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>
318                <span class="o">},</span>
319
320                <span class="c">/**</span>
321<span class="c">                 * Appends an event handler</span>
322<span class="c">                 *</span>
323<span class="c">                 * @method addListener</span>
324<span class="c">                 *</span>
325<span class="c">                 * @param {String|HTMLElement|Array|NodeList} el An id, an element </span>
326<span class="c">                 *  reference, or a collection of ids and/or elements to assign the </span>
327<span class="c">                 *  listener to.</span>
328<span class="c">                 * @param {String}   type     The type of event to append</span>
329<span class="c">                 * @param {Function} fn        The method the event invokes</span>
330<span class="c">                 * @param {Object}   obj    An arbitrary object that will be </span>
331<span class="c">                 *                             passed as a parameter to the handler</span>
332<span class="c">                 * @param {Boolean|object}  args 1..n ar</span>
333<span class="c">                 * @return {Boolean} True if the action was successful or defered,</span>
334<span class="c">                 *                        false if one or more of the elements </span>
335<span class="c">                 *                        could not have the listener attached,</span>
336<span class="c">                 *                        or if the operation throws an exception.</span>
337<span class="c">                 * @static</span>
338<span class="c">                 * @deprecated Use Y.on instead.  This will be removed in PR2</span>
339<span class="c">                 */</span>
340                <span class="nx">addListener</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">el</span><span class="o">,</span> <span class="nx">type</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>
341
342                    <span class="c">// Y.log(&#39;addListener: &#39; + Y.Lang.dump(Y.Array(arguments, 0, true), 1));</span>
343<span class="c"></span>
344                    <span class="k">var</span> <span class="nx">a</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">1</span><span class="o">,</span> <span class="kc">true</span><span class="o">),</span> <span class="nx">override</span> <span class="o">=</span> <span class="nx">a</span><span class="o">[</span><span class="m">3</span><span class="o">],</span> <span class="nx">E</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">,</span>
345                        <span class="nx">aa</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>
346
347                    <span class="k">if</span> <span class="o">(!</span><span class="nx">fn</span> <span class="o">||</span> <span class="o">!</span><span class="nx">fn</span><span class="o">.</span><span class="nx">call</span><span class="o">)</span> <span class="o">{</span>
348    <span class="c">// throw new TypeError(type + &quot; addListener call failed, callback undefined&quot;);</span>
349<span class="c"></span>    <span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="nx">type</span> <span class="o">+</span> <span class="s2">&quot; addListener call failed, invalid callback&quot;</span><span class="o">,</span> <span class="s2">&quot;error&quot;</span><span class="o">,</span> <span class="s2">&quot;event&quot;</span><span class="o">);</span>
350                        <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
351                    <span class="o">}</span>
352
353                    <span class="c">// The el argument can be an array of elements or element ids.</span>
354<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">_isValidCollection</span><span class="o">(</span><span class="nx">el</span><span class="o">))</span> <span class="o">{</span>
355
356                        <span class="c">// Y.log(&#39;collection: &#39; + el);</span>
357<span class="c"></span>                        <span class="c">// Y.log(&#39;collection: &#39; + el.item(0) + &#39;, &#39; + el.item(1));</span>
358<span class="c"></span>
359                        <span class="k">var</span> <span class="nx">handles</span><span class="o">=[],</span> <span class="nx">h</span><span class="o">,</span> <span class="nx">i</span><span class="o">,</span> <span class="nx">l</span><span class="o">,</span> <span class="nx">proc</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span> <span class="nx">k</span><span class="o">)</span> <span class="o">{</span>
360                            <span class="c">// handles.push(this.addListener(el[i], type, fn, obj, override));</span>
361<span class="c"></span>                            <span class="c">// var node = el.item(k);</span>
362<span class="c"></span>                            <span class="c">// Y.log(&#39;collection stuff: &#39; + node);</span>
363<span class="c"></span>                           
364                            <span class="k">var</span> <span class="nx">b</span> <span class="o">=</span> <span class="nx">a</span><span class="o">.</span><span class="nx">slice</span><span class="o">();</span>
365                            <span class="nx">b</span><span class="o">.</span><span class="nx">unshift</span><span class="o">(</span><span class="nx">v</span><span class="o">);</span>
366                            <span class="nx">h</span> <span class="o">=</span> <span class="nx">E</span><span class="o">.</span><span class="nx">addListener</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="nx">E</span><span class="o">,</span> <span class="nx">b</span><span class="o">);</span>
367                            <span class="nx">handles</span><span class="o">.</span><span class="nx">push</span><span class="o">(</span><span class="nx">h</span><span class="o">);</span>
368                        <span class="o">};</span>
369
370                        <span class="nx">Y</span><span class="o">.</span><span class="nx">each</span><span class="o">(</span><span class="nx">el</span><span class="o">,</span> <span class="nx">proc</span><span class="o">,</span> <span class="nx">E</span><span class="o">);</span>
371
372
373                        <span class="k">return</span> <span class="nx">handles</span><span class="o">;</span>
374
375
376                    <span class="o">}</span> <span class="k">else</span> <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">isString</span><span class="o">(</span><span class="nx">el</span><span class="o">))</span> <span class="o">{</span>
377                        <span class="k">var</span> <span class="nx">oEl</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">all</span><span class="o">(</span><span class="nx">el</span><span class="o">);</span>
378                        <span class="c">// If the el argument is a string, we assume it is </span>
379<span class="c"></span>                        <span class="c">// actually the id of the element.  If the page is loaded</span>
380<span class="c"></span>                        <span class="c">// we convert el to the actual element, otherwise we </span>
381<span class="c"></span>                        <span class="c">// defer attaching the event until onload event fires</span>
382<span class="c"></span>
383                        <span class="c">// check to see if we need to delay hooking up the event </span>
384<span class="c"></span>                        <span class="c">// until after the page loads.</span>
385<span class="c"></span>                        <span class="k">var</span> <span class="nx">size</span> <span class="o">=</span> <span class="nx">oEl</span><span class="o">.</span><span class="nx">size</span><span class="o">();</span>
386                        <span class="k">if</span> <span class="o">(</span><span class="nx">size</span><span class="o">)</span> <span class="o">{</span>
387                            <span class="k">if</span> <span class="o">(</span><span class="nx">size</span> <span class="o">&gt;</span> <span class="m">1</span><span class="o">)</span> <span class="o">{</span>
388                                <span class="nx">aa</span><span class="o">[</span><span class="m">0</span><span class="o">]</span> <span class="o">=</span> <span class="nx">oEl</span><span class="o">;</span>
389                                <span class="k">return</span> <span class="nx">E</span><span class="o">.</span><span class="nx">addListener</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="nx">E</span><span class="o">,</span> <span class="nx">aa</span><span class="o">);</span>
390                            <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
391                                <span class="nx">el</span> <span class="o">=</span> <span class="nx">oEl</span><span class="o">.</span><span class="nx">item</span><span class="o">(</span><span class="m">0</span><span class="o">);</span>
392                            <span class="o">}</span>
393                        <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
394                            <span class="c">//</span>
395<span class="c"></span>                            <span class="c">// defer adding the event until the element is available</span>
396<span class="c"></span>                            <span class="k">this</span><span class="o">.</span><span class="nx">onAvailable</span><span class="o">(</span><span class="nx">el</span><span class="o">,</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
397                                <span class="c">// Y.Event.addListener(el, type, fn, obj, override);</span>
398<span class="c"></span>                                <span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">addListener</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">Event</span><span class="o">,</span> <span class="nx">aa</span><span class="o">);</span>
399                            <span class="o">});</span>
400
401                            <span class="k">return</span> <span class="kc">true</span><span class="o">;</span>
402                        <span class="o">}</span>
403                    <span class="o">}</span>
404
405                    <span class="c">// Element should be an html element or an array if we get </span>
406<span class="c"></span>                    <span class="c">// here.</span>
407<span class="c"></span>                    <span class="k">if</span> <span class="o">(!</span><span class="nx">el</span><span class="o">)</span> <span class="o">{</span>
408                        <span class="c">// Y.log(&quot;unable to attach event &quot; + type);</span>
409<span class="c"></span>                        <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
410                    <span class="o">}</span>
411
412                    <span class="c">// the custom event key is the uid for the element + type</span>
413<span class="c"></span>
414                    <span class="k">var</span> <span class="nx">ek</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="nx">el</span><span class="o">),</span> <span class="nx">key</span> <span class="o">=</span> <span class="s1">&#39;event:&#39;</span> <span class="o">+</span> <span class="nx">ek</span> <span class="o">+</span> <span class="nx">type</span><span class="o">,</span>
415                        <span class="nx">cewrapper</span> <span class="o">=</span> <span class="nx">_wrappers</span><span class="o">[</span><span class="nx">key</span><span class="o">];</span>
416
417
418                    <span class="k">if</span> <span class="o">(!</span><span class="nx">cewrapper</span><span class="o">)</span> <span class="o">{</span>
419                        <span class="c">// create CE wrapper</span>
420<span class="c"></span>                        <span class="nx">cewrapper</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">publish</span><span class="o">(</span><span class="nx">key</span><span class="o">,</span> <span class="o">{</span>
421                            <span class="nx">silent</span><span class="o">:</span> <span class="kc">true</span><span class="o">,</span>
422                            <span class="c">// host: this,</span>
423<span class="c"></span>                            <span class="nx">bubbles</span><span class="o">:</span> <span class="kc">false</span>
424                        <span class="o">});</span>
425
426                        <span class="c">// cache the dom event details in the custom event</span>
427<span class="c"></span>                        <span class="c">// for later removeListener calls</span>
428<span class="c"></span>                        <span class="nx">cewrapper</span><span class="o">.</span><span class="nx">el</span> <span class="o">=</span> <span class="nx">el</span><span class="o">;</span>
429                        <span class="nx">cewrapper</span><span class="o">.</span><span class="nx">type</span> <span class="o">=</span> <span class="nx">type</span><span class="o">;</span>
430                        <span class="nx">cewrapper</span><span class="o">.</span><span class="nx">fn</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">e</span><span class="o">)</span> <span class="o">{</span>
431                            <span class="nx">cewrapper</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">getEvent</span><span class="o">(</span><span class="nx">e</span><span class="o">,</span> <span class="nx">el</span><span class="o">));</span>
432                        <span class="o">};</span>
433
434                        <span class="k">if</span> <span class="o">(</span><span class="nx">el</span> <span class="o">==</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">config</span><span class="o">.</span><span class="nx">win</span> <span class="o">&amp;&amp;</span> <span class="nx">type</span> <span class="o">==</span> <span class="s2">&quot;load&quot;</span><span class="o">)</span> <span class="o">{</span>
435                            <span class="c">// window load happens once</span>
436<span class="c"></span>                            <span class="nx">cewrapper</span><span class="o">.</span><span class="nx">fireOnce</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
437                            <span class="nx">_windowLoadKey</span> <span class="o">=</span> <span class="nx">key</span><span class="o">;</span>
438
439                            <span class="c">// if the load is complete, fire immediately.</span>
440<span class="c"></span>                            <span class="c">// all subscribers, including the current one</span>
441<span class="c"></span>                            <span class="c">// will be notified.</span>
442<span class="c"></span>                            <span class="k">if</span> <span class="o">(</span><span class="nx">YUI</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">windowLoaded</span><span class="o">)</span> <span class="o">{</span>
443                                <span class="nx">cewrapper</span><span class="o">.</span><span class="nx">fire</span><span class="o">();</span>
444                            <span class="o">}</span>
445                        <span class="o">}</span>
446
447                        <span class="nx">_wrappers</span><span class="o">[</span><span class="nx">key</span><span class="o">]</span> <span class="o">=</span> <span class="nx">cewrapper</span><span class="o">;</span>
448                        <span class="nx">_el_events</span><span class="o">[</span><span class="nx">ek</span><span class="o">]</span> <span class="o">=</span> <span class="nx">_el_events</span><span class="o">[</span><span class="nx">ek</span><span class="o">]</span> <span class="o">||</span> <span class="o">{};</span>
449                        <span class="nx">_el_events</span><span class="o">[</span><span class="nx">ek</span><span class="o">][</span><span class="nx">key</span><span class="o">]</span> <span class="o">=</span> <span class="nx">cewrapper</span><span class="o">;</span>
450
451                        <span class="c">// var capture = (Y.lang.isObject(obj) &amp;&amp; obj.capture);</span>
452<span class="c"></span>                        <span class="c">// attach a listener that fires the custom event</span>
453<span class="c"></span>                        <span class="k">this</span><span class="o">.</span><span class="nx">nativeAdd</span><span class="o">(</span><span class="nx">el</span><span class="o">,</span> <span class="nx">type</span><span class="o">,</span> <span class="nx">cewrapper</span><span class="o">.</span><span class="nx">fn</span><span class="o">,</span> <span class="kc">false</span><span class="o">);</span>
454                    <span class="o">}</span>
455
456       
457                    <span class="c">// from type, fn, etc to fn, obj, override</span>
458<span class="c"></span>                    <span class="nx">a</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>
459                    <span class="c">// a = a.shift();</span>
460<span class="c"></span>
461                    <span class="k">var</span> <span class="nx">context</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="nx">get</span><span class="o">(</span><span class="nx">el</span><span class="o">);</span>
462                    <span class="c">// if (override) {</span>
463<span class="c"></span>                        <span class="c">// if (override === true) {</span>
464<span class="c"></span>                            <span class="c">// context = obj;</span>
465<span class="c"></span>                        <span class="c">// } else {</span>
466<span class="c"></span>                            <span class="c">// context = override;</span>
467<span class="c"></span>                        <span class="c">// }</span>
468<span class="c"></span>                    <span class="c">// }</span>
469<span class="c"></span>
470                    <span class="nx">a</span><span class="o">[</span><span class="m">1</span><span class="o">]</span> <span class="o">=</span> <span class="nx">context</span><span class="o">;</span>
471
472                    <span class="c">// set context to the Node if not specified</span>
473<span class="c"></span>                    <span class="k">return</span> <span class="nx">cewrapper</span><span class="o">.</span><span class="nx">subscribe</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="nx">cewrapper</span><span class="o">,</span> <span class="nx">a</span><span class="o">);</span>
474
475
476                <span class="o">},</span>
477
478                <span class="c">/**</span>
479<span class="c">                 * Removes an event listener.  Supports the signature the event was bound</span>
480<span class="c">                 * with, but the preferred way to remove listeners is using the handle</span>
481<span class="c">                 * that is returned when using Y.on</span>
482<span class="c">                 *</span>
483<span class="c">                 * @method removeListener</span>
484<span class="c">                 *</span>
485<span class="c">                 * @param {String|HTMLElement|Array|NodeList} el An id, an element </span>
486<span class="c">                 *  reference, or a collection of ids and/or elements to remove</span>
487<span class="c">                 *  the listener from.</span>
488<span class="c">                 * @param {String} type the type of event to remove.</span>
489<span class="c">                 * @param {Function} fn the method the event invokes.  If fn is</span>
490<span class="c">                 *  undefined, then all event handlers for the type of event are *  removed.</span>
491<span class="c">                 * @return {boolean} true if the unbind was successful, false *  otherwise.</span>
492<span class="c">                 * @static</span>
493<span class="c">                 */</span>
494                <span class="nx">removeListener</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">el</span><span class="o">,</span> <span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">)</span> <span class="o">{</span>
495
496                    <span class="k">if</span> <span class="o">(</span><span class="nx">el</span> <span class="o">&amp;&amp;</span> <span class="nx">el</span><span class="o">.</span><span class="nx">detach</span><span class="o">)</span> <span class="o">{</span>
497                        <span class="k">return</span> <span class="nx">el</span><span class="o">.</span><span class="nx">detach</span><span class="o">();</span>
498                    <span class="o">}</span>
499                    <span class="k">var</span> <span class="nx">i</span><span class="o">,</span> <span class="nx">len</span><span class="o">,</span> <span class="nx">li</span><span class="o">;</span>
500
501                    <span class="c">// The el argument can be a string</span>
502<span class="c"></span>                    <span class="k">if</span> <span class="o">(</span><span class="k">typeof</span> <span class="nx">el</span> <span class="o">==</span> <span class="s2">&quot;string&quot;</span><span class="o">)</span> <span class="o">{</span>
503                        <span class="nx">el</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">el</span><span class="o">);</span>
504                    <span class="c">// The el argument can be an array of elements or element ids.</span>
505<span class="c"></span>                    <span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span> <span class="k">this</span><span class="o">.</span><span class="nx">_isValidCollection</span><span class="o">(</span><span class="nx">el</span><span class="o">))</span> <span class="o">{</span>
506                        <span class="k">var</span> <span class="nx">ok</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
507                        <span class="k">for</span> <span class="o">(</span><span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">,</span><span class="nx">len</span><span class="o">=</span><span class="nx">el</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span><span class="o">&lt;</span><span class="nx">len</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
508                            <span class="nx">ok</span> <span class="o">=</span> <span class="o">(</span> <span class="k">this</span><span class="o">.</span><span class="nx">removeListener</span><span class="o">(</span><span class="nx">el</span><span class="o">[</span><span class="nx">i</span><span class="o">],</span> <span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">)</span> <span class="o">&amp;&amp;</span> <span class="nx">ok</span> <span class="o">);</span>
509                        <span class="o">}</span>
510                        <span class="k">return</span> <span class="nx">ok</span><span class="o">;</span>
511                    <span class="o">}</span>
512
513                    <span class="k">if</span> <span class="o">(!</span><span class="nx">fn</span> <span class="o">||</span> <span class="o">!</span><span class="nx">fn</span><span class="o">.</span><span class="nx">call</span><span class="o">)</span> <span class="o">{</span>
514                        <span class="c">// Y.log(&quot;Error, function is not valid &quot; + fn);</span>
515<span class="c"></span>                        <span class="c">//return false;</span>
516<span class="c"></span>                        <span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="nx">purgeElement</span><span class="o">(</span><span class="nx">el</span><span class="o">,</span> <span class="kc">false</span><span class="o">,</span> <span class="nx">type</span><span class="o">);</span>
517                    <span class="o">}</span>
518
519
520                    <span class="k">var</span> <span class="nx">id</span> <span class="o">=</span> <span class="s1">&#39;event:&#39;</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="nx">el</span><span class="o">)</span> <span class="o">+</span> <span class="nx">type</span><span class="o">,</span> 
521                        <span class="nx">ce</span> <span class="o">=</span> <span class="nx">_wrappers</span><span class="o">[</span><span class="nx">id</span><span class="o">];</span>
522                    <span class="k">if</span> <span class="o">(</span><span class="nx">ce</span><span class="o">)</span> <span class="o">{</span>
523                        <span class="k">return</span> <span class="nx">ce</span><span class="o">.</span><span class="nx">unsubscribe</span><span class="o">(</span><span class="nx">fn</span><span class="o">);</span>
524                    <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
525                        <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
526                    <span class="o">}</span>
527
528                <span class="o">},</span>
529
530                <span class="c">/**</span>
531<span class="c">                 * Finds the event in the window object, the caller&#39;s arguments, or</span>
532<span class="c">                 * in the arguments of another method in the callstack.  This is</span>
533<span class="c">                 * executed automatically for events registered through the event</span>
534<span class="c">                 * manager, so the implementer should not normally need to execute</span>
535<span class="c">                 * this function at all.</span>
536<span class="c">                 * @method getEvent</span>
537<span class="c">                 * @param {Event} e the event parameter from the handler</span>
538<span class="c">                 * @param {HTMLElement} boundEl the element the listener is attached to</span>
539<span class="c">                 * @return {Event} the event </span>
540<span class="c">                 * @static</span>
541<span class="c">                 */</span>
542                <span class="nx">getEvent</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">e</span><span class="o">,</span> <span class="nx">boundEl</span><span class="o">)</span> <span class="o">{</span>
543                    <span class="k">var</span> <span class="nx">ev</span> <span class="o">=</span> <span class="nx">e</span> <span class="o">||</span> <span class="nb">window</span><span class="o">.</span><span class="nx">event</span><span class="o">;</span>
544
545                    <span class="k">if</span> <span class="o">(!</span><span class="nx">ev</span><span class="o">)</span> <span class="o">{</span>
546                        <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">getEvent</span><span class="o">.</span><span class="nx">caller</span><span class="o">;</span>
547                        <span class="k">while</span> <span class="o">(</span><span class="nx">c</span><span class="o">)</span> <span class="o">{</span>
548                            <span class="nx">ev</span> <span class="o">=</span> <span class="nx">c</span><span class="o">.</span><span class="nx">arguments</span><span class="o">[</span><span class="m">0</span><span class="o">];</span>
549                            <span class="k">if</span> <span class="o">(</span><span class="nx">ev</span> <span class="o">&amp;&amp;</span> <span class="nx">Event</span> <span class="o">==</span> <span class="nx">ev</span><span class="o">.</span><span class="nx">constructor</span><span class="o">)</span> <span class="o">{</span>
550                                <span class="k">break</span><span class="o">;</span>
551                            <span class="o">}</span>
552                            <span class="nx">c</span> <span class="o">=</span> <span class="nx">c</span><span class="o">.</span><span class="nx">caller</span><span class="o">;</span>
553                        <span class="o">}</span>
554                    <span class="o">}</span>
555
556                    <span class="c">// Y.log(&#39;wrapper for facade: &#39; + &#39;event:&#39; + Y.stamp(boundEl) + e.type);</span>
557<span class="c"></span>
558                    <span class="k">return</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="nx">ev</span><span class="o">,</span> <span class="nx">boundEl</span><span class="o">,</span> <span class="nx">_wrappers</span><span class="o">[</span><span class="s1">&#39;event:&#39;</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="nx">boundEl</span><span class="o">)</span> <span class="o">+</span> <span class="nx">e</span><span class="o">.</span><span class="nx">type</span><span class="o">]);</span>
559                <span class="o">},</span>
560
561
562                <span class="c">/**</span>
563<span class="c">                 * Generates an unique ID for the element if it does not already </span>
564<span class="c">                 * have one.</span>
565<span class="c">                 * @method generateId</span>
566<span class="c">                 * @param el the element to create the id for</span>
567<span class="c">                 * @return {string} the resulting id of the element</span>
568<span class="c">                 * @static</span>
569<span class="c">                 */</span>
570                <span class="nx">generateId</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">el</span><span class="o">)</span> <span class="o">{</span>
571                    <span class="k">var</span> <span class="nx">id</span> <span class="o">=</span> <span class="nx">el</span><span class="o">.</span><span class="nx">id</span><span class="o">;</span>
572
573                    <span class="k">if</span> <span class="o">(!</span><span class="nx">id</span><span class="o">)</span> <span class="o">{</span>
574                        <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="nx">el</span><span class="o">);</span>
575                        <span class="nx">el</span><span class="o">.</span><span class="nx">id</span> <span class="o">=</span> <span class="nx">id</span><span class="o">;</span>
576                    <span class="o">}</span>
577
578                    <span class="k">return</span> <span class="nx">id</span><span class="o">;</span>
579                <span class="o">},</span>
580
581
582                <span class="c">/**</span>
583<span class="c">                 * We want to be able to use getElementsByTagName as a collection</span>
584<span class="c">                 * to attach a group of events to.  Unfortunately, different </span>
585<span class="c">                 * browsers return different types of collections.  This function</span>
586<span class="c">                 * tests to determine if the object is array-like.  It will also </span>
587<span class="c">                 * fail if the object is an array, but is empty.</span>
588<span class="c">                 * @method _isValidCollection</span>
589<span class="c">                 * @param o the object to test</span>
590<span class="c">                 * @return {boolean} true if the object is array-like and populated</span>
591<span class="c">                 * @static</span>
592<span class="c">                 * @private</span>
593<span class="c">                 */</span>
594                <span class="nx">_isValidCollection</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="o">{</span>
595                    <span class="k">try</span> <span class="o">{</span>
596                        <span class="k">return</span> <span class="o">(</span> <span class="nx">o</span>                     <span class="o">&amp;&amp;</span> <span class="c">// o is something</span>
597<span class="c"></span>                                 <span class="k">typeof</span> <span class="nx">o</span> <span class="o">!==</span> <span class="s2">&quot;string&quot;</span> <span class="o">&amp;&amp;</span> <span class="c">// o is not a string</span>
598<span class="c"></span>                                 <span class="o">(</span><span class="nx">o</span><span class="o">.</span><span class="nx">each</span> <span class="o">||</span> <span class="nx">o</span><span class="o">.</span><span class="nx">length</span><span class="o">)</span>  <span class="o">&amp;&amp;</span> <span class="c">// o is indexed</span>
599<span class="c"></span>                                 <span class="o">!</span><span class="nx">o</span><span class="o">.</span><span class="nx">tagName</span>            <span class="o">&amp;&amp;</span> <span class="c">// o is not an HTML element</span>
600<span class="c"></span>                                 <span class="o">!</span><span class="nx">o</span><span class="o">.</span><span class="nx">alert</span>              <span class="o">&amp;&amp;</span> <span class="c">// o is not a window</span>
601<span class="c"></span>                                 <span class="o">(</span><span class="nx">o</span><span class="o">.</span><span class="nx">item</span> <span class="o">||</span> <span class="k">typeof</span> <span class="nx">o</span><span class="o">[</span><span class="m">0</span><span class="o">]</span> <span class="o">!==</span> <span class="s2">&quot;undefined&quot;</span><span class="o">)</span> <span class="o">);</span>
602                    <span class="o">}</span> <span class="k">catch</span><span class="o">(</span><span class="nx">ex</span><span class="o">)</span> <span class="o">{</span>
603                        <span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;collection check failure&quot;</span><span class="o">,</span> <span class="s2">&quot;warn&quot;</span><span class="o">,</span> <span class="s2">&quot;event&quot;</span><span class="o">);</span>
604                        <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
605                    <span class="o">}</span>
606
607                <span class="o">},</span>
608
609                <span class="c">/*</span>
610<span class="c">                 * Custom event the fires when the dom is initially usable</span>
611<span class="c">                 * @event DOMReadyEvent</span>
612<span class="c">                 */</span>
613                <span class="c">// DOMReadyEvent: new Y.CustomEvent(&quot;event:ready&quot;, this),</span>
614<span class="c"></span>                <span class="c">// DOMReadyEvent: Y.publish(&quot;event:ready&quot;, this, {</span>
615<span class="c"></span>                    <span class="c">// fireOnce: true</span>
616<span class="c"></span>                <span class="c">// }),</span>
617<span class="c"></span>
618                <span class="c">/**</span>
619<span class="c">                 * hook up any deferred listeners</span>
620<span class="c">                 * @method _load</span>
621<span class="c">                 * @static</span>
622<span class="c">                 * @private</span>
623<span class="c">                 */</span>
624                <span class="nx">_load</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">e</span><span class="o">)</span> <span class="o">{</span>
625
626                    <span class="k">if</span> <span class="o">(!</span><span class="nx">loadComplete</span><span class="o">)</span> <span class="o">{</span>
627
628                        <span class="c">// Y.log(&#39;Load Complete&#39;, &#39;info&#39;, &#39;event&#39;);</span>
629<span class="c"></span>
630                        <span class="nx">loadComplete</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
631
632                        <span class="c">// Just in case DOMReady did not go off for some reason</span>
633<span class="c"></span>                        <span class="c">// E._ready();</span>
634<span class="c"></span>                        <span class="k">if</span> <span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">fire</span><span class="o">)</span> <span class="o">{</span>
635                            <span class="nx">Y</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="s1">&#39;event:ready&#39;</span><span class="o">);</span>
636                        <span class="o">}</span>
637
638                        <span class="c">// Available elements may not have been detected before the</span>
639<span class="c"></span>                        <span class="c">// window load event fires. Try to find them now so that the</span>
640<span class="c"></span>                        <span class="c">// the user is more likely to get the onAvailable notifications</span>
641<span class="c"></span>                        <span class="c">// before the window load notification</span>
642<span class="c"></span>                        <span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">_tryPreloadAttach</span><span class="o">();</span>
643
644                    <span class="o">}</span>
645                <span class="o">},</span>
646
647                <span class="c">/**</span>
648<span class="c">                 * Polling function that runs before the onload event fires, </span>
649<span class="c">                 * attempting to attach to DOM Nodes as soon as they are </span>
650<span class="c">                 * available</span>
651<span class="c">                 * @method _tryPreloadAttach</span>
652<span class="c">                 * @static</span>
653<span class="c">                 * @private</span>
654<span class="c">                 */</span>
655                <span class="nx">_tryPreloadAttach</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
656
657                    <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">locked</span><span class="o">)</span> <span class="o">{</span>
658                        <span class="k">return</span><span class="o">;</span>
659                    <span class="o">}</span>
660
661                    <span class="k">if</span> <span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">UA</span><span class="o">.</span><span class="nx">ie</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">YUI</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">DOMReady</span><span class="o">)</span> <span class="o">{</span>
662                        <span class="c">// Hold off if DOMReady has not fired and check current</span>
663<span class="c"></span>                        <span class="c">// readyState to protect against the IE operation aborted</span>
664<span class="c"></span>                        <span class="c">// issue.</span>
665<span class="c"></span>                        <span class="k">this</span><span class="o">.</span><span class="nx">startInterval</span><span class="o">();</span>
666                        <span class="k">return</span><span class="o">;</span>
667                    <span class="o">}</span>
668
669                    <span class="k">this</span><span class="o">.</span><span class="nx">locked</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
670
671                    <span class="c">// Y.log.debug(&quot;tryPreloadAttach&quot;);</span>
672<span class="c"></span>
673                    <span class="c">// keep trying until after the page is loaded.  We need to </span>
674<span class="c"></span>                    <span class="c">// check the page load state prior to trying to bind the </span>
675<span class="c"></span>                    <span class="c">// elements so that we can be certain all elements have been </span>
676<span class="c"></span>                    <span class="c">// tested appropriately</span>
677<span class="c"></span>                    <span class="k">var</span> <span class="nx">tryAgain</span> <span class="o">=</span> <span class="o">!</span><span class="nx">loadComplete</span><span class="o">;</span>
678                    <span class="k">if</span> <span class="o">(!</span><span class="nx">tryAgain</span><span class="o">)</span> <span class="o">{</span>
679                        <span class="nx">tryAgain</span> <span class="o">=</span> <span class="o">(</span><span class="nx">_retryCount</span> <span class="o">&gt;</span> <span class="m">0</span><span class="o">);</span>
680                    <span class="o">}</span>
681
682                    <span class="c">// onAvailable</span>
683<span class="c"></span>                    <span class="k">var</span> <span class="nx">notAvail</span> <span class="o">=</span> <span class="o">[];</span>
684
685                    <span class="k">var</span> <span class="nx">executeItem</span> <span class="o">=</span> <span class="k">function</span> <span class="o">(</span><span class="nx">el</span><span class="o">,</span> <span class="nx">item</span><span class="o">)</span> <span class="o">{</span>
686                        <span class="k">var</span> <span class="nx">context</span><span class="o">;</span>
687                        <span class="k">if</span> <span class="o">(</span><span class="nx">item</span><span class="o">.</span><span class="nx">override</span><span class="o">)</span> <span class="o">{</span>
688                            <span class="k">if</span> <span class="o">(</span><span class="nx">item</span><span class="o">.</span><span class="nx">override</span> <span class="o">===</span> <span class="kc">true</span><span class="o">)</span> <span class="o">{</span>
689                                <span class="nx">context</span> <span class="o">=</span> <span class="nx">item</span><span class="o">.</span><span class="nx">obj</span><span class="o">;</span>
690                            <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
691                                <span class="nx">context</span> <span class="o">=</span> <span class="nx">item</span><span class="o">.</span><span class="nx">override</span><span class="o">;</span>
692                            <span class="o">}</span>
693                        <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
694                            <span class="nx">context</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">el</span><span class="o">);</span>
695                        <span class="o">}</span>
696                        <span class="nx">item</span><span class="o">.</span><span class="nx">fn</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="nx">context</span><span class="o">,</span> <span class="nx">item</span><span class="o">.</span><span class="nx">obj</span><span class="o">);</span>
697                    <span class="o">};</span>
698
699                    <span class="k">var</span> <span class="nx">i</span><span class="o">,</span><span class="nx">len</span><span class="o">,</span><span class="nx">item</span><span class="o">,</span><span class="nx">el</span><span class="o">;</span>
700
701                    <span class="c">// onAvailable</span>
702<span class="c"></span>                    <span class="k">for</span> <span class="o">(</span><span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">,</span><span class="nx">len</span><span class="o">=</span><span class="nx">_avail</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span><span class="o">&lt;</span><span class="nx">len</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
703                        <span class="nx">item</span> <span class="o">=</span> <span class="nx">_avail</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
704                        <span class="k">if</span> <span class="o">(</span><span class="nx">item</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">item</span><span class="o">.</span><span class="nx">checkReady</span><span class="o">)</span> <span class="o">{</span>
705                            <span class="nx">el</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">item</span><span class="o">.</span><span class="nx">id</span><span class="o">);</span>
706                            <span class="k">if</span> <span class="o">(</span><span class="nx">el</span><span class="o">)</span> <span class="o">{</span>
707                                <span class="nx">executeItem</span><span class="o">(</span><span class="nx">el</span><span class="o">,</span> <span class="nx">item</span><span class="o">);</span>
708                                <span class="nx">_avail</span><span class="o">[</span><span class="nx">i</span><span class="o">]</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
709                            <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
710                                <span class="nx">notAvail</span><span class="o">.</span><span class="nx">push</span><span class="o">(</span><span class="nx">item</span><span class="o">);</span>
711                            <span class="o">}</span>
712                        <span class="o">}</span>
713                    <span class="o">}</span>
714
715                    <span class="c">// onContentReady</span>
716<span class="c"></span>                    <span class="k">for</span> <span class="o">(</span><span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">,</span><span class="nx">len</span><span class="o">=</span><span class="nx">_avail</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span><span class="o">&lt;</span><span class="nx">len</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
717                        <span class="nx">item</span> <span class="o">=</span> <span class="nx">_avail</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
718                        <span class="k">if</span> <span class="o">(</span><span class="nx">item</span> <span class="o">&amp;&amp;</span> <span class="nx">item</span><span class="o">.</span><span class="nx">checkReady</span><span class="o">)</span> <span class="o">{</span>
719                            <span class="nx">el</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">item</span><span class="o">.</span><span class="nx">id</span><span class="o">);</span>
720
721                            <span class="k">if</span> <span class="o">(</span><span class="nx">el</span><span class="o">)</span> <span class="o">{</span>
722                                <span class="c">// The element is available, but not necessarily ready</span>
723<span class="c"></span>                                <span class="c">// @todo should we test parentNode.nextSibling?</span>
724<span class="c"></span>                                <span class="k">if</span> <span class="o">(</span><span class="nx">loadComplete</span> <span class="o">||</span> <span class="nx">el</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="s1">&#39;nextSibling&#39;</span><span class="o">))</span> <span class="o">{</span>
725                                    <span class="nx">executeItem</span><span class="o">(</span><span class="nx">el</span><span class="o">,</span> <span class="nx">item</span><span class="o">);</span>
726                                    <span class="nx">_avail</span><span class="o">[</span><span class="nx">i</span><span class="o">]</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
727                                <span class="o">}</span>
728                            <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
729                                <span class="nx">notAvail</span><span class="o">.</span><span class="nx">push</span><span class="o">(</span><span class="nx">item</span><span class="o">);</span>
730                            <span class="o">}</span>
731                        <span class="o">}</span>
732                    <span class="o">}</span>
733
734                    <span class="nx">_retryCount</span> <span class="o">=</span> <span class="o">(</span><span class="nx">notAvail</span><span class="o">.</span><span class="nx">length</span> <span class="o">===</span> <span class="m">0</span><span class="o">)</span> <span class="o">?</span> <span class="m">0</span> <span class="o">:</span> <span class="nx">_retryCount</span> <span class="o">-</span> <span class="m">1</span><span class="o">;</span>
735
736                    <span class="k">if</span> <span class="o">(</span><span class="nx">tryAgain</span><span class="o">)</span> <span class="o">{</span>
737                        <span class="c">// we may need to strip the nulled out items here</span>
738<span class="c"></span>                        <span class="k">this</span><span class="o">.</span><span class="nx">startInterval</span><span class="o">();</span>
739                    <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
740                        <span class="nx">clearInterval</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_interval</span><span class="o">);</span>
741                        <span class="k">this</span><span class="o">.</span><span class="nx">_interval</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
742                    <span class="o">}</span>
743
744                    <span class="k">this</span><span class="o">.</span><span class="nx">locked</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>
745
746                    <span class="k">return</span><span class="o">;</span>
747
748                <span class="o">},</span>
749
750                <span class="c">/**</span>
751<span class="c">                 * Removes all listeners attached to the given element via addListener.</span>
752<span class="c">                 * Optionally, the node&#39;s children can also be purged.</span>
753<span class="c">                 * Optionally, you can specify a specific type of event to remove.</span>
754<span class="c">                 * @method purgeElement</span>
755<span class="c">                 * @param {HTMLElement} el the element to purge</span>
756<span class="c">                 * @param {boolean} recurse recursively purge this element&#39;s children</span>
757<span class="c">                 * as well.  Use with caution.</span>
758<span class="c">                 * @param {string} type optional type of listener to purge. If</span>
759<span class="c">                 * left out, all listeners will be removed</span>
760<span class="c">                 * @static</span>
761<span class="c">                 */</span>
762                <span class="nx">purgeElement</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">el</span><span class="o">,</span> <span class="nx">recurse</span><span class="o">,</span> <span class="nx">type</span><span class="o">)</span> <span class="o">{</span>
763                    <span class="k">var</span> <span class="nx">oEl</span> <span class="o">=</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">isString</span><span class="o">(</span><span class="nx">el</span><span class="o">))</span> <span class="o">?</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">el</span><span class="o">)</span> <span class="o">:</span> <span class="nx">el</span><span class="o">,</span>
764                        <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="nx">oEl</span><span class="o">);</span>
765                    <span class="k">var</span> <span class="nx">lis</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">getListeners</span><span class="o">(</span><span class="nx">oEl</span><span class="o">,</span> <span class="nx">type</span><span class="o">),</span> <span class="nx">i</span><span class="o">,</span> <span class="nx">len</span><span class="o">;</span>
766                    <span class="k">if</span> <span class="o">(</span><span class="nx">lis</span><span class="o">)</span> <span class="o">{</span>
767                        <span class="k">for</span> <span class="o">(</span><span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">,</span><span class="nx">len</span><span class="o">=</span><span class="nx">lis</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span><span class="o">&lt;</span><span class="nx">len</span> <span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
768                            <span class="nx">lis</span><span class="o">[</span><span class="nx">i</span><span class="o">].</span><span class="nx">unsubscribeAll</span><span class="o">();</span>
769                        <span class="o">}</span>
770                    <span class="o">}</span>
771
772                    <span class="k">if</span> <span class="o">(</span><span class="nx">recurse</span> <span class="o">&amp;&amp;</span> <span class="nx">oEl</span> <span class="o">&amp;&amp;</span> <span class="nx">oEl</span><span class="o">.</span><span class="nx">childNodes</span><span class="o">)</span> <span class="o">{</span>
773                        <span class="k">for</span> <span class="o">(</span><span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">,</span><span class="nx">len</span><span class="o">=</span><span class="nx">oEl</span><span class="o">.</span><span class="nx">childNodes</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span><span class="o">&lt;</span><span class="nx">len</span> <span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
774                            <span class="k">this</span><span class="o">.</span><span class="nx">purgeElement</span><span class="o">(</span><span class="nx">oEl</span><span class="o">.</span><span class="nx">childNodes</span><span class="o">[</span><span class="nx">i</span><span class="o">],</span> <span class="nx">recurse</span><span class="o">,</span> <span class="nx">type</span><span class="o">);</span>
775                        <span class="o">}</span>
776                    <span class="o">}</span>
777                <span class="o">},</span>
778
779                <span class="c">/**</span>
780<span class="c">                 * Returns all listeners attached to the given element via addListener.</span>
781<span class="c">                 * Optionally, you can specify a specific type of event to return.</span>
782<span class="c">                 * @method getListeners</span>
783<span class="c">                 * @param el {HTMLElement|string} the element or element id to inspect </span>
784<span class="c">                 * @param type {string} optional type of listener to return. If</span>
785<span class="c">                 * left out, all listeners will be returned</span>
786<span class="c">                 * @return {Y.Custom.Event} the custom event wrapper for the DOM event(s)</span>
787<span class="c">                 * @static</span>
788<span class="c">                 */</span>           
789                <span class="nx">getListeners</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">el</span><span class="o">,</span> <span class="nx">type</span><span class="o">)</span> <span class="o">{</span>
790                    <span class="k">var</span> <span class="nx">results</span><span class="o">=[],</span> <span class="nx">ek</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="nx">el</span><span class="o">),</span> <span class="nx">key</span> <span class="o">=</span> <span class="o">(</span><span class="nx">type</span><span class="o">)</span> <span class="o">?</span> <span class="s1">&#39;event:&#39;</span> <span class="o">+</span> <span class="nx">type</span> <span class="o">:</span> <span class="kc">null</span><span class="o">,</span>
791                        <span class="nx">evts</span> <span class="o">=</span> <span class="nx">_el_events</span><span class="o">[</span><span class="nx">ek</span><span class="o">];</span>
792
793                    <span class="k">if</span> <span class="o">(</span><span class="nx">key</span><span class="o">)</span> <span class="o">{</span>
794                        <span class="k">if</span> <span class="o">(</span><span class="nx">evts</span><span class="o">[</span><span class="nx">key</span><span class="o">])</span> <span class="o">{</span>
795                            <span class="nx">results</span><span class="o">.</span><span class="nx">push</span><span class="o">(</span><span class="nx">evts</span><span class="o">[</span><span class="nx">key</span><span class="o">]);</span>
796                        <span class="o">}</span>
797                    <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
798                        <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">evts</span><span class="o">)</span> <span class="o">{</span>
799                            <span class="nx">results</span><span class="o">.</span><span class="nx">push</span><span class="o">(</span><span class="nx">evts</span><span class="o">[</span><span class="nx">i</span><span class="o">]);</span>
800                        <span class="o">}</span>
801                    <span class="o">}</span>
802
803                    <span class="k">return</span> <span class="o">(</span><span class="nx">results</span><span class="o">.</span><span class="nx">length</span><span class="o">)</span> <span class="o">?</span> <span class="nx">results</span> <span class="o">:</span> <span class="kc">null</span><span class="o">;</span>
804                <span class="o">},</span>
805
806                <span class="c">/**</span>
807<span class="c">                 * Removes all listeners registered by pe.event.  Called </span>
808<span class="c">                 * automatically during the unload event.</span>
809<span class="c">                 * @method _unload</span>
810<span class="c">                 * @static</span>
811<span class="c">                 * @private</span>
812<span class="c">                 */</span>
813                <span class="nx">_unload</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">e</span><span class="o">)</span> <span class="o">{</span>
814
815                    <span class="k">var</span> <span class="nx">E</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">,</span> <span class="nx">i</span><span class="o">,</span> <span class="nx">w</span><span class="o">;</span>
816
817                    <span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="k">in</span> <span class="nx">_wrappers</span><span class="o">)</span> <span class="o">{</span>
818                        <span class="nx">w</span> <span class="o">=</span> <span class="nx">_wrappers</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
819                        <span class="nx">w</span><span class="o">.</span><span class="nx">unsubscribeAll</span><span class="o">();</span>
820                        <span class="nx">E</span><span class="o">.</span><span class="nx">nativeRemove</span><span class="o">(</span><span class="nx">w</span><span class="o">.</span><span class="nx">el</span><span class="o">,</span> <span class="nx">w</span><span class="o">.</span><span class="nx">type</span><span class="o">,</span> <span class="nx">w</span><span class="o">.</span><span class="nx">fn</span><span class="o">);</span>
821                        <span class="nx">delete</span> <span class="nx">_wrappers</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
822                    <span class="o">}</span>
823
824                    <span class="nx">E</span><span class="o">.</span><span class="nx">nativeRemove</span><span class="o">(</span><span class="nb">window</span><span class="o">,</span> <span class="s2">&quot;unload&quot;</span><span class="o">,</span> <span class="nx">E</span><span class="o">.</span><span class="nx">_unload</span><span class="o">);</span>
825                <span class="o">},</span>
826
827               
828                <span class="c">/**</span>
829<span class="c">                 * Adds a DOM event directly without the caching, cleanup, context adj, etc</span>
830<span class="c">                 *</span>
831<span class="c">                 * @method nativeAdd</span>
832<span class="c">                 * @param {HTMLElement} el      the element to bind the handler to</span>
833<span class="c">                 * @param {string}      type   the type of event handler</span>
834<span class="c">                 * @param {function}    fn      the callback to invoke</span>
835<span class="c">                 * @param {boolen}      capture capture or bubble phase</span>
836<span class="c">                 * @static</span>
837<span class="c">                 * @private</span>
838<span class="c">                 */</span>
839                <span class="nx">nativeAdd</span><span class="o">:</span> <span class="nx">add</span><span class="o">,</span>
840
841                <span class="c">/**</span>
842<span class="c">                 * Basic remove listener</span>
843<span class="c">                 *</span>
844<span class="c">                 * @method nativeRemove</span>
845<span class="c">                 * @param {HTMLElement} el      the element to bind the handler to</span>
846<span class="c">                 * @param {string}      type   the type of event handler</span>
847<span class="c">                 * @param {function}    fn      the callback to invoke</span>
848<span class="c">                 * @param {boolen}      capture capture or bubble phase</span>
849<span class="c">                 * @static</span>
850<span class="c">                 * @private</span>
851<span class="c">                 */</span>
852                <span class="nx">nativeRemove</span><span class="o">:</span> <span class="nx">remove</span>
853            <span class="o">};</span>
854
855        <span class="o">}();</span>
856
857        <span class="k">var</span> <span class="nx">E</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">;</span>
858
859        <span class="c">// Process onAvailable/onContentReady items when when the DOM is ready in IE</span>
860<span class="c"></span>        <span class="k">if</span> <span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">UA</span><span class="o">.</span><span class="nx">ie</span> <span class="o">&amp;&amp;</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">on</span><span class="o">)</span> <span class="o">{</span>
861            <span class="nx">Y</span><span class="o">.</span><span class="nx">on</span><span class="o">(</span><span class="s1">&#39;event:ready&#39;</span><span class="o">,</span> <span class="nx">E</span><span class="o">.</span><span class="nx">_tryPreloadAttach</span><span class="o">,</span> <span class="nx">E</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>
862        <span class="o">}</span>
863
864        <span class="nx">E</span><span class="o">.</span><span class="nx">Custom</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">;</span>
865        <span class="nx">E</span><span class="o">.</span><span class="nx">Subscriber</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Subscriber</span><span class="o">;</span>
866        <span class="nx">E</span><span class="o">.</span><span class="nx">Target</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">EventTarget</span><span class="o">;</span>
867
868        <span class="c">/**</span>
869<span class="c">         * Y.Event.on is an alias for addListener</span>
870<span class="c">         * @method on</span>
871<span class="c">         * @see addListener</span>
872<span class="c">         * @static</span>
873<span class="c">         */</span>
874        <span class="nx">E</span><span class="o">.</span><span class="nx">attach</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">fn</span><span class="o">,</span> <span class="nx">el</span><span class="o">,</span> <span class="nx">data</span><span class="o">,</span> <span class="nx">context</span><span class="o">)</span> <span class="o">{</span>
875            <span class="k">var</span> <span class="nx">a</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>
876                <span class="nx">oEl</span> <span class="o">=</span> <span class="nx">a</span><span class="o">.</span><span class="nx">splice</span><span class="o">(</span><span class="m">2</span><span class="o">,</span> <span class="m">1</span><span class="o">);</span>
877            <span class="nx">a</span><span class="o">.</span><span class="nx">unshift</span><span class="o">(</span><span class="nx">oEl</span><span class="o">[</span><span class="m">0</span><span class="o">]);</span>
878            <span class="k">return</span> <span class="nx">E</span><span class="o">.</span><span class="nx">addListener</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="nx">E</span><span class="o">,</span> <span class="nx">a</span><span class="o">);</span>
879        <span class="o">};</span>
880
881        <span class="nx">E</span><span class="o">.</span><span class="nx">detach</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">fn</span><span class="o">,</span> <span class="nx">el</span><span class="o">,</span> <span class="nx">data</span><span class="o">,</span> <span class="nx">context</span><span class="o">)</span> <span class="o">{</span>
882            <span class="k">return</span> <span class="nx">E</span><span class="o">.</span><span class="nx">removeListener</span><span class="o">(</span><span class="nx">el</span><span class="o">,</span> <span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">,</span> <span class="nx">data</span><span class="o">,</span> <span class="nx">context</span><span class="o">);</span>
883        <span class="o">};</span>
884
885        <span class="nx">E</span><span class="o">.</span><span class="nx">attach</span><span class="o">(</span><span class="s2">&quot;load&quot;</span><span class="o">,</span> <span class="nx">E</span><span class="o">.</span><span class="nx">_load</span><span class="o">,</span> <span class="nb">window</span><span class="o">,</span> <span class="nx">E</span><span class="o">);</span>
886        <span class="nx">E</span><span class="o">.</span><span class="nx">nativeAdd</span><span class="o">(</span><span class="nb">window</span><span class="o">,</span> <span class="s2">&quot;unload&quot;</span><span class="o">,</span> <span class="nx">E</span><span class="o">.</span><span class="nx">_unload</span><span class="o">);</span>
887
888        <span class="nx">E</span><span class="o">.</span><span class="nx">_tryPreloadAttach</span><span class="o">();</span>
889
890<span class="o">},</span> <span class="s2">&quot;3.0.0&quot;</span><span class="o">);</span>
891
892<span class="o">})();</span>
893</pre></div>
894                    </div>
895                        </div>
896                </div>
897                <div class="yui-b">
898            <div class="nav">
899
900                    <div class="module">
901                        <h4>Modules</h4>
902                        <ul class="content">
903
904                                <li class=""><a href="module_anim.html">anim</a></li>
905
906                                <li class=""><a href="module_attribute.html">attribute</a></li>
907
908                                <li class=""><a href="module_base.html">base</a></li>
909
910                                <li class=""><a href="module_cookie.html">cookie</a></li>
911
912                                <li class=""><a href="module_dd.html">dd</a></li>
913
914                                <li class=""><a href="module_dd-plugin.html">dd-plugin</a></li>
915
916                                <li class=""><a href="module_dom.html">dom</a></li>
917
918                                <li class=""><a href="module_dump.html">dump</a></li>
919
920                                <li class="selected"><a href="module_event.html">event</a></li>
921
922                                <li class=""><a href="module_io.html">io</a></li>
923
924                                <li class=""><a href="module_json.html">json</a></li>
925
926                                <li class=""><a href="module_node.html">node</a></li>
927
928                                <li class=""><a href="module_oop.html">oop</a></li>
929
930                                <li class=""><a href="module_queue.html">queue</a></li>
931
932                                <li class=""><a href="module_substitute.html">substitute</a></li>
933
934                                <li class=""><a href="module_yui.html">yui</a></li>
935                        </ul>
936                    </div>
937
938                    <div class="module">
939                        <h4>Classes</h4>
940                        <ul class="content">
941                                <li class=""><a href="Do.html">Do</a></li>
942                                <li class=""><a href="Do.AlterArgs.html">Do.AlterArgs</a></li>
943                                <li class=""><a href="Do.AlterReturn.html">Do.AlterReturn</a></li>
944                                <li class=""><a href="Do.Error.html">Do.Error</a></li>
945                                <li class=""><a href="Do.Method.html">Do.Method</a></li>
946                                <li class=""><a href="Event.html">Event</a></li>
947                                <li class=""><a href="Event.Custom.html">Event.Custom</a></li>
948                                <li class=""><a href="Event.Facade.html">Event.Facade</a></li>
949                                <li class=""><a href="Event.Handle.html">Event.Handle</a></li>
950                                <li class=""><a href="Event.Subscriber.html">Event.Subscriber</a></li>
951                                <li class=""><a href="Event.Target.html">Event.Target</a></li>
952                        </ul>
953                    </div>
954
955                    <div class="module">
956                        <h4>Files</h4>
957                        <ul class="content">       
958                                <li class=""><a href="event-custom.js.html">event-custom.js</a></li>
959                                <li class=""><a href="event-do.js.html">event-do.js</a></li>
960                                <li class="selected"><a href="event-dom.js.html">event-dom.js</a></li>
961                                <li class=""><a href="event-facade.js.html">event-facade.js</a></li>
962                                <li class=""><a href="event-ready.js.html">event-ready.js</a></li>
963                                <li class=""><a href="event-target.js.html">event-target.js</a></li>
964                                <li class=""><a href="event.js.html">event.js</a></li>
965                        </ul>
966                    </div>
967
968
969
970
971
972            </div>
973                </div>
974        </div>
975        <div id="ft">
976        <hr />
977        Copyright &copy; 2008 Yahoo! Inc. All rights reserved.
978        </div>
979</div>
980</body>
981</html>
Note: See TracBrowser for help on using the repository browser.