3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
15 * @class Ext.Element
\r
16 * <p>Encapsulates a DOM element, adding simple DOM manipulation facilities, normalizing for browser differences.</p>
\r
17 * <p>All instances of this class inherit the methods of {@link Ext.Fx} making visual effects easily available to all DOM elements.</p>
\r
18 * <p>Note that the events documented in this class are not Ext events, they encapsulate browser events. To
\r
19 * access the underlying browser event, see {@link Ext.EventObject#browserEvent}. Some older
\r
20 * browsers may not support the full range of events. Which events are supported is beyond the control of ExtJs.</p>
\r
24 var el = Ext.get("my-div");
\r
26 // by DOM element reference
\r
27 var el = Ext.get(myDivElement);
\r
29 * <b>Animations</b><br />
\r
30 * <p>When an element is manipulated, by default there is no animation.</p>
\r
32 var el = Ext.get("my-div");
\r
37 * <p>Many of the functions for manipulating an element have an optional "animate" parameter. This
\r
38 * parameter can be specified as boolean (<tt>true</tt>) for default animation effects.</p>
\r
40 // default animation
\r
41 el.setWidth(100, true);
\r
44 * <p>To configure the effects, an object literal with animation options to use as the Element animation
\r
45 * configuration object can also be specified. Note that the supported Element animation configuration
\r
46 * options are a subset of the {@link Ext.Fx} animation options specific to Fx effects. The supported
\r
47 * Element animation configuration options are:</p>
\r
49 Option Default Description
\r
50 --------- -------- ---------------------------------------------
\r
51 {@link Ext.Fx#duration duration} .35 The duration of the animation in seconds
\r
52 {@link Ext.Fx#easing easing} easeOut The easing method
\r
53 {@link Ext.Fx#callback callback} none A function to execute when the anim completes
\r
54 {@link Ext.Fx#scope scope} this The scope (this) of the callback function
\r
58 // Element animation options object
\r
60 {@link Ext.Fx#duration duration}: 1,
\r
61 {@link Ext.Fx#easing easing}: 'elasticIn',
\r
62 {@link Ext.Fx#callback callback}: this.foo,
\r
63 {@link Ext.Fx#scope scope}: this
\r
65 // animation with some options set
\r
66 el.setWidth(100, opt);
\r
68 * <p>The Element animation object being used for the animation will be set on the options
\r
69 * object as "anim", which allows you to stop or manipulate the animation. Here is an example:</p>
\r
71 // using the "anim" property to get the Anim object
\r
72 if(opt.anim.isAnimated()){
\r
76 * <p>Also see the <tt>{@link #animate}</tt> method for another animation technique.</p>
\r
77 * <p><b> Composite (Collections of) Elements</b></p>
\r
78 * <p>For working with collections of Elements, see {@link Ext.CompositeElement}</p>
\r
79 * @constructor Create a new Element directly.
\r
80 * @param {String/HTMLElement} element
\r
81 * @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
86 Ext.Element = function(element, forceNew){
\r
87 var dom = typeof element == "string" ?
\r
88 DOC.getElementById(element) : element,
\r
91 if(!dom) return null;
\r
95 if(!forceNew && id && Ext.Element.cache[id]){ // element object already exists
\r
96 return Ext.Element.cache[id];
\r
99 <div id="prop-Ext.Element-dom"></div>/**
\r
101 * @type HTMLElement
\r
105 <div id="prop-Ext.Element-id"></div>/**
\r
106 * The DOM element ID
\r
109 this.id = id || Ext.id(dom);
\r
112 var D = Ext.lib.Dom,
\r
113 DH = Ext.DomHelper,
\r
119 <div id="method-Ext.Element-set"></div>/**
\r
120 * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
\r
121 * @param {Object} o The object with the attributes
\r
122 * @param {Boolean} useSet (optional) false to override the default setAttribute to use expandos.
\r
123 * @return {Ext.Element} this
\r
125 set : function(o, useSet){
\r
132 if (attr != "style" && !Ext.isFunction(val)) {
\r
133 if (attr == "cls" ) {
\r
134 el.className = val;
\r
135 } else if (o.hasOwnProperty(attr)) {
\r
136 if (useSet || !!el.setAttribute) el.setAttribute(attr, val);
\r
137 else el[attr] = val;
\r
142 DH.applyStyles(el, o.style);
\r
148 <div id="event-Ext.Element-click"></div>/**
\r
150 * Fires when a mouse click is detected within the element.
\r
151 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
152 * @param {HtmlElement} t The target of the event.
\r
153 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
155 <div id="event-Ext.Element-contextmenu"></div>/**
\r
156 * @event contextmenu
\r
157 * Fires when a right click is detected within the element.
\r
158 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
159 * @param {HtmlElement} t The target of the event.
\r
160 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
162 <div id="event-Ext.Element-dblclick"></div>/**
\r
164 * Fires when a mouse double click is detected within the element.
\r
165 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
166 * @param {HtmlElement} t The target of the event.
\r
167 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
169 <div id="event-Ext.Element-mousedown"></div>/**
\r
171 * Fires when a mousedown is detected within the element.
\r
172 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
173 * @param {HtmlElement} t The target of the event.
\r
174 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
176 <div id="event-Ext.Element-mouseup"></div>/**
\r
178 * Fires when a mouseup is detected within the element.
\r
179 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
180 * @param {HtmlElement} t The target of the event.
\r
181 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
183 <div id="event-Ext.Element-mouseover"></div>/**
\r
185 * Fires when a mouseover is detected within the element.
\r
186 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
187 * @param {HtmlElement} t The target of the event.
\r
188 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
190 <div id="event-Ext.Element-mousemove"></div>/**
\r
192 * Fires when a mousemove is detected with the element.
\r
193 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
194 * @param {HtmlElement} t The target of the event.
\r
195 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
197 <div id="event-Ext.Element-mouseout"></div>/**
\r
199 * Fires when a mouseout is detected with the element.
\r
200 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
201 * @param {HtmlElement} t The target of the event.
\r
202 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
204 <div id="event-Ext.Element-mouseenter"></div>/**
\r
205 * @event mouseenter
\r
206 * Fires when the mouse enters the element.
\r
207 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
208 * @param {HtmlElement} t The target of the event.
\r
209 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
211 <div id="event-Ext.Element-mouseleave"></div>/**
\r
212 * @event mouseleave
\r
213 * Fires when the mouse leaves the element.
\r
214 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
215 * @param {HtmlElement} t The target of the event.
\r
216 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
220 <div id="event-Ext.Element-keypress"></div>/**
\r
222 * Fires when a keypress is detected within the element.
\r
223 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
224 * @param {HtmlElement} t The target of the event.
\r
225 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
227 <div id="event-Ext.Element-keydown"></div>/**
\r
229 * Fires when a keydown is detected within the element.
\r
230 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
231 * @param {HtmlElement} t The target of the event.
\r
232 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
234 <div id="event-Ext.Element-keyup"></div>/**
\r
236 * Fires when a keyup is detected within the element.
\r
237 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
238 * @param {HtmlElement} t The target of the event.
\r
239 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
243 // HTML frame/object events
\r
244 <div id="event-Ext.Element-load"></div>/**
\r
246 * Fires when the user agent finishes loading all content within the element. Only supported by window, frames, objects and images.
\r
247 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
248 * @param {HtmlElement} t The target of the event.
\r
249 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
251 <div id="event-Ext.Element-unload"></div>/**
\r
253 * 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
254 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
255 * @param {HtmlElement} t The target of the event.
\r
256 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
258 <div id="event-Ext.Element-abort"></div>/**
\r
260 * Fires when an object/image is stopped from loading before completely loaded.
\r
261 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
262 * @param {HtmlElement} t The target of the event.
\r
263 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
265 <div id="event-Ext.Element-error"></div>/**
\r
267 * Fires when an object/image/frame cannot be loaded properly.
\r
268 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
269 * @param {HtmlElement} t The target of the event.
\r
270 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
272 <div id="event-Ext.Element-resize"></div>/**
\r
274 * Fires when a document view is resized.
\r
275 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
276 * @param {HtmlElement} t The target of the event.
\r
277 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
279 <div id="event-Ext.Element-scroll"></div>/**
\r
281 * Fires when a document view is scrolled.
\r
282 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
283 * @param {HtmlElement} t The target of the event.
\r
284 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
288 <div id="event-Ext.Element-select"></div>/**
\r
290 * Fires when a user selects some text in a text field, including input and textarea.
\r
291 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
292 * @param {HtmlElement} t The target of the event.
\r
293 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
295 <div id="event-Ext.Element-change"></div>/**
\r
297 * Fires when a control loses the input focus and its value has been modified since gaining focus.
\r
298 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
299 * @param {HtmlElement} t The target of the event.
\r
300 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
302 <div id="event-Ext.Element-submit"></div>/**
\r
304 * Fires when a form is submitted.
\r
305 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
306 * @param {HtmlElement} t The target of the event.
\r
307 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
309 <div id="event-Ext.Element-reset"></div>/**
\r
311 * Fires when a form is reset.
\r
312 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
313 * @param {HtmlElement} t The target of the event.
\r
314 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
316 <div id="event-Ext.Element-focus"></div>/**
\r
318 * Fires when an element receives focus either via the pointing device or by tab navigation.
\r
319 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
320 * @param {HtmlElement} t The target of the event.
\r
321 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
323 <div id="event-Ext.Element-blur"></div>/**
\r
325 * Fires when an element loses focus either via the pointing device or by tabbing navigation.
\r
326 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
327 * @param {HtmlElement} t The target of the event.
\r
328 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
331 // User Interface events
\r
332 <div id="event-Ext.Element-DOMFocusIn"></div>/**
\r
333 * @event DOMFocusIn
\r
334 * Where supported. Similar to HTML focus event, but can be applied to any focusable element.
\r
335 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
336 * @param {HtmlElement} t The target of the event.
\r
337 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
339 <div id="event-Ext.Element-DOMFocusOut"></div>/**
\r
340 * @event DOMFocusOut
\r
341 * Where supported. Similar to HTML blur event, but can be applied to any focusable element.
\r
342 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
343 * @param {HtmlElement} t The target of the event.
\r
344 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
346 <div id="event-Ext.Element-DOMActivate"></div>/**
\r
347 * @event DOMActivate
\r
348 * Where supported. Fires when an element is activated, for instance, through a mouse click or a keypress.
\r
349 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
350 * @param {HtmlElement} t The target of the event.
\r
351 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
354 // DOM Mutation events
\r
355 <div id="event-Ext.Element-DOMSubtreeModified"></div>/**
\r
356 * @event DOMSubtreeModified
\r
357 * Where supported. Fires when the subtree is modified.
\r
358 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
359 * @param {HtmlElement} t The target of the event.
\r
360 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
362 <div id="event-Ext.Element-DOMNodeInserted"></div>/**
\r
363 * @event DOMNodeInserted
\r
364 * Where supported. Fires when a node has been added as a child of another node.
\r
365 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
366 * @param {HtmlElement} t The target of the event.
\r
367 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
369 <div id="event-Ext.Element-DOMNodeRemoved"></div>/**
\r
370 * @event DOMNodeRemoved
\r
371 * Where supported. Fires when a descendant node of the element is removed.
\r
372 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
373 * @param {HtmlElement} t The target of the event.
\r
374 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
376 <div id="event-Ext.Element-DOMNodeRemovedFromDocument"></div>/**
\r
377 * @event DOMNodeRemovedFromDocument
\r
378 * Where supported. Fires when a node is being removed from a document.
\r
379 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
380 * @param {HtmlElement} t The target of the event.
\r
381 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
383 <div id="event-Ext.Element-DOMNodeInsertedIntoDocument"></div>/**
\r
384 * @event DOMNodeInsertedIntoDocument
\r
385 * Where supported. Fires when a node is being inserted into a document.
\r
386 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
387 * @param {HtmlElement} t The target of the event.
\r
388 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
390 <div id="event-Ext.Element-DOMAttrModified"></div>/**
\r
391 * @event DOMAttrModified
\r
392 * Where supported. Fires when an attribute has been modified.
\r
393 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
394 * @param {HtmlElement} t The target of the event.
\r
395 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
397 <div id="event-Ext.Element-DOMCharacterDataModified"></div>/**
\r
398 * @event DOMCharacterDataModified
\r
399 * Where supported. Fires when the character data has been modified.
\r
400 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
401 * @param {HtmlElement} t The target of the event.
\r
402 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
405 <div id="prop-Ext.Element-defaultUnit"></div>/**
\r
406 * The default unit to append to CSS values where a unit isn't provided (defaults to px).
\r
409 defaultUnit : "px",
\r
411 <div id="method-Ext.Element-is"></div>/**
\r
412 * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
\r
413 * @param {String} selector The simple selector to test
\r
414 * @return {Boolean} True if this element matches the selector, else false
\r
416 is : function(simpleSelector){
\r
417 return Ext.DomQuery.is(this.dom, simpleSelector);
\r
420 <div id="method-Ext.Element-focus"></div>/**
\r
421 * Tries to focus the element. Any exceptions are caught and ignored.
\r
422 * @param {Number} defer (optional) Milliseconds to defer the focus
\r
423 * @return {Ext.Element} this
\r
425 focus : function(defer, /* private */ dom) {
\r
427 dom = dom || me.dom;
\r
430 me.focus.defer(defer, null, [null, dom]);
\r
438 <div id="method-Ext.Element-blur"></div>/**
\r
439 * Tries to blur the element. Any exceptions are caught and ignored.
\r
440 * @return {Ext.Element} this
\r
442 blur : function() {
\r
449 <div id="method-Ext.Element-getValue"></div>/**
\r
450 * Returns the value of the "value" attribute
\r
451 * @param {Boolean} asNumber true to parse the value as a number
\r
452 * @return {String/Number}
\r
454 getValue : function(asNumber){
\r
455 var val = this.dom.value;
\r
456 return asNumber ? parseInt(val, 10) : val;
\r
459 <div id="method-Ext.Element-addListener"></div>/**
\r
460 * Appends an event handler to this element. The shorthand version {@link #on} is equivalent.
\r
461 * @param {String} eventName The name of event to handle.
\r
462 * @param {Function} fn The handler function the event invokes. This function is passed
\r
463 * the following parameters:<ul>
\r
464 * <li><b>evt</b> : EventObject<div class="sub-desc">The {@link Ext.EventObject EventObject} describing the event.</div></li>
\r
465 * <li><b>el</b> : HtmlElement<div class="sub-desc">The DOM element which was the target of the event.
\r
466 * Note that this may be filtered by using the <tt>delegate</tt> option.</div></li>
\r
467 * <li><b>o</b> : Object<div class="sub-desc">The options object from the addListener call.</div></li>
\r
469 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the handler function is executed.
\r
470 * <b>If omitted, defaults to this Element.</b>.
\r
471 * @param {Object} options (optional) An object containing handler configuration properties.
\r
472 * This may contain any of the following properties:<ul>
\r
473 * <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
474 * <b>If omitted, defaults to this Element.</b></div></li>
\r
475 * <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
476 * <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
477 * <li><b>preventDefault</b> Boolean: <div class="sub-desc">True to prevent the default action</div></li>
\r
478 * <li><b>stopPropagation</b> Boolean: <div class="sub-desc">True to prevent event propagation</div></li>
\r
479 * <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
480 * <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
481 * <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
482 * <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
483 * <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
484 * by the specified number of milliseconds. If the event fires again within that time, the original
\r
485 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</div></li>
\r
488 * <b>Combining Options</b><br>
\r
489 * In the following examples, the shorthand form {@link #on} is used rather than the more verbose
\r
490 * addListener. The two are equivalent. Using the options argument, it is possible to combine different
\r
491 * types of listeners:<br>
\r
493 * A delayed, one-time listener that auto stops the event and adds a custom argument (forumId) to the
\r
494 * options object. The options object is available as the third parameter in the handler function.<div style="margin: 5px 20px 20px;">
\r
496 el.on('click', this.onClick, this, {
\r
501 });</code></pre></p>
\r
503 * <b>Attaching multiple handlers in 1 call</b><br>
\r
504 * The method also allows for a single argument to be passed which is a config object containing properties
\r
505 * which specify multiple handlers.</p>
\r
515 fn: this.onMouseOver,
\r
519 fn: this.onMouseOut,
\r
524 * Or a shorthand syntax:<br>
\r
525 * Code:<pre><code></p>
\r
527 'click' : this.onClick,
\r
528 'mouseover' : this.onMouseOver,
\r
529 'mouseout' : this.onMouseOut,
\r
532 * </code></pre></p>
\r
533 * <p><b>delegate</b></p>
\r
534 * <p>This is a configuration option that you can pass along when registering a handler for
\r
535 * an event to assist with event delegation. Event delegation is a technique that is used to
\r
536 * reduce memory consumption and prevent exposure to memory-leaks. By registering an event
\r
537 * for a container element as opposed to each element within a container. By setting this
\r
538 * configuration option to a simple selector, the target element will be filtered to look for
\r
539 * a descendant of the target.
\r
540 * For example:<pre><code>
\r
541 // using this markup:
\r
543 <p id='p1'>paragraph one</p>
\r
544 <p id='p2' class='clickable'>paragraph two</p>
\r
545 <p id='p3'>paragraph three</p>
\r
547 // utilize event delegation to registering just one handler on the container element:
\r
548 el = Ext.get('elId');
\r
553 console.info(t.id); // 'p2'
\r
557 // filter the target element to be a descendant with the class 'clickable'
\r
558 delegate: '.clickable'
\r
561 * </code></pre></p>
\r
562 * @return {Ext.Element} this
\r
564 addListener : function(eventName, fn, scope, options){
\r
565 Ext.EventManager.on(this.dom, eventName, fn, scope || this, options);
\r
569 <div id="method-Ext.Element-removeListener"></div>/**
\r
570 * Removes an event handler from this element. The shorthand version {@link #un} is equivalent.
\r
571 * <b>Note</b>: if a <i>scope</i> was explicitly specified when {@link #addListener adding} the
\r
572 * listener, the same scope must be specified here.
\r
575 el.removeListener('click', this.handlerFn);
\r
577 el.un('click', this.handlerFn);
\r
579 * @param {String} eventName The name of the event from which to remove the handler.
\r
580 * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
\r
581 * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
\r
582 * then this must refer to the same object.
\r
583 * @return {Ext.Element} this
\r
585 removeListener : function(eventName, fn, scope){
\r
586 Ext.EventManager.removeListener(this.dom, eventName, fn, scope || this);
\r
590 <div id="method-Ext.Element-removeAllListeners"></div>/**
\r
591 * Removes all previous added listeners from this element
\r
592 * @return {Ext.Element} this
\r
594 removeAllListeners : function(){
\r
595 Ext.EventManager.removeAll(this.dom);
\r
600 * @private Test if size has a unit, otherwise appends the default
\r
602 addUnits : function(size){
\r
603 if(size === "" || size == "auto" || size === undefined){
\r
605 } else if(!isNaN(size) || !unitPattern.test(size)){
\r
606 size = size + (this.defaultUnit || 'px');
\r
611 <div id="method-Ext.Element-load"></div>/**
\r
612 * <p>Updates the <a href="http://developer.mozilla.org/en/DOM/element.innerHTML">innerHTML</a> of this Element
\r
613 * 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
614 * <p>Updating innerHTML of an element will <b>not</b> execute embedded <tt><script></tt> elements. This is a browser restriction.</p>
\r
615 * @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
616 * exactly how to request the HTML.
\r
617 * @return {Ext.Element} this
\r
619 load : function(url, params, cb){
\r
620 Ext.Ajax.request(Ext.apply({
\r
622 url: url.url || url,
\r
625 indicatorText: url.indicatorText || ''
\r
626 }, Ext.isObject(url) ? url : {}));
\r
630 <div id="method-Ext.Element-isBorderBox"></div>/**
\r
631 * Tests various css rules/browsers to determine if this element uses a border box
\r
632 * @return {Boolean}
\r
634 isBorderBox : function(){
\r
635 return noBoxAdjust[(this.dom.tagName || "").toLowerCase()] || Ext.isBorderBox;
\r
638 <div id="method-Ext.Element-remove"></div>/**
\r
639 * Removes this element from the DOM and deletes it from the cache
\r
641 remove : function(){
\r
645 me.removeAllListeners();
\r
648 delete El.cache[dom.id];
\r
649 delete El.dataCache[dom.id];
\r
650 Ext.removeNode(dom);
\r
654 <div id="method-Ext.Element-hover"></div>/**
\r
655 * Sets up event handlers to call the passed functions when the mouse is moved into and out of the Element.
\r
656 * @param {Function} overFn The function to call when the mouse enters the Element.
\r
657 * @param {Function} outFn The function to call when the mouse leaves the Element.
\r
658 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the functions are executed. Defaults to the Element's DOM element.
\r
659 * @param {Object} options (optional) Options for the listener. See {@link Ext.util.Observable#addListener the <tt>options</tt> parameter}.
\r
660 * @return {Ext.Element} this
\r
662 hover : function(overFn, outFn, scope, options){
\r
664 me.on('mouseenter', overFn, scope || me.dom, options);
\r
665 me.on('mouseleave', outFn, scope || me.dom, options);
\r
669 <div id="method-Ext.Element-contains"></div>/**
\r
670 * Returns true if this element is an ancestor of the passed element
\r
671 * @param {HTMLElement/String} el The element to check
\r
672 * @return {Boolean} True if this element is an ancestor of el, else false
\r
674 contains : function(el){
\r
675 return !el ? false : Ext.lib.Dom.isAncestor(this.dom, el.dom ? el.dom : el);
\r
678 <div id="method-Ext.Element-getAttributeNS"></div>/**
\r
679 * Returns the value of a namespaced attribute from the element's underlying DOM node.
\r
680 * @param {String} namespace The namespace in which to look for the attribute
\r
681 * @param {String} name The attribute name
\r
682 * @return {String} The attribute value
\r
685 getAttributeNS : function(ns, name){
\r
686 return this.getAttribute(name, ns);
\r
689 <div id="method-Ext.Element-getAttribute"></div>/**
\r
690 * Returns the value of an attribute from the element's underlying DOM node.
\r
691 * @param {String} name The attribute name
\r
692 * @param {String} namespace (optional) The namespace in which to look for the attribute
\r
693 * @return {String} The attribute value
\r
695 getAttribute : Ext.isIE ? function(name, ns){
\r
697 type = typeof d[ns + ":" + name];
\r
699 if(['undefined', 'unknown'].indexOf(type) == -1){
\r
700 return d[ns + ":" + name];
\r
703 } : function(name, ns){
\r
705 return d.getAttributeNS(ns, name) || d.getAttribute(ns + ":" + name) || d.getAttribute(name) || d[name];
\r
708 <div id="method-Ext.Element-update"></div>/**
\r
709 * Update the innerHTML of this element
\r
710 * @param {String} html The new HTML
\r
711 * @return {Ext.Element} this
\r
713 update : function(html) {
\r
715 this.dom.innerHTML = html;
\r
721 var ep = El.prototype;
\r
723 El.addMethods = function(o){
\r
727 <div id="method-Ext.Element-on"></div>/**
\r
728 * Appends an event handler (shorthand for {@link #addListener}).
\r
729 * @param {String} eventName The name of event to handle.
\r
730 * @param {Function} fn The handler function the event invokes.
\r
731 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function is executed.
\r
732 * @param {Object} options (optional) An object containing standard {@link #addListener} options
\r
733 * @member Ext.Element
\r
736 ep.on = ep.addListener;
\r
738 <div id="method-Ext.Element-un"></div>/**
\r
739 * Removes an event handler from this element (see {@link #removeListener} for additional notes).
\r
740 * @param {String} eventName The name of the event from which to remove the handler.
\r
741 * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
\r
742 * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
\r
743 * then this must refer to the same object.
\r
744 * @return {Ext.Element} this
\r
745 * @member Ext.Element
\r
748 ep.un = ep.removeListener;
\r
750 <div id="prop-Ext.Element-autoBoxAdjust"></div>/**
\r
751 * true to automatically adjust width and height settings for box-model issues (default to true)
\r
753 ep.autoBoxAdjust = true;
\r
756 var unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i,
\r
765 <div id="method-Ext.Element-get"></div>/**
\r
766 * Retrieves Ext.Element objects.
\r
767 * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method
\r
768 * retrieves Ext.Element objects which encapsulate DOM elements. To retrieve a Component by
\r
769 * its ID, use {@link Ext.ComponentMgr#get}.</p>
\r
770 * <p>Uses simple caching to consistently return the same object. Automatically fixes if an
\r
771 * object was recreated with the same id via AJAX or DOM.</p>
\r
772 * @param {Mixed} el The id of the node, a DOM Node or an existing Element.
\r
773 * @return {Element} The Element object (or null if no matching element was found)
\r
775 * @member Ext.Element
\r
778 El.get = function(el){
\r
782 if(!el){ return null; }
\r
783 if (typeof el == "string") { // element id
\r
784 if (!(elm = DOC.getElementById(el))) {
\r
787 if (ex = El.cache[el]) {
\r
790 ex = El.cache[el] = new El(elm);
\r
793 } else if (el.tagName) { // dom element
\r
797 if(ex = El.cache[id]){
\r
800 ex = El.cache[id] = new El(el);
\r
803 } else if (el instanceof El) {
\r
805 el.dom = DOC.getElementById(el.id) || el.dom; // refresh dom element in case no longer valid,
\r
806 // catch case where it hasn't been appended
\r
807 El.cache[el.id] = el; // in case it was created directly with Element(), let's cache it
\r
810 } else if(el.isComposite) {
\r
812 } else if(Ext.isArray(el)) {
\r
813 return El.select(el);
\r
814 } else if(el == DOC) {
\r
815 // create a bogus element object representing the document object
\r
817 var f = function(){};
\r
818 f.prototype = El.prototype;
\r
827 // private method for getting and setting element data
\r
828 El.data = function(el, key, value){
\r
829 var c = El.dataCache[el.id];
\r
831 c = El.dataCache[el.id] = {};
\r
833 if(arguments.length == 2){
\r
836 return (c[key] = value);
\r
841 // Garbage collection - uncache elements/purge listeners on orphaned elements
\r
842 // so we don't hold a reference and cause the browser to retain them
\r
843 function garbageCollect(){
\r
844 if(!Ext.enableGarbageCollector){
\r
845 clearInterval(El.collectorThread);
\r
851 for(eid in El.cache){
\r
852 el = El.cache[eid];
\r
854 // -------------------------------------------------------
\r
855 // Determining what is garbage:
\r
856 // -------------------------------------------------------
\r
858 // dom node is null, definitely garbage
\r
859 // -------------------------------------------------------
\r
861 // no parentNode == direct orphan, definitely garbage
\r
862 // -------------------------------------------------------
\r
863 // !d.offsetParent && !document.getElementById(eid)
\r
864 // display none elements have no offsetParent so we will
\r
865 // also try to look it up by it's id. However, check
\r
866 // offsetParent first so we don't do unneeded lookups.
\r
867 // This enables collection of elements that are not orphans
\r
868 // directly, but somewhere up the line they have an orphan
\r
870 // -------------------------------------------------------
\r
871 if(!d || !d.parentNode || (!d.offsetParent && !DOC.getElementById(eid))){
\r
872 delete El.cache[eid];
\r
873 if(d && Ext.enableListenerCollection){
\r
874 Ext.EventManager.removeAll(d);
\r
880 El.collectorThreadId = setInterval(garbageCollect, 30000);
\r
882 var flyFn = function(){};
\r
883 flyFn.prototype = El.prototype;
\r
886 El.Flyweight = function(dom){
\r
890 El.Flyweight.prototype = new flyFn();
\r
891 El.Flyweight.prototype.isFlyweight = true;
\r
892 El._flyweights = {};
\r
894 <div id="method-Ext.Element-fly"></div>/**
\r
895 * <p>Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
\r
896 * the dom node can be overwritten by other code. Shorthand of {@link Ext.Element#fly}</p>
\r
897 * <p>Use this to make one-time references to DOM elements which are not going to be accessed again either by
\r
898 * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link Ext#get}
\r
899 * will be more appropriate to take advantage of the caching provided by the Ext.Element class.</p>
\r
900 * @param {String/HTMLElement} el The dom node or id
\r
901 * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts
\r
902 * (e.g. internally Ext uses "_global")
\r
903 * @return {Element} The shared Element object (or null if no matching element was found)
\r
904 * @member Ext.Element
\r
907 El.fly = function(el, named){
\r
909 named = named || '_global';
\r
911 if (el = Ext.getDom(el)) {
\r
912 (El._flyweights[named] = El._flyweights[named] || new El.Flyweight()).dom = el;
\r
913 ret = El._flyweights[named];
\r
918 <div id="method-Ext-get"></div>/**
\r
919 * Retrieves Ext.Element objects.
\r
920 * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method
\r
921 * retrieves Ext.Element objects which encapsulate DOM elements. To retrieve a Component by
\r
922 * its ID, use {@link Ext.ComponentMgr#get}.</p>
\r
923 * <p>Uses simple caching to consistently return the same object. Automatically fixes if an
\r
924 * object was recreated with the same id via AJAX or DOM.</p>
\r
925 * Shorthand of {@link Ext.Element#get}
\r
926 * @param {Mixed} el The id of the node, a DOM Node or an existing Element.
\r
927 * @return {Element} The Element object (or null if no matching element was found)
\r
933 <div id="method-Ext-fly"></div>/**
\r
934 * <p>Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
\r
935 * the dom node can be overwritten by other code. Shorthand of {@link Ext.Element#fly}</p>
\r
936 * <p>Use this to make one-time references to DOM elements which are not going to be accessed again either by
\r
937 * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link Ext#get}
\r
938 * will be more appropriate to take advantage of the caching provided by the Ext.Element class.</p>
\r
939 * @param {String/HTMLElement} el The dom node or id
\r
940 * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts
\r
941 * (e.g. internally Ext uses "_global")
\r
942 * @return {Element} The shared Element object (or null if no matching element was found)
\r
948 // speedy lookup for elements never to box adjust
\r
949 var noBoxAdjust = Ext.isStrict ? {
\r
952 input:1, select:1, textarea:1
\r
954 if(Ext.isIE || Ext.isGecko){
\r
955 noBoxAdjust['button'] = 1;
\r
959 Ext.EventManager.on(window, 'unload', function(){
\r
961 delete El.dataCache;
\r
962 delete El._flyweights;
\r