3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.core.Element
17 * <p>Encapsulates a DOM element, adding simple DOM manipulation facilities, normalizing for browser differences.</p>
18 * <p>All instances of this class inherit the methods of {@link Ext.fx.Anim} making visual effects easily available to all DOM elements.</p>
19 * <p>Note that the events documented in this class are not Ext events, they encapsulate browser events. To
20 * access the underlying browser event, see {@link Ext.EventObject#browserEvent}. Some older
21 * browsers may not support the full range of events. Which events are supported is beyond the control of ExtJs.</p>
25 var el = Ext.get("my-div");
27 // by DOM element reference
28 var el = Ext.get(myDivElement);
30 * <b>Animations</b><br />
31 * <p>When an element is manipulated, by default there is no animation.</p>
33 var el = Ext.get("my-div");
38 * <p>Many of the functions for manipulating an element have an optional "animate" parameter. This
39 * parameter can be specified as boolean (<tt>true</tt>) for default animation effects.</p>
42 el.setWidth(100, true);
45 * <p>To configure the effects, an object literal with animation options to use as the Element animation
46 * configuration object can also be specified. Note that the supported Element animation configuration
47 * options are a subset of the {@link Ext.fx.Anim} animation options specific to Fx effects. The supported
48 * Element animation configuration options are:</p>
50 Option Default Description
51 --------- -------- ---------------------------------------------
52 {@link Ext.fx.Anim#duration duration} .35 The duration of the animation in seconds
53 {@link Ext.fx.Anim#easing easing} easeOut The easing method
54 {@link Ext.fx.Anim#callback callback} none A function to execute when the anim completes
55 {@link Ext.fx.Anim#scope scope} this The scope (this) of the callback function
59 // Element animation options object
61 {@link Ext.fx.Anim#duration duration}: 1,
62 {@link Ext.fx.Anim#easing easing}: 'elasticIn',
63 {@link Ext.fx.Anim#callback callback}: this.foo,
64 {@link Ext.fx.Anim#scope scope}: this
66 // animation with some options set
67 el.setWidth(100, opt);
69 * <p>The Element animation object being used for the animation will be set on the options
70 * object as "anim", which allows you to stop or manipulate the animation. Here is an example:</p>
72 // using the "anim" property to get the Anim object
73 if(opt.anim.isAnimated()){
77 * <p>Also see the <tt>{@link #animate}</tt> method for another animation technique.</p>
78 * <p><b> Composite (Collections of) Elements</b></p>
79 * <p>For working with collections of Elements, see {@link Ext.CompositeElement}</p>
80 * @constructor Create a new Element directly.
81 * @param {String/HTMLElement} element
82 * @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).
88 Ext.Element = Ext.core.Element = function(element, forceNew) {
89 var dom = typeof element == "string" ? DOC.getElementById(element) : element,
98 if (!forceNew && id && EC[id]) {
99 // element object already exists
113 this.id = id || Ext.id(dom);
116 var DH = Ext.core.DomHelper,
117 El = Ext.core.Element;
122 * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
123 * @param {Object} o The object with the attributes
124 * @param {Boolean} useSet (optional) false to override the default setAttribute to use expandos.
125 * @return {Ext.core.Element} this
127 set: function(o, useSet) {
131 useSet = (useSet !== false) && !!el.setAttribute;
134 if (o.hasOwnProperty(attr)) {
136 if (attr == 'style') {
137 DH.applyStyles(el, val);
138 } else if (attr == 'cls') {
141 el.setAttribute(attr, val);
153 * Fires when a mouse click is detected within the element.
154 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
155 * @param {HtmlElement} t The target of the event.
156 * @param {Object} o The options configuration passed to the {@link #addListener} call.
160 * Fires when a right click is detected within the element.
161 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
162 * @param {HtmlElement} t The target of the event.
163 * @param {Object} o The options configuration passed to the {@link #addListener} call.
167 * Fires when a mouse double click is detected within the element.
168 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
169 * @param {HtmlElement} t The target of the event.
170 * @param {Object} o The options configuration passed to the {@link #addListener} call.
174 * Fires when a mousedown is detected within the element.
175 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
176 * @param {HtmlElement} t The target of the event.
177 * @param {Object} o The options configuration passed to the {@link #addListener} call.
181 * Fires when a mouseup is detected within the element.
182 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
183 * @param {HtmlElement} t The target of the event.
184 * @param {Object} o The options configuration passed to the {@link #addListener} call.
188 * Fires when a mouseover is detected within the element.
189 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
190 * @param {HtmlElement} t The target of the event.
191 * @param {Object} o The options configuration passed to the {@link #addListener} call.
195 * Fires when a mousemove is detected with the element.
196 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
197 * @param {HtmlElement} t The target of the event.
198 * @param {Object} o The options configuration passed to the {@link #addListener} call.
202 * Fires when a mouseout is detected with the element.
203 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
204 * @param {HtmlElement} t The target of the event.
205 * @param {Object} o The options configuration passed to the {@link #addListener} call.
209 * Fires when the mouse enters the element.
210 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
211 * @param {HtmlElement} t The target of the event.
212 * @param {Object} o The options configuration passed to the {@link #addListener} call.
216 * Fires when the mouse leaves the element.
217 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
218 * @param {HtmlElement} t The target of the event.
219 * @param {Object} o The options configuration passed to the {@link #addListener} call.
225 * Fires when a keypress is detected within the element.
226 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
227 * @param {HtmlElement} t The target of the event.
228 * @param {Object} o The options configuration passed to the {@link #addListener} call.
232 * Fires when a keydown is detected within the element.
233 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
234 * @param {HtmlElement} t The target of the event.
235 * @param {Object} o The options configuration passed to the {@link #addListener} call.
239 * Fires when a keyup is detected within the element.
240 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
241 * @param {HtmlElement} t The target of the event.
242 * @param {Object} o The options configuration passed to the {@link #addListener} call.
246 // HTML frame/object events
249 * Fires when the user agent finishes loading all content within the element. Only supported by window, frames, objects and images.
250 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
251 * @param {HtmlElement} t The target of the event.
252 * @param {Object} o The options configuration passed to the {@link #addListener} call.
256 * 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.
257 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
258 * @param {HtmlElement} t The target of the event.
259 * @param {Object} o The options configuration passed to the {@link #addListener} call.
263 * Fires when an object/image is stopped from loading before completely loaded.
264 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
265 * @param {HtmlElement} t The target of the event.
266 * @param {Object} o The options configuration passed to the {@link #addListener} call.
270 * Fires when an object/image/frame cannot be loaded properly.
271 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
272 * @param {HtmlElement} t The target of the event.
273 * @param {Object} o The options configuration passed to the {@link #addListener} call.
277 * Fires when a document view is resized.
278 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
279 * @param {HtmlElement} t The target of the event.
280 * @param {Object} o The options configuration passed to the {@link #addListener} call.
284 * Fires when a document view is scrolled.
285 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
286 * @param {HtmlElement} t The target of the event.
287 * @param {Object} o The options configuration passed to the {@link #addListener} call.
293 * Fires when a user selects some text in a text field, including input and textarea.
294 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
295 * @param {HtmlElement} t The target of the event.
296 * @param {Object} o The options configuration passed to the {@link #addListener} call.
300 * Fires when a control loses the input focus and its value has been modified since gaining focus.
301 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
302 * @param {HtmlElement} t The target of the event.
303 * @param {Object} o The options configuration passed to the {@link #addListener} call.
307 * Fires when a form is submitted.
308 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
309 * @param {HtmlElement} t The target of the event.
310 * @param {Object} o The options configuration passed to the {@link #addListener} call.
314 * Fires when a form is reset.
315 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
316 * @param {HtmlElement} t The target of the event.
317 * @param {Object} o The options configuration passed to the {@link #addListener} call.
321 * Fires when an element receives focus either via the pointing device or by tab navigation.
322 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
323 * @param {HtmlElement} t The target of the event.
324 * @param {Object} o The options configuration passed to the {@link #addListener} call.
328 * Fires when an element loses focus either via the pointing device or by tabbing navigation.
329 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
330 * @param {HtmlElement} t The target of the event.
331 * @param {Object} o The options configuration passed to the {@link #addListener} call.
334 // User Interface events
337 * Where supported. Similar to HTML focus event, but can be applied to any focusable element.
338 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
339 * @param {HtmlElement} t The target of the event.
340 * @param {Object} o The options configuration passed to the {@link #addListener} call.
344 * Where supported. Similar to HTML blur event, but can be applied to any focusable element.
345 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
346 * @param {HtmlElement} t The target of the event.
347 * @param {Object} o The options configuration passed to the {@link #addListener} call.
351 * Where supported. Fires when an element is activated, for instance, through a mouse click or a keypress.
352 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
353 * @param {HtmlElement} t The target of the event.
354 * @param {Object} o The options configuration passed to the {@link #addListener} call.
357 // DOM Mutation events
359 * @event DOMSubtreeModified
360 * Where supported. Fires when the subtree is modified.
361 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
362 * @param {HtmlElement} t The target of the event.
363 * @param {Object} o The options configuration passed to the {@link #addListener} call.
366 * @event DOMNodeInserted
367 * Where supported. Fires when a node has been added as a child of another node.
368 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
369 * @param {HtmlElement} t The target of the event.
370 * @param {Object} o The options configuration passed to the {@link #addListener} call.
373 * @event DOMNodeRemoved
374 * Where supported. Fires when a descendant node of the element is removed.
375 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
376 * @param {HtmlElement} t The target of the event.
377 * @param {Object} o The options configuration passed to the {@link #addListener} call.
380 * @event DOMNodeRemovedFromDocument
381 * Where supported. Fires when a node is being removed from a document.
382 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
383 * @param {HtmlElement} t The target of the event.
384 * @param {Object} o The options configuration passed to the {@link #addListener} call.
387 * @event DOMNodeInsertedIntoDocument
388 * Where supported. Fires when a node is being inserted into a document.
389 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
390 * @param {HtmlElement} t The target of the event.
391 * @param {Object} o The options configuration passed to the {@link #addListener} call.
394 * @event DOMAttrModified
395 * Where supported. Fires when an attribute has been modified.
396 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
397 * @param {HtmlElement} t The target of the event.
398 * @param {Object} o The options configuration passed to the {@link #addListener} call.
401 * @event DOMCharacterDataModified
402 * Where supported. Fires when the character data has been modified.
403 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
404 * @param {HtmlElement} t The target of the event.
405 * @param {Object} o The options configuration passed to the {@link #addListener} call.
409 * The default unit to append to CSS values where a unit isn't provided (defaults to px).
415 * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
416 * @param {String} selector The simple selector to test
417 * @return {Boolean} True if this element matches the selector, else false
419 is: function(simpleSelector) {
420 return Ext.DomQuery.is(this.dom, simpleSelector);
424 * Tries to focus the element. Any exceptions are caught and ignored.
425 * @param {Number} defer (optional) Milliseconds to defer the focus
426 * @return {Ext.core.Element} this
428 focus: function(defer,
435 Ext.defer(me.focus, defer, null, [null, dom]);
444 * Tries to blur the element. Any exceptions are caught and ignored.
445 * @return {Ext.core.Element} this
455 * Returns the value of the "value" attribute
456 * @param {Boolean} asNumber true to parse the value as a number
457 * @return {String/Number}
459 getValue: function(asNumber) {
460 var val = this.dom.value;
461 return asNumber ? parseInt(val, 10) : val;
465 * Appends an event handler to this element. The shorthand version {@link #on} is equivalent.
466 * @param {String} eventName The name of event to handle.
467 * @param {Function} fn The handler function the event invokes. This function is passed
468 * the following parameters:<ul>
469 * <li><b>evt</b> : EventObject<div class="sub-desc">The {@link Ext.EventObject EventObject} describing the event.</div></li>
470 * <li><b>el</b> : HtmlElement<div class="sub-desc">The DOM element which was the target of the event.
471 * Note that this may be filtered by using the <tt>delegate</tt> option.</div></li>
472 * <li><b>o</b> : Object<div class="sub-desc">The options object from the addListener call.</div></li>
474 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the handler function is executed.
475 * <b>If omitted, defaults to this Element.</b>.
476 * @param {Object} options (optional) An object containing handler configuration properties.
477 * This may contain any of the following properties:<ul>
478 * <li><b>scope</b> Object : <div class="sub-desc">The scope (<code><b>this</b></code> reference) in which the handler function is executed.
479 * <b>If omitted, defaults to this Element.</b></div></li>
480 * <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>
481 * <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>
482 * <li><b>preventDefault</b> Boolean: <div class="sub-desc">True to prevent the default action</div></li>
483 * <li><b>stopPropagation</b> Boolean: <div class="sub-desc">True to prevent event propagation</div></li>
484 * <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>
485 * <li><b>target</b> Ext.core.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>
486 * <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>
487 * <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>
488 * <li><b>buffer</b> Number: <div class="sub-desc">Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed
489 * by the specified number of milliseconds. If the event fires again within that time, the original
490 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</div></li>
493 * <b>Combining Options</b><br>
494 * In the following examples, the shorthand form {@link #on} is used rather than the more verbose
495 * addListener. The two are equivalent. Using the options argument, it is possible to combine different
496 * types of listeners:<br>
498 * A delayed, one-time listener that auto stops the event and adds a custom argument (forumId) to the
499 * options object. The options object is available as the third parameter in the handler function.<div style="margin: 5px 20px 20px;">
501 el.on('click', this.onClick, this, {
508 * <b>Attaching multiple handlers in 1 call</b><br>
509 * The method also allows for a single argument to be passed which is a config object containing properties
510 * which specify multiple handlers.</p>
520 fn: this.onMouseOver,
529 * Or a shorthand syntax:<br>
530 * Code:<pre><code></p>
532 'click' : this.onClick,
533 'mouseover' : this.onMouseOver,
534 'mouseout' : this.onMouseOut,
538 * <p><b>delegate</b></p>
539 * <p>This is a configuration option that you can pass along when registering a handler for
540 * an event to assist with event delegation. Event delegation is a technique that is used to
541 * reduce memory consumption and prevent exposure to memory-leaks. By registering an event
542 * for a container element as opposed to each element within a container. By setting this
543 * configuration option to a simple selector, the target element will be filtered to look for
544 * a descendant of the target.
545 * For example:<pre><code>
546 // using this markup:
548 <p id='p1'>paragraph one</p>
549 <p id='p2' class='clickable'>paragraph two</p>
550 <p id='p3'>paragraph three</p>
552 // utilize event delegation to registering just one handler on the container element:
553 el = Ext.get('elId');
558 console.info(t.id); // 'p2'
562 // filter the target element to be a descendant with the class 'clickable'
563 delegate: '.clickable'
567 * @return {Ext.core.Element} this
569 addListener: function(eventName, fn, scope, options) {
570 Ext.EventManager.on(this.dom, eventName, fn, scope || this, options);
575 * Removes an event handler from this element. The shorthand version {@link #un} is equivalent.
576 * <b>Note</b>: if a <i>scope</i> was explicitly specified when {@link #addListener adding} the
577 * listener, the same scope must be specified here.
580 el.removeListener('click', this.handlerFn);
582 el.un('click', this.handlerFn);
584 * @param {String} eventName The name of the event from which to remove the handler.
585 * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
586 * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
587 * then this must refer to the same object.
588 * @return {Ext.core.Element} this
590 removeListener: function(eventName, fn, scope) {
591 Ext.EventManager.un(this.dom, eventName, fn, scope || this);
596 * Removes all previous added listeners from this element
597 * @return {Ext.core.Element} this
599 removeAllListeners: function() {
600 Ext.EventManager.removeAll(this.dom);
605 * Recursively removes all previous added listeners from this element and its children
606 * @return {Ext.core.Element} this
608 purgeAllListeners: function() {
609 Ext.EventManager.purgeElement(this);
614 * @private Test if size has a unit, otherwise appends the passed unit string, or the default for this Element.
615 * @param size {Mixed} The size to set
616 * @param units {String} The units to append to a numeric size value
618 addUnits: function(size, units) {
620 // Most common case first: Size is set to a number
621 if (Ext.isNumber(size)) {
622 return size + (units || this.defaultUnit || 'px');
625 // Size set to a value which means "auto"
626 if (size === "" || size == "auto" || size === undefined || size === null) {
630 // Otherwise, warn if it's not a valid CSS measurement
631 if (!unitPattern.test(size)) {
633 if (Ext.isDefined(Ext.global.console)) {
634 Ext.global.console.warn("Warning, size detected as NaN on Element.addUnits.");
643 * Tests various css rules/browsers to determine if this element uses a border box
646 isBorderBox: function() {
647 return Ext.isBorderBox || noBoxAdjust[(this.dom.tagName || "").toLowerCase()];
651 * <p>Removes this element's dom reference. Note that event and cache removal is handled at {@link Ext#removeNode Ext.removeNode}</p>
664 * Sets up event handlers to call the passed functions when the mouse is moved into and out of the Element.
665 * @param {Function} overFn The function to call when the mouse enters the Element.
666 * @param {Function} outFn The function to call when the mouse leaves the Element.
667 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the functions are executed. Defaults to the Element's DOM element.
668 * @param {Object} options (optional) Options for the listener. See {@link Ext.util.Observable#addListener the <tt>options</tt> parameter}.
669 * @return {Ext.core.Element} this
671 hover: function(overFn, outFn, scope, options) {
673 me.on('mouseenter', overFn, scope || me.dom, options);
674 me.on('mouseleave', outFn, scope || me.dom, options);
679 * Returns true if this element is an ancestor of the passed element
680 * @param {HTMLElement/String} el The element to check
681 * @return {Boolean} True if this element is an ancestor of el, else false
683 contains: function(el) {
684 return ! el ? false: Ext.core.Element.isAncestor(this.dom, el.dom ? el.dom: el);
688 * Returns the value of a namespaced attribute from the element's underlying DOM node.
689 * @param {String} namespace The namespace in which to look for the attribute
690 * @param {String} name The attribute name
691 * @return {String} The attribute value
694 getAttributeNS: function(ns, name) {
695 return this.getAttribute(name, ns);
699 * Returns the value of an attribute from the element's underlying DOM node.
700 * @param {String} name The attribute name
701 * @param {String} namespace (optional) The namespace in which to look for the attribute
702 * @return {String} The attribute value
705 getAttribute: (Ext.isIE && !(Ext.isIE9 && document.documentMode === 9)) ?
710 type = typeof d[ns + ":" + name];
711 if (type != 'undefined' && type != 'unknown') {
712 return d[ns + ":" + name] || null;
716 if (name === "for") {
719 return d[name] || null;
720 }: function(name, ns) {
723 return d.getAttributeNS(ns, name) || d.getAttribute(ns + ":" + name);
725 return d.getAttribute(name) || d[name] || null;
729 * Update the innerHTML of this element
730 * @param {String} html The new HTML
731 * @return {Ext.core.Element} this
733 update: function(html) {
735 this.dom.innerHTML = html;
741 var ep = El.prototype;
743 El.addMethods = function(o) {
748 * Appends an event handler (shorthand for {@link #addListener}).
749 * @param {String} eventName The name of event to handle.
750 * @param {Function} fn The handler function the event invokes.
751 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function is executed.
752 * @param {Object} options (optional) An object containing standard {@link #addListener} options
753 * @member Ext.core.Element
756 ep.on = ep.addListener;
759 * Removes an event handler from this element (see {@link #removeListener} for additional notes).
760 * @param {String} eventName The name of the event from which to remove the handler.
761 * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
762 * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
763 * then this must refer to the same object.
764 * @return {Ext.core.Element} this
765 * @member Ext.core.Element
768 ep.un = ep.removeListener;
771 * Removes all previous added listeners from this element
772 * @return {Ext.core.Element} this
773 * @member Ext.core.Element
774 * @method clearListeners
776 ep.clearListeners = ep.removeAllListeners;
779 * Removes this element's dom reference. Note that event and cache removal is handled at {@link Ext#removeNode Ext.removeNode}.
780 * Alias to {@link #remove}.
781 * @member Ext.core.Element
784 ep.destroy = ep.remove;
787 * true to automatically adjust width and height settings for box-model issues (default to true)
789 ep.autoBoxAdjust = true;
792 var unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i,
796 * Retrieves Ext.core.Element objects.
797 * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method
798 * retrieves Ext.core.Element objects which encapsulate DOM elements. To retrieve a Component by
799 * its ID, use {@link Ext.ComponentManager#get}.</p>
800 * <p>Uses simple caching to consistently return the same object. Automatically fixes if an
801 * object was recreated with the same id via AJAX or DOM.</p>
802 * @param {Mixed} el The id of the node, a DOM Node or an existing Element.
803 * @return {Element} The Element object (or null if no matching element was found)
805 * @member Ext.core.Element
808 El.get = function(el) {
815 if (typeof el == "string") {
817 if (! (elm = DOC.getElementById(el))) {
820 if (EC[el] && EC[el].el) {
824 ex = El.addToCache(new El(elm));
827 } else if (el.tagName) {
829 if (! (id = el.id)) {
832 if (EC[id] && EC[id].el) {
836 ex = El.addToCache(new El(el));
839 } else if (el instanceof El) {
841 // refresh dom element in case no longer valid,
842 // catch case where it hasn't been appended
843 // If an el instance is passed, don't pass to getElementById without some kind of id
844 if (Ext.isIE && (el.id == undefined || el.id == '')) {
847 el.dom = DOC.getElementById(el.id) || el.dom;
851 } else if (el.isComposite) {
853 } else if (Ext.isArray(el)) {
854 return El.select(el);
855 } else if (el == DOC) {
856 // create a bogus element object representing the document object
858 var f = function() {};
859 f.prototype = El.prototype;
868 El.addToCache = function(el, id) {
880 // private method for getting and setting element data
881 El.data = function(el, key, value) {
886 var c = EC[el.id].data;
887 if (arguments.length == 2) {
890 return (c[key] = value);
895 // Garbage collection - uncache elements/purge listeners on orphaned elements
896 // so we don't hold a reference and cause the browser to retain them
897 function garbageCollect() {
898 if (!Ext.enableGarbageCollector) {
899 clearInterval(El.collectorThreadId);
907 if (!EC.hasOwnProperty(eid)) {
911 if (o.skipGarbageCollection) {
916 // -------------------------------------------------------
917 // Determining what is garbage:
918 // -------------------------------------------------------
920 // dom node is null, definitely garbage
921 // -------------------------------------------------------
923 // no parentNode == direct orphan, definitely garbage
924 // -------------------------------------------------------
925 // !d.offsetParent && !document.getElementById(eid)
926 // display none elements have no offsetParent so we will
927 // also try to look it up by it's id. However, check
928 // offsetParent first so we don't do unneeded lookups.
929 // This enables collection of elements that are not orphans
930 // directly, but somewhere up the line they have an orphan
932 // -------------------------------------------------------
933 if (!d || !d.parentNode || (!d.offsetParent && !DOC.getElementById(eid))) {
934 if (d && Ext.enableListenerCollection) {
935 Ext.EventManager.removeAll(d);
940 // Cleanup IE Object leaks
944 if (!EC.hasOwnProperty(eid)) {
953 El.collectorThreadId = setInterval(garbageCollect, 30000);
955 var flyFn = function() {};
956 flyFn.prototype = El.prototype;
959 El.Flyweight = function(dom) {
963 El.Flyweight.prototype = new flyFn();
964 El.Flyweight.prototype.isFlyweight = true;
968 * <p>Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
969 * the dom node can be overwritten by other code. Shorthand of {@link Ext.core.Element#fly}</p>
970 * <p>Use this to make one-time references to DOM elements which are not going to be accessed again either by
971 * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link Ext#get Ext.get}
972 * will be more appropriate to take advantage of the caching provided by the Ext.core.Element class.</p>
973 * @param {String/HTMLElement} el The dom node or id
974 * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts
975 * (e.g. internally Ext uses "_global")
976 * @return {Element} The shared Element object (or null if no matching element was found)
977 * @member Ext.core.Element
980 El.fly = function(el, named) {
982 named = named || '_global';
985 (El._flyweights[named] = El._flyweights[named] || new El.Flyweight()).dom = el;
986 ret = El._flyweights[named];
992 * Retrieves Ext.core.Element objects.
993 * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method
994 * retrieves Ext.core.Element objects which encapsulate DOM elements. To retrieve a Component by
995 * its ID, use {@link Ext.ComponentManager#get}.</p>
996 * <p>Uses simple caching to consistently return the same object. Automatically fixes if an
997 * object was recreated with the same id via AJAX or DOM.</p>
998 * Shorthand of {@link Ext.core.Element#get}
999 * @param {Mixed} el The id of the node, a DOM Node or an existing Element.
1000 * @return {Element} The Element object (or null if no matching element was found)
1007 * <p>Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
1008 * the dom node can be overwritten by other code. Shorthand of {@link Ext.core.Element#fly}</p>
1009 * <p>Use this to make one-time references to DOM elements which are not going to be accessed again either by
1010 * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link Ext#get Ext.get}
1011 * will be more appropriate to take advantage of the caching provided by the Ext.core.Element class.</p>
1012 * @param {String/HTMLElement} el The dom node or id
1013 * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts
1014 * (e.g. internally Ext uses "_global")
1015 * @return {Element} The shared Element object (or null if no matching element was found)
1021 // speedy lookup for elements never to box adjust
1022 var noBoxAdjust = Ext.isStrict ? {
1029 if (Ext.isIE || Ext.isGecko) {
1030 noBoxAdjust['button'] = 1;