Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / Element.html
1 <html>\r
2 <head>\r
3   <title>The source code</title>\r
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js">/**\r
9  * @class Ext.Element\r
10  * <p>Encapsulates a DOM element, adding simple DOM manipulation facilities, normalizing for browser differences.</p>\r
11  * <p>All instances of this class inherit the methods of {@link Ext.Fx} making visual effects easily available to all DOM elements.</p>\r
12  * <p>Note that the events documented in this class are not Ext events, they encapsulate browser events. To\r
13  * access the underlying browser event, see {@link Ext.EventObject#browserEvent}. Some older\r
14  * browsers may not support the full range of events. Which events are supported is beyond the control of ExtJs.</p>\r
15  * Usage:<br>\r
16 <pre><code>\r
17 // by id\r
18 var el = Ext.get("my-div");\r
19 \r
20 // by DOM element reference\r
21 var el = Ext.get(myDivElement);\r
22 </code></pre>\r
23  * <b>Animations</b><br />\r
24  * <p>When an element is manipulated, by default there is no animation.</p>\r
25  * <pre><code>\r
26 var el = Ext.get("my-div");\r
27 \r
28 // no animation\r
29 el.setWidth(100);\r
30  * </code></pre>\r
31  * <p>Many of the functions for manipulating an element have an optional "animate" parameter.  This\r
32  * parameter can be specified as boolean (<tt>true</tt>) for default animation effects.</p>\r
33  * <pre><code>\r
34 // default animation\r
35 el.setWidth(100, true);\r
36  * </code></pre>\r
37  * \r
38  * <p>To configure the effects, an object literal with animation options to use as the Element animation\r
39  * configuration object can also be specified. Note that the supported Element animation configuration\r
40  * options are a subset of the {@link Ext.Fx} animation options specific to Fx effects.  The supported\r
41  * Element animation configuration options are:</p>\r
42 <pre>\r
43 Option    Default   Description\r
44 --------- --------  ---------------------------------------------\r
45 {@link Ext.Fx#duration duration}  .35       The duration of the animation in seconds\r
46 {@link Ext.Fx#easing easing}    easeOut   The easing method\r
47 {@link Ext.Fx#callback callback}  none      A function to execute when the anim completes\r
48 {@link Ext.Fx#scope scope}     this      The scope (this) of the callback function\r
49 </pre>\r
50  * \r
51  * <pre><code>\r
52 // Element animation options object\r
53 var opt = {\r
54     {@link Ext.Fx#duration duration}: 1,\r
55     {@link Ext.Fx#easing easing}: 'elasticIn',\r
56     {@link Ext.Fx#callback callback}: this.foo,\r
57     {@link Ext.Fx#scope scope}: this\r
58 };\r
59 // animation with some options set\r
60 el.setWidth(100, opt);\r
61  * </code></pre>\r
62  * <p>The Element animation object being used for the animation will be set on the options\r
63  * object as "anim", which allows you to stop or manipulate the animation. Here is an example:</p>\r
64  * <pre><code>\r
65 // using the "anim" property to get the Anim object\r
66 if(opt.anim.isAnimated()){\r
67     opt.anim.stop();\r
68 }\r
69  * </code></pre>\r
70  * <p>Also see the <tt>{@link #animate}</tt> method for another animation technique.</p>\r
71  * <p><b> Composite (Collections of) Elements</b></p>\r
72  * <p>For working with collections of Elements, see {@link Ext.CompositeElement}</p>\r
73  * @constructor Create a new Element directly.\r
74  * @param {String/HTMLElement} element\r
75  * @param {Boolean} forceNew (optional) By default the constructor checks to see if there is already an instance of this element in the cache and if there is it returns the same instance. This will skip that check (useful for extending this class).\r
76  */\r
77 (function(){\r
78 var DOC = document;\r
79 \r
80 Ext.Element = function(element, forceNew){\r
81     var dom = typeof element == "string" ?\r
82               DOC.getElementById(element) : element,\r
83         id;\r
84 \r
85     if(!dom) return null;\r
86 \r
87     id = dom.id;\r
88 \r
89     if(!forceNew && id && Ext.Element.cache[id]){ // element object already exists\r
90         return Ext.Element.cache[id];\r
91     }\r
92 \r
93     <div id="prop-Ext.Element-dom"></div>/**\r
94      * The DOM element\r
95      * @type HTMLElement\r
96      */\r
97     this.dom = dom;\r
98 \r
99     <div id="prop-Ext.Element-id"></div>/**\r
100      * The DOM element ID\r
101      * @type String\r
102      */\r
103     this.id = id || Ext.id(dom);\r
104 };\r
105 \r
106 var D = Ext.lib.Dom,\r
107     DH = Ext.DomHelper,\r
108     E = Ext.lib.Event,\r
109     A = Ext.lib.Anim,\r
110     El = Ext.Element;\r
111 \r
112 El.prototype = {\r
113     <div id="method-Ext.Element-set"></div>/**\r
114      * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)\r
115      * @param {Object} o The object with the attributes\r
116      * @param {Boolean} useSet (optional) false to override the default setAttribute to use expandos.\r
117      * @return {Ext.Element} this\r
118      */\r
119     set : function(o, useSet){\r
120         var el = this.dom,\r
121             attr,\r
122             val;        \r
123        \r
124         for(attr in o){\r
125             val = o[attr];\r
126             if (attr != "style" && !Ext.isFunction(val)) {\r
127                 if (attr == "cls" ) {\r
128                     el.className = val;\r
129                 } else if (o.hasOwnProperty(attr)) {\r
130                     if (useSet || !!el.setAttribute) el.setAttribute(attr, val);\r
131                     else el[attr] = val;\r
132                 }\r
133             }\r
134         }\r
135         if(o.style){\r
136             Ext.DomHelper.applyStyles(el, o.style);\r
137         }\r
138         return this;\r
139     },\r
140     \r
141 //  Mouse events\r
142     <div id="event-Ext.Element-click"></div>/**\r
143      * @event click\r
144      * Fires when a mouse click is detected within the element.\r
145      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
146      * @param {HtmlElement} t The target of the event.\r
147      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
148      */\r
149     <div id="event-Ext.Element-dblclick"></div>/**\r
150      * @event dblclick\r
151      * Fires when a mouse double click is detected within the element.\r
152      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
153      * @param {HtmlElement} t The target of the event.\r
154      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
155      */\r
156     <div id="event-Ext.Element-mousedown"></div>/**\r
157      * @event mousedown\r
158      * Fires when a mousedown is detected within the element.\r
159      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
160      * @param {HtmlElement} t The target of the event.\r
161      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
162      */\r
163     <div id="event-Ext.Element-mouseup"></div>/**\r
164      * @event mouseup\r
165      * Fires when a mouseup is detected within the element.\r
166      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
167      * @param {HtmlElement} t The target of the event.\r
168      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
169      */\r
170     <div id="event-Ext.Element-mouseover"></div>/**\r
171      * @event mouseover\r
172      * Fires when a mouseover is detected within the element.\r
173      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
174      * @param {HtmlElement} t The target of the event.\r
175      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
176      */\r
177     <div id="event-Ext.Element-mousemove"></div>/**\r
178      * @event mousemove\r
179      * Fires when a mousemove is detected with the element.\r
180      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
181      * @param {HtmlElement} t The target of the event.\r
182      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
183      */\r
184     <div id="event-Ext.Element-mouseout"></div>/**\r
185      * @event mouseout\r
186      * Fires when a mouseout is detected with the element.\r
187      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
188      * @param {HtmlElement} t The target of the event.\r
189      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
190      */\r
191     <div id="event-Ext.Element-mouseenter"></div>/**\r
192      * @event mouseenter\r
193      * Fires when the mouse enters the element.\r
194      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
195      * @param {HtmlElement} t The target of the event.\r
196      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
197      */\r
198     <div id="event-Ext.Element-mouseleave"></div>/**\r
199      * @event mouseleave\r
200      * Fires when the mouse leaves the element.\r
201      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
202      * @param {HtmlElement} t The target of the event.\r
203      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
204      */\r
205     \r
206 //  Keyboard events\r
207     <div id="event-Ext.Element-keypress"></div>/**\r
208      * @event keypress\r
209      * Fires when a keypress is detected within the element.\r
210      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
211      * @param {HtmlElement} t The target of the event.\r
212      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
213      */\r
214     <div id="event-Ext.Element-keydown"></div>/**\r
215      * @event keydown\r
216      * Fires when a keydown is detected within the element.\r
217      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
218      * @param {HtmlElement} t The target of the event.\r
219      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
220      */\r
221     <div id="event-Ext.Element-keyup"></div>/**\r
222      * @event keyup\r
223      * Fires when a keyup is detected within the element.\r
224      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
225      * @param {HtmlElement} t The target of the event.\r
226      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
227      */\r
228 \r
229 \r
230 //  HTML frame/object events\r
231     <div id="event-Ext.Element-load"></div>/**\r
232      * @event load\r
233      * Fires when the user agent finishes loading all content within the element. Only supported by window, frames, objects and images.\r
234      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
235      * @param {HtmlElement} t The target of the event.\r
236      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
237      */\r
238     <div id="event-Ext.Element-unload"></div>/**\r
239      * @event unload\r
240      * Fires when the user agent removes all content from a window or frame. For elements, it fires when the target element or any of its content has been removed.\r
241      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
242      * @param {HtmlElement} t The target of the event.\r
243      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
244      */\r
245     <div id="event-Ext.Element-abort"></div>/**\r
246      * @event abort\r
247      * Fires when an object/image is stopped from loading before completely loaded.\r
248      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
249      * @param {HtmlElement} t The target of the event.\r
250      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
251      */\r
252     <div id="event-Ext.Element-error"></div>/**\r
253      * @event error\r
254      * Fires when an object/image/frame cannot be loaded properly.\r
255      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
256      * @param {HtmlElement} t The target of the event.\r
257      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
258      */\r
259     <div id="event-Ext.Element-resize"></div>/**\r
260      * @event resize\r
261      * Fires when a document view is resized.\r
262      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
263      * @param {HtmlElement} t The target of the event.\r
264      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
265      */\r
266     <div id="event-Ext.Element-scroll"></div>/**\r
267      * @event scroll\r
268      * Fires when a document view is scrolled.\r
269      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
270      * @param {HtmlElement} t The target of the event.\r
271      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
272      */\r
273 \r
274 //  Form events\r
275     <div id="event-Ext.Element-select"></div>/**\r
276      * @event select\r
277      * Fires when a user selects some text in a text field, including input and textarea.\r
278      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
279      * @param {HtmlElement} t The target of the event.\r
280      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
281      */\r
282     <div id="event-Ext.Element-change"></div>/**\r
283      * @event change\r
284      * Fires when a control loses the input focus and its value has been modified since gaining focus.\r
285      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
286      * @param {HtmlElement} t The target of the event.\r
287      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
288      */\r
289     <div id="event-Ext.Element-submit"></div>/**\r
290      * @event submit\r
291      * Fires when a form is submitted.\r
292      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
293      * @param {HtmlElement} t The target of the event.\r
294      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
295      */\r
296     <div id="event-Ext.Element-reset"></div>/**\r
297      * @event reset\r
298      * Fires when a form is reset.\r
299      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
300      * @param {HtmlElement} t The target of the event.\r
301      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
302      */\r
303     <div id="event-Ext.Element-focus"></div>/**\r
304      * @event focus\r
305      * Fires when an element receives focus either via the pointing device or by tab navigation.\r
306      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
307      * @param {HtmlElement} t The target of the event.\r
308      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
309      */\r
310     <div id="event-Ext.Element-blur"></div>/**\r
311      * @event blur\r
312      * Fires when an element loses focus either via the pointing device or by tabbing navigation.\r
313      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
314      * @param {HtmlElement} t The target of the event.\r
315      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
316      */\r
317 \r
318 //  User Interface events\r
319     <div id="event-Ext.Element-DOMFocusIn"></div>/**\r
320      * @event DOMFocusIn\r
321      * Where supported. Similar to HTML focus event, but can be applied to any focusable element.\r
322      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
323      * @param {HtmlElement} t The target of the event.\r
324      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
325      */\r
326     <div id="event-Ext.Element-DOMFocusOut"></div>/**\r
327      * @event DOMFocusOut\r
328      * Where supported. Similar to HTML blur event, but can be applied to any focusable element.\r
329      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
330      * @param {HtmlElement} t The target of the event.\r
331      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
332      */\r
333     <div id="event-Ext.Element-DOMActivate"></div>/**\r
334      * @event DOMActivate\r
335      * Where supported. Fires when an element is activated, for instance, through a mouse click or a keypress.\r
336      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
337      * @param {HtmlElement} t The target of the event.\r
338      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
339      */\r
340 \r
341 //  DOM Mutation events\r
342     <div id="event-Ext.Element-DOMSubtreeModified"></div>/**\r
343      * @event DOMSubtreeModified\r
344      * Where supported. Fires when the subtree is modified.\r
345      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
346      * @param {HtmlElement} t The target of the event.\r
347      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
348      */\r
349     <div id="event-Ext.Element-DOMNodeInserted"></div>/**\r
350      * @event DOMNodeInserted\r
351      * Where supported. Fires when a node has been added as a child of another node.\r
352      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
353      * @param {HtmlElement} t The target of the event.\r
354      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
355      */\r
356     <div id="event-Ext.Element-DOMNodeRemoved"></div>/**\r
357      * @event DOMNodeRemoved\r
358      * Where supported. Fires when a descendant node of the element is removed.\r
359      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
360      * @param {HtmlElement} t The target of the event.\r
361      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
362      */\r
363     <div id="event-Ext.Element-DOMNodeRemovedFromDocument"></div>/**\r
364      * @event DOMNodeRemovedFromDocument\r
365      * Where supported. Fires when a node is being removed from a document.\r
366      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
367      * @param {HtmlElement} t The target of the event.\r
368      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
369      */\r
370     <div id="event-Ext.Element-DOMNodeInsertedIntoDocument"></div>/**\r
371      * @event DOMNodeInsertedIntoDocument\r
372      * Where supported. Fires when a node is being inserted into a document.\r
373      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
374      * @param {HtmlElement} t The target of the event.\r
375      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
376      */\r
377     <div id="event-Ext.Element-DOMAttrModified"></div>/**\r
378      * @event DOMAttrModified\r
379      * Where supported. Fires when an attribute has been modified.\r
380      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
381      * @param {HtmlElement} t The target of the event.\r
382      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
383      */\r
384     <div id="event-Ext.Element-DOMCharacterDataModified"></div>/**\r
385      * @event DOMCharacterDataModified\r
386      * Where supported. Fires when the character data has been modified.\r
387      * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.\r
388      * @param {HtmlElement} t The target of the event.\r
389      * @param {Object} o The options configuration passed to the {@link #addListener} call.\r
390      */\r
391 \r
392     <div id="prop-Ext.Element-defaultUnit"></div>/**\r
393      * The default unit to append to CSS values where a unit isn't provided (defaults to px).\r
394      * @type String\r
395      */\r
396     defaultUnit : "px",\r
397 \r
398     <div id="method-Ext.Element-is"></div>/**\r
399      * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)\r
400      * @param {String} selector The simple selector to test\r
401      * @return {Boolean} True if this element matches the selector, else false\r
402      */\r
403     is : function(simpleSelector){\r
404         return Ext.DomQuery.is(this.dom, simpleSelector);\r
405     },\r
406 \r
407     <div id="method-Ext.Element-focus"></div>/**\r
408      * Tries to focus the element. Any exceptions are caught and ignored.\r
409      * @param {Number} defer (optional) Milliseconds to defer the focus\r
410      * @return {Ext.Element} this\r
411      */\r
412     focus : function(defer, /* private */ dom) {\r
413         var me = this,\r
414             dom = dom || me.dom;\r
415         try{\r
416             if(Number(defer)){\r
417                 me.focus.defer(defer, null, [null, dom]);\r
418             }else{\r
419                 dom.focus();\r
420             }\r
421         }catch(e){}\r
422         return me;\r
423     },\r
424 \r
425     <div id="method-Ext.Element-blur"></div>/**\r
426      * Tries to blur the element. Any exceptions are caught and ignored.\r
427      * @return {Ext.Element} this\r
428      */\r
429     blur : function() {\r
430         try{\r
431             this.dom.blur();\r
432         }catch(e){}\r
433         return this;\r
434     },\r
435 \r
436     <div id="method-Ext.Element-getValue"></div>/**\r
437      * Returns the value of the "value" attribute\r
438      * @param {Boolean} asNumber true to parse the value as a number\r
439      * @return {String/Number}\r
440      */\r
441     getValue : function(asNumber){\r
442         var val = this.dom.value;\r
443         return asNumber ? parseInt(val, 10) : val;\r
444     },\r
445 \r
446     <div id="method-Ext.Element-addListener"></div>/**\r
447      * Appends an event handler to this element.  The shorthand version {@link #on} is equivalent.\r
448      * @param {String} eventName The type of event to handle\r
449      * @param {Function} fn The handler function the event invokes. This function is passed\r
450      * the following parameters:<ul>\r
451      * <li><b>evt</b> : EventObject<div class="sub-desc">The {@link Ext.EventObject EventObject} describing the event.</div></li>\r
452      * <li><b>el</b> : Element<div class="sub-desc">The {@link Ext.Element Element} which was the target of the event.\r
453      * Note that this may be filtered by using the <tt>delegate</tt> option.</div></li>\r
454      * <li><b>o</b> : Object<div class="sub-desc">The options object from the addListener call.</div></li>\r
455      * </ul>\r
456      * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the handler function is executed.\r
457      * <b>If omitted, defaults to this Element.</b>.\r
458      * @param {Object} options (optional) An object containing handler configuration properties.\r
459      * This may contain any of the following properties:<ul>\r
460      * <li><b>scope</b> Object : <div class="sub-desc">The scope (<code><b>this</b></code> reference) in which the handler function is executed.\r
461      * <b>If omitted, defaults to this Element.</b></div></li>\r
462      * <li><b>delegate</b> String: <div class="sub-desc">A simple selector to filter the target or look for a descendant of the target. See below for additional details.</div></li>\r
463      * <li><b>stopEvent</b> Boolean: <div class="sub-desc">True to stop the event. That is stop propagation, and prevent the default action.</div></li>\r
464      * <li><b>preventDefault</b> Boolean: <div class="sub-desc">True to prevent the default action</div></li>\r
465      * <li><b>stopPropagation</b> Boolean: <div class="sub-desc">True to prevent event propagation</div></li>\r
466      * <li><b>normalized</b> Boolean: <div class="sub-desc">False to pass a browser event to the handler function instead of an Ext.EventObject</div></li>\r
467      * <li><b>target</b> Ext.Element: <div class="sub-desc">Only call the handler if the event was fired on the target Element, <i>not</i> if the event was bubbled up from a child node.</div></li>\r
468      * <li><b>delay</b> Number: <div class="sub-desc">The number of milliseconds to delay the invocation of the handler after the event fires.</div></li>\r
469      * <li><b>single</b> Boolean: <div class="sub-desc">True to add a handler to handle just the next firing of the event, and then remove itself.</div></li>\r
470      * <li><b>buffer</b> Number: <div class="sub-desc">Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed\r
471      * by the specified number of milliseconds. If the event fires again within that time, the original\r
472      * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</div></li>\r
473      * </ul><br>\r
474      * <p>\r
475      * <b>Combining Options</b><br>\r
476      * In the following examples, the shorthand form {@link #on} is used rather than the more verbose\r
477      * addListener.  The two are equivalent.  Using the options argument, it is possible to combine different\r
478      * types of listeners:<br>\r
479      * <br>\r
480      * A delayed, one-time listener that auto stops the event and adds a custom argument (forumId) to the\r
481      * options object. The options object is available as the third parameter in the handler function.<div style="margin: 5px 20px 20px;">\r
482      * Code:<pre><code>\r
483 el.on('click', this.onClick, this, {\r
484     single: true,\r
485     delay: 100,\r
486     stopEvent : true,\r
487     forumId: 4\r
488 });</code></pre></p>\r
489      * <p>\r
490      * <b>Attaching multiple handlers in 1 call</b><br>\r
491      * The method also allows for a single argument to be passed which is a config object containing properties\r
492      * which specify multiple handlers.</p>\r
493      * <p>\r
494      * Code:<pre><code>\r
495 el.on({\r
496     'click' : {\r
497         fn: this.onClick,\r
498         scope: this,\r
499         delay: 100\r
500     },\r
501     'mouseover' : {\r
502         fn: this.onMouseOver,\r
503         scope: this\r
504     },\r
505     'mouseout' : {\r
506         fn: this.onMouseOut,\r
507         scope: this\r
508     }\r
509 });</code></pre>\r
510      * <p>\r
511      * Or a shorthand syntax:<br>\r
512      * Code:<pre><code></p>\r
513 el.on({\r
514     'click' : this.onClick,\r
515     'mouseover' : this.onMouseOver,\r
516     'mouseout' : this.onMouseOut,\r
517     scope: this\r
518 });\r
519      * </code></pre></p>\r
520      * <p><b>delegate</b></p>\r
521      * <p>This is a configuration option that you can pass along when registering a handler for\r
522      * an event to assist with event delegation. Event delegation is a technique that is used to\r
523      * reduce memory consumption and prevent exposure to memory-leaks. By registering an event\r
524      * for a container element as opposed to each element within a container. By setting this\r
525      * configuration option to a simple selector, the target element will be filtered to look for\r
526      * a descendant of the target.\r
527      * For example:<pre><code>\r
528 // using this markup:\r
529 &lt;div id='elId'>\r
530     &lt;p id='p1'>paragraph one&lt;/p>\r
531     &lt;p id='p2' class='clickable'>paragraph two&lt;/p>\r
532     &lt;p id='p3'>paragraph three&lt;/p>\r
533 &lt;/div>\r
534 // utilize event delegation to registering just one handler on the container element: \r
535 el = Ext.get('elId');\r
536 el.on(\r
537     'click',\r
538     function(e,t) {\r
539         // handle click\r
540         console.info(t.id); // 'p2'\r
541     },\r
542     this,\r
543     {\r
544         // filter the target element to be a descendant with the class 'clickable'\r
545         delegate: '.clickable' \r
546     }\r
547 );\r
548      * </code></pre></p>\r
549      * @return {Ext.Element} this\r
550      */\r
551     addListener : function(eventName, fn, scope, options){\r
552         Ext.EventManager.on(this.dom,  eventName, fn, scope || this, options);\r
553         return this;\r
554     },\r
555 \r
556     <div id="method-Ext.Element-removeListener"></div>/**\r
557      * Removes an event handler from this element.  The shorthand version {@link #un} is equivalent.\r
558      * <b>Note</b>: if a <i>scope</i> was explicitly specified when {@link #addListener adding} the\r
559      * listener, the same scope must be specified here.\r
560      * Example:\r
561      * <pre><code>\r
562 el.removeListener('click', this.handlerFn);\r
563 // or\r
564 el.un('click', this.handlerFn);\r
565 </code></pre>\r
566      * @param {String} eventName the type of event to remove\r
567      * @param {Function} fn the method the event invokes\r
568      * @param {Object} scope (optional) The scope (The <tt>this</tt> reference) of the handler function. Defaults\r
569      * to this Element.\r
570      * @return {Ext.Element} this\r
571      */\r
572     removeListener : function(eventName, fn, scope){\r
573         Ext.EventManager.removeListener(this.dom,  eventName, fn, scope || this);\r
574         return this;\r
575     },\r
576 \r
577     <div id="method-Ext.Element-removeAllListeners"></div>/**\r
578      * Removes all previous added listeners from this element\r
579      * @return {Ext.Element} this\r
580      */\r
581     removeAllListeners : function(){\r
582         Ext.EventManager.removeAll(this.dom);\r
583         return this;\r
584     },\r
585 \r
586     /**\r
587      * @private Test if size has a unit, otherwise appends the default\r
588      */\r
589     addUnits : function(size){\r
590         if(size === "" || size == "auto" || size === undefined){\r
591             size = size || '';\r
592         } else if(!isNaN(size) || !unitPattern.test(size)){\r
593             size = size + (this.defaultUnit || 'px');\r
594         }\r
595         return size;\r
596     },\r
597 \r
598     <div id="method-Ext.Element-load"></div>/**\r
599      * <p>Updates the <a href="http://developer.mozilla.org/en/DOM/element.innerHTML">innerHTML</a> of this Element\r
600      * from a specified URL. Note that this is subject to the <a href="http://en.wikipedia.org/wiki/Same_origin_policy">Same Origin Policy</a></p>\r
601      * <p>Updating innerHTML of an element will <b>not</b> execute embedded <tt>&lt;script></tt> elements. This is a browser restriction.</p>\r
602      * @param {Mixed} options. Either a sring containing the URL from which to load the HTML, or an {@link Ext.Ajax#request} options object specifying\r
603      * exactly how to request the HTML.\r
604      * @return {Ext.Element} this\r
605      */\r
606     load : function(url, params, cb){\r
607         Ext.Ajax.request(Ext.apply({\r
608             params: params,\r
609             url: url.url || url,\r
610             callback: cb,\r
611             el: this.dom,\r
612             indicatorText: url.indicatorText || ''\r
613         }, Ext.isObject(url) ? url : {}));\r
614         return this;\r
615     },\r
616 \r
617     <div id="method-Ext.Element-isBorderBox"></div>/**\r
618      * Tests various css rules/browsers to determine if this element uses a border box\r
619      * @return {Boolean}\r
620      */\r
621     isBorderBox : function(){\r
622         return noBoxAdjust[(this.dom.tagName || "").toLowerCase()] || Ext.isBorderBox;\r
623     },\r
624 \r
625     <div id="method-Ext.Element-remove"></div>/**\r
626      * Removes this element from the DOM and deletes it from the cache\r
627      */\r
628     remove : function(){\r
629         var me = this,\r
630             dom = me.dom;\r
631         \r
632         me.removeAllListeners();\r
633         delete El.cache[dom.id];\r
634         delete El.dataCache[dom.id]\r
635         Ext.removeNode(dom);\r
636     },\r
637 \r
638     <div id="method-Ext.Element-hover"></div>/**\r
639      * Sets up event handlers to call the passed functions when the mouse is moved into and out of the Element.\r
640      * @param {Function} overFn The function to call when the mouse enters the Element.\r
641      * @param {Function} outFn The function to call when the mouse leaves the Element.\r
642      * @param {Object} scope (optional) The scope (<tt>this</tt> reference) in which the functions are executed. Defaults to the Element's DOM element.\r
643      * @param {Object} options (optional) Options for the listener. See {@link Ext.util.Observable#addListener the <tt>options</tt> parameter}.\r
644      * @return {Ext.Element} this\r
645      */\r
646     hover : function(overFn, outFn, scope, options){\r
647         var me = this;\r
648         me.on('mouseenter', overFn, scope || me.dom, options);\r
649         me.on('mouseleave', outFn, scope || me.dom, options);\r
650         return me;\r
651     },\r
652 \r
653     <div id="method-Ext.Element-contains"></div>/**\r
654      * Returns true if this element is an ancestor of the passed element\r
655      * @param {HTMLElement/String} el The element to check\r
656      * @return {Boolean} True if this element is an ancestor of el, else false\r
657      */\r
658     contains : function(el){\r
659         return !el ? false : Ext.lib.Dom.isAncestor(this.dom, el.dom ? el.dom : el);\r
660     },\r
661 \r
662     <div id="method-Ext.Element-getAttributeNS"></div>/**\r
663      * Returns the value of a namespaced attribute from the element's underlying DOM node.\r
664      * @param {String} namespace The namespace in which to look for the attribute\r
665      * @param {String} name The attribute name\r
666      * @return {String} The attribute value\r
667      * @deprecated\r
668      */\r
669     getAttributeNS : function(ns, name){\r
670         return this.getAttribute(name, ns); \r
671     },\r
672     \r
673     <div id="method-Ext.Element-getAttribute"></div>/**\r
674      * Returns the value of an attribute from the element's underlying DOM node.\r
675      * @param {String} name The attribute name\r
676      * @param {String} namespace (optional) The namespace in which to look for the attribute\r
677      * @return {String} The attribute value\r
678      */\r
679     getAttribute : Ext.isIE ? function(name, ns){\r
680         var d = this.dom,\r
681             type = typeof d[ns + ":" + name];\r
682 \r
683         if(['undefined', 'unknown'].indexOf(type) == -1){\r
684             return d[ns + ":" + name];\r
685         }\r
686         return d[name];\r
687     } : function(name, ns){\r
688         var d = this.dom;\r
689         return d.getAttributeNS(ns, name) || d.getAttribute(ns + ":" + name) || d.getAttribute(name) || d[name];\r
690     },\r
691     \r
692     <div id="method-Ext.Element-update"></div>/**\r
693     * Update the innerHTML of this element\r
694     * @param {String} html The new HTML\r
695     * @return {Ext.Element} this\r
696      */\r
697     update : function(html) {\r
698         this.dom.innerHTML = html;\r
699         return this;\r
700     }\r
701 };\r
702 \r
703 var ep = El.prototype;\r
704 \r
705 El.addMethods = function(o){\r
706    Ext.apply(ep, o);\r
707 };\r
708 \r
709 <div id="method-Ext.Element-on"></div>/**\r
710  * Appends an event handler (shorthand for {@link #addListener}).\r
711  * @param {String} eventName The type of event to handle\r
712  * @param {Function} fn The handler function the event invokes\r
713  * @param {Object} scope (optional) The scope (this element) of the handler function\r
714  * @param {Object} options (optional) An object containing standard {@link #addListener} options\r
715  * @member Ext.Element\r
716  * @method on\r
717  */\r
718 ep.on = ep.addListener;\r
719 \r
720 <div id="method-Ext.Element-un"></div>/**\r
721  * Removes an event handler from this element (see {@link #removeListener} for additional notes).\r
722  * @param {String} eventName the type of event to remove\r
723  * @param {Function} fn the method the event invokes\r
724  * @param {Object} scope (optional) The scope (The <tt>this</tt> reference) of the handler function. Defaults\r
725  * to this Element.\r
726  * @return {Ext.Element} this\r
727  * @member Ext.Element\r
728  * @method un\r
729  */\r
730 ep.un = ep.removeListener;\r
731 \r
732 <div id="prop-Ext.Element-autoBoxAdjust"></div>/**\r
733  * true to automatically adjust width and height settings for box-model issues (default to true)\r
734  */\r
735 ep.autoBoxAdjust = true;\r
736 \r
737 // private\r
738 var unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i,\r
739     docEl;\r
740 \r
741 /**\r
742  * @private\r
743  */\r
744 El.cache = {};\r
745 El.dataCache = {};\r
746 \r
747 <div id="method-Ext.Element-get"></div>/**\r
748  * Retrieves Ext.Element objects.\r
749  * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method\r
750  * retrieves Ext.Element objects which encapsulate DOM elements. To retrieve a Component by\r
751  * its ID, use {@link Ext.ComponentMgr#get}.</p>\r
752  * <p>Uses simple caching to consistently return the same object. Automatically fixes if an\r
753  * object was recreated with the same id via AJAX or DOM.</p>\r
754  * @param {Mixed} el The id of the node, a DOM Node or an existing Element.\r
755  * @return {Element} The Element object (or null if no matching element was found)\r
756  * @static\r
757  * @member Ext.Element\r
758  * @method get\r
759  */\r
760 El.get = function(el){\r
761     var ex,\r
762         elm,\r
763         id;\r
764     if(!el){ return null; }\r
765     if (typeof el == "string") { // element id\r
766         if (!(elm = DOC.getElementById(el))) {\r
767             return null;\r
768         }\r
769         if (ex = El.cache[el]) {\r
770             ex.dom = elm;\r
771         } else {\r
772             ex = El.cache[el] = new El(elm);\r
773         }\r
774         return ex;\r
775     } else if (el.tagName) { // dom element\r
776         if(!(id = el.id)){\r
777             id = Ext.id(el);\r
778         }\r
779         if(ex = El.cache[id]){\r
780             ex.dom = el;\r
781         }else{\r
782             ex = El.cache[id] = new El(el);\r
783         }\r
784         return ex;\r
785     } else if (el instanceof El) {\r
786         if(el != docEl){\r
787             el.dom = DOC.getElementById(el.id) || el.dom; // refresh dom element in case no longer valid,\r
788                                                           // catch case where it hasn't been appended\r
789             El.cache[el.id] = el; // in case it was created directly with Element(), let's cache it\r
790         }\r
791         return el;\r
792     } else if(el.isComposite) {\r
793         return el;\r
794     } else if(Ext.isArray(el)) {\r
795         return El.select(el);\r
796     } else if(el == DOC) {\r
797         // create a bogus element object representing the document object\r
798         if(!docEl){\r
799             var f = function(){};\r
800             f.prototype = El.prototype;\r
801             docEl = new f();\r
802             docEl.dom = DOC;\r
803         }\r
804         return docEl;\r
805     }\r
806     return null;\r
807 };\r
808 \r
809 // private method for getting and setting element data\r
810 El.data = function(el, key, value){\r
811     var c = El.dataCache[el.id];\r
812     if(!c){\r
813         c = El.dataCache[el.id] = {};\r
814     }\r
815     if(arguments.length == 2){\r
816         return c[key];    \r
817     }else{\r
818         c[key] = value;\r
819     }\r
820 };\r
821 \r
822 // private\r
823 // Garbage collection - uncache elements/purge listeners on orphaned elements\r
824 // so we don't hold a reference and cause the browser to retain them\r
825 function garbageCollect(){\r
826     if(!Ext.enableGarbageCollector){\r
827         clearInterval(El.collectorThread);\r
828     } else {\r
829         var eid,\r
830             el,\r
831             d;\r
832 \r
833         for(eid in El.cache){\r
834             el = El.cache[eid];\r
835             d = el.dom;\r
836             // -------------------------------------------------------\r
837             // Determining what is garbage:\r
838             // -------------------------------------------------------\r
839             // !d\r
840             // dom node is null, definitely garbage\r
841             // -------------------------------------------------------\r
842             // !d.parentNode\r
843             // no parentNode == direct orphan, definitely garbage\r
844             // -------------------------------------------------------\r
845             // !d.offsetParent && !document.getElementById(eid)\r
846             // display none elements have no offsetParent so we will\r
847             // also try to look it up by it's id. However, check\r
848             // offsetParent first so we don't do unneeded lookups.\r
849             // This enables collection of elements that are not orphans\r
850             // directly, but somewhere up the line they have an orphan\r
851             // parent.\r
852             // -------------------------------------------------------\r
853             if(!d || !d.parentNode || (!d.offsetParent && !DOC.getElementById(eid))){\r
854                 delete El.cache[eid];\r
855                 if(d && Ext.enableListenerCollection){\r
856                     Ext.EventManager.removeAll(d);\r
857                 }\r
858             }\r
859         }\r
860     }\r
861 }\r
862 El.collectorThreadId = setInterval(garbageCollect, 30000);\r
863 \r
864 var flyFn = function(){};\r
865 flyFn.prototype = El.prototype;\r
866 \r
867 // dom is optional\r
868 El.Flyweight = function(dom){\r
869     this.dom = dom;\r
870 };\r
871 \r
872 El.Flyweight.prototype = new flyFn();\r
873 El.Flyweight.prototype.isFlyweight = true;\r
874 El._flyweights = {};\r
875 \r
876 <div id="method-Ext.Element-fly"></div>/**\r
877  * <p>Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -\r
878  * the dom node can be overwritten by other code. Shorthand of {@link Ext.Element#fly}</p>\r
879  * <p>Use this to make one-time references to DOM elements which are not going to be accessed again either by\r
880  * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link Ext#get}\r
881  * will be more appropriate to take advantage of the caching provided by the Ext.Element class.</p>\r
882  * @param {String/HTMLElement} el The dom node or id\r
883  * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts\r
884  * (e.g. internally Ext uses "_global")\r
885  * @return {Element} The shared Element object (or null if no matching element was found)\r
886  * @member Ext.Element\r
887  * @method fly\r
888  */\r
889 El.fly = function(el, named){\r
890     var ret = null;\r
891     named = named || '_global';\r
892 \r
893     if (el = Ext.getDom(el)) {\r
894         (El._flyweights[named] = El._flyweights[named] || new El.Flyweight()).dom = el;\r
895         ret = El._flyweights[named];\r
896     }\r
897     return ret;\r
898 };\r
899 \r
900 <div id="method-Ext-get"></div>/**\r
901  * Retrieves Ext.Element objects.\r
902  * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method\r
903  * retrieves Ext.Element objects which encapsulate DOM elements. To retrieve a Component by\r
904  * its ID, use {@link Ext.ComponentMgr#get}.</p>\r
905  * <p>Uses simple caching to consistently return the same object. Automatically fixes if an\r
906  * object was recreated with the same id via AJAX or DOM.</p>\r
907  * Shorthand of {@link Ext.Element#get}\r
908  * @param {Mixed} el The id of the node, a DOM Node or an existing Element.\r
909  * @return {Element} The Element object (or null if no matching element was found)\r
910  * @member Ext\r
911  * @method get\r
912  */\r
913 Ext.get = El.get;\r
914 \r
915 <div id="method-Ext-fly"></div>/**\r
916  * <p>Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -\r
917  * the dom node can be overwritten by other code. Shorthand of {@link Ext.Element#fly}</p>\r
918  * <p>Use this to make one-time references to DOM elements which are not going to be accessed again either by\r
919  * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link Ext#get}\r
920  * will be more appropriate to take advantage of the caching provided by the Ext.Element class.</p>\r
921  * @param {String/HTMLElement} el The dom node or id\r
922  * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts\r
923  * (e.g. internally Ext uses "_global")\r
924  * @return {Element} The shared Element object (or null if no matching element was found)\r
925  * @member Ext\r
926  * @method fly\r
927  */\r
928 Ext.fly = El.fly;\r
929 \r
930 // speedy lookup for elements never to box adjust\r
931 var noBoxAdjust = Ext.isStrict ? {\r
932     select:1\r
933 } : {\r
934     input:1, select:1, textarea:1\r
935 };\r
936 if(Ext.isIE || Ext.isGecko){\r
937     noBoxAdjust['button'] = 1;\r
938 }\r
939 \r
940 \r
941 Ext.EventManager.on(window, 'unload', function(){\r
942     delete El.cache;\r
943     delete El.dataCache;\r
944     delete El._flyweights;\r
945 });\r
946 })();\r
947 </pre>    \r
948 </body>\r
949 </html>