2 * @class Ext.core.Element
3 * <p>Encapsulates a DOM element, adding simple DOM manipulation facilities, normalizing for browser differences.</p>
4 * <p>All instances of this class inherit the methods of {@link Ext.fx.Anim} making visual effects easily available to all DOM elements.</p>
5 * <p>Note that the events documented in this class are not Ext events, they encapsulate browser events. To
6 * access the underlying browser event, see {@link Ext.EventObject#browserEvent}. Some older
7 * browsers may not support the full range of events. Which events are supported is beyond the control of ExtJs.</p>
11 var el = Ext.get("my-div");
13 // by DOM element reference
14 var el = Ext.get(myDivElement);
16 * <b>Animations</b><br />
17 * <p>When an element is manipulated, by default there is no animation.</p>
19 var el = Ext.get("my-div");
24 * <p>Many of the functions for manipulating an element have an optional "animate" parameter. This
25 * parameter can be specified as boolean (<tt>true</tt>) for default animation effects.</p>
28 el.setWidth(100, true);
31 * <p>To configure the effects, an object literal with animation options to use as the Element animation
32 * configuration object can also be specified. Note that the supported Element animation configuration
33 * options are a subset of the {@link Ext.fx.Anim} animation options specific to Fx effects. The supported
34 * Element animation configuration options are:</p>
36 Option Default Description
37 --------- -------- ---------------------------------------------
38 {@link Ext.fx.Anim#duration duration} .35 The duration of the animation in seconds
39 {@link Ext.fx.Anim#easing easing} easeOut The easing method
40 {@link Ext.fx.Anim#callback callback} none A function to execute when the anim completes
41 {@link Ext.fx.Anim#scope scope} this The scope (this) of the callback function
45 // Element animation options object
47 {@link Ext.fx.Anim#duration duration}: 1,
48 {@link Ext.fx.Anim#easing easing}: 'elasticIn',
49 {@link Ext.fx.Anim#callback callback}: this.foo,
50 {@link Ext.fx.Anim#scope scope}: this
52 // animation with some options set
53 el.setWidth(100, opt);
55 * <p>The Element animation object being used for the animation will be set on the options
56 * object as "anim", which allows you to stop or manipulate the animation. Here is an example:</p>
58 // using the "anim" property to get the Anim object
59 if(opt.anim.isAnimated()){
63 * <p>Also see the <tt>{@link #animate}</tt> method for another animation technique.</p>
64 * <p><b> Composite (Collections of) Elements</b></p>
65 * <p>For working with collections of Elements, see {@link Ext.CompositeElement}</p>
66 * @constructor Create a new Element directly.
67 * @param {String/HTMLElement} element
68 * @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).
74 Ext.Element = Ext.core.Element = function(element, forceNew) {
75 var dom = typeof element == "string" ? DOC.getElementById(element) : element,
84 if (!forceNew && id && EC[id]) {
85 // element object already exists
99 this.id = id || Ext.id(dom);
102 var DH = Ext.core.DomHelper,
103 El = Ext.core.Element;
108 * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
109 * @param {Object} o The object with the attributes
110 * @param {Boolean} useSet (optional) false to override the default setAttribute to use expandos.
111 * @return {Ext.core.Element} this
113 set: function(o, useSet) {
117 useSet = (useSet !== false) && !!el.setAttribute;
120 if (o.hasOwnProperty(attr)) {
122 if (attr == 'style') {
123 DH.applyStyles(el, val);
124 } else if (attr == 'cls') {
127 el.setAttribute(attr, val);
139 * Fires when a mouse click is detected within the element.
140 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
141 * @param {HtmlElement} t The target of the event.
142 * @param {Object} o The options configuration passed to the {@link #addListener} call.
146 * Fires when a right click is detected within the element.
147 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
148 * @param {HtmlElement} t The target of the event.
149 * @param {Object} o The options configuration passed to the {@link #addListener} call.
153 * Fires when a mouse double 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 mousedown 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 mouseup 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 mouseover 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 mousemove is detected with 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 mouseout is detected with 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 the mouse enters 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 the mouse leaves 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.
211 * Fires when a keypress is detected within the element.
212 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
213 * @param {HtmlElement} t The target of the event.
214 * @param {Object} o The options configuration passed to the {@link #addListener} call.
218 * Fires when a keydown is detected within the element.
219 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
220 * @param {HtmlElement} t The target of the event.
221 * @param {Object} o The options configuration passed to the {@link #addListener} call.
225 * Fires when a keyup 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 // HTML frame/object events
235 * Fires when the user agent finishes loading all content within the element. Only supported by window, frames, objects and images.
236 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
237 * @param {HtmlElement} t The target of the event.
238 * @param {Object} o The options configuration passed to the {@link #addListener} call.
242 * 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.
243 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
244 * @param {HtmlElement} t The target of the event.
245 * @param {Object} o The options configuration passed to the {@link #addListener} call.
249 * Fires when an object/image is stopped from loading before completely loaded.
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 an object/image/frame cannot be loaded properly.
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 a document view is resized.
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 a document view is scrolled.
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.
279 * Fires when a user selects some text in a text field, including input and textarea.
280 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
281 * @param {HtmlElement} t The target of the event.
282 * @param {Object} o The options configuration passed to the {@link #addListener} call.
286 * Fires when a control loses the input focus and its value has been modified since gaining focus.
287 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
288 * @param {HtmlElement} t The target of the event.
289 * @param {Object} o The options configuration passed to the {@link #addListener} call.
293 * Fires when a form is submitted.
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 form is reset.
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 an element receives focus either via the pointing device or by tab navigation.
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 an element loses focus either via the pointing device or by tabbing navigation.
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.
320 // User Interface events
323 * Where supported. Similar to HTML focus event, but can be applied to any focusable element.
324 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
325 * @param {HtmlElement} t The target of the event.
326 * @param {Object} o The options configuration passed to the {@link #addListener} call.
330 * Where supported. Similar to HTML blur event, but can be applied to any focusable element.
331 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
332 * @param {HtmlElement} t The target of the event.
333 * @param {Object} o The options configuration passed to the {@link #addListener} call.
337 * Where supported. Fires when an element is activated, for instance, through a mouse click or a keypress.
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.
343 // DOM Mutation events
345 * @event DOMSubtreeModified
346 * Where supported. Fires when the subtree is modified.
347 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
348 * @param {HtmlElement} t The target of the event.
349 * @param {Object} o The options configuration passed to the {@link #addListener} call.
352 * @event DOMNodeInserted
353 * Where supported. Fires when a node has been added as a child of another node.
354 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
355 * @param {HtmlElement} t The target of the event.
356 * @param {Object} o The options configuration passed to the {@link #addListener} call.
359 * @event DOMNodeRemoved
360 * Where supported. Fires when a descendant node of the element is removed.
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 DOMNodeRemovedFromDocument
367 * Where supported. Fires when a node is being removed from a document.
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 DOMNodeInsertedIntoDocument
374 * Where supported. Fires when a node is being inserted into a document.
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 DOMAttrModified
381 * Where supported. Fires when an attribute has been modified.
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 DOMCharacterDataModified
388 * Where supported. Fires when the character data has been modified.
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.
395 * The default unit to append to CSS values where a unit isn't provided (defaults to px).
401 * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
402 * @param {String} selector The simple selector to test
403 * @return {Boolean} True if this element matches the selector, else false
405 is: function(simpleSelector) {
406 return Ext.DomQuery.is(this.dom, simpleSelector);
410 * Tries to focus the element. Any exceptions are caught and ignored.
411 * @param {Number} defer (optional) Milliseconds to defer the focus
412 * @return {Ext.core.Element} this
414 focus: function(defer,
421 Ext.defer(me.focus, defer, null, [null, dom]);
430 * Tries to blur the element. Any exceptions are caught and ignored.
431 * @return {Ext.core.Element} this
441 * Returns the value of the "value" attribute
442 * @param {Boolean} asNumber true to parse the value as a number
443 * @return {String/Number}
445 getValue: function(asNumber) {
446 var val = this.dom.value;
447 return asNumber ? parseInt(val, 10) : val;
451 * Appends an event handler to this element. The shorthand version {@link #on} is equivalent.
452 * @param {String} eventName The name of event to handle.
453 * @param {Function} fn The handler function the event invokes. This function is passed
454 * the following parameters:<ul>
455 * <li><b>evt</b> : EventObject<div class="sub-desc">The {@link Ext.EventObject EventObject} describing the event.</div></li>
456 * <li><b>el</b> : HtmlElement<div class="sub-desc">The DOM element which was the target of the event.
457 * Note that this may be filtered by using the <tt>delegate</tt> option.</div></li>
458 * <li><b>o</b> : Object<div class="sub-desc">The options object from the addListener call.</div></li>
460 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the handler function is executed.
461 * <b>If omitted, defaults to this Element.</b>.
462 * @param {Object} options (optional) An object containing handler configuration properties.
463 * This may contain any of the following properties:<ul>
464 * <li><b>scope</b> Object : <div class="sub-desc">The scope (<code><b>this</b></code> reference) in which the handler function is executed.
465 * <b>If omitted, defaults to this Element.</b></div></li>
466 * <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>
467 * <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>
468 * <li><b>preventDefault</b> Boolean: <div class="sub-desc">True to prevent the default action</div></li>
469 * <li><b>stopPropagation</b> Boolean: <div class="sub-desc">True to prevent event propagation</div></li>
470 * <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>
471 * <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>
472 * <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>
473 * <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>
474 * <li><b>buffer</b> Number: <div class="sub-desc">Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed
475 * by the specified number of milliseconds. If the event fires again within that time, the original
476 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</div></li>
479 * <b>Combining Options</b><br>
480 * In the following examples, the shorthand form {@link #on} is used rather than the more verbose
481 * addListener. The two are equivalent. Using the options argument, it is possible to combine different
482 * types of listeners:<br>
484 * A delayed, one-time listener that auto stops the event and adds a custom argument (forumId) to the
485 * options object. The options object is available as the third parameter in the handler function.<div style="margin: 5px 20px 20px;">
487 el.on('click', this.onClick, this, {
494 * <b>Attaching multiple handlers in 1 call</b><br>
495 * The method also allows for a single argument to be passed which is a config object containing properties
496 * which specify multiple handlers.</p>
506 fn: this.onMouseOver,
515 * Or a shorthand syntax:<br>
516 * Code:<pre><code></p>
518 'click' : this.onClick,
519 'mouseover' : this.onMouseOver,
520 'mouseout' : this.onMouseOut,
524 * <p><b>delegate</b></p>
525 * <p>This is a configuration option that you can pass along when registering a handler for
526 * an event to assist with event delegation. Event delegation is a technique that is used to
527 * reduce memory consumption and prevent exposure to memory-leaks. By registering an event
528 * for a container element as opposed to each element within a container. By setting this
529 * configuration option to a simple selector, the target element will be filtered to look for
530 * a descendant of the target.
531 * For example:<pre><code>
532 // using this markup:
534 <p id='p1'>paragraph one</p>
535 <p id='p2' class='clickable'>paragraph two</p>
536 <p id='p3'>paragraph three</p>
538 // utilize event delegation to registering just one handler on the container element:
539 el = Ext.get('elId');
544 console.info(t.id); // 'p2'
548 // filter the target element to be a descendant with the class 'clickable'
549 delegate: '.clickable'
553 * @return {Ext.core.Element} this
555 addListener: function(eventName, fn, scope, options) {
556 Ext.EventManager.on(this.dom, eventName, fn, scope || this, options);
561 * Removes an event handler from this element. The shorthand version {@link #un} is equivalent.
562 * <b>Note</b>: if a <i>scope</i> was explicitly specified when {@link #addListener adding} the
563 * listener, the same scope must be specified here.
566 el.removeListener('click', this.handlerFn);
568 el.un('click', this.handlerFn);
570 * @param {String} eventName The name of the event from which to remove the handler.
571 * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
572 * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
573 * then this must refer to the same object.
574 * @return {Ext.core.Element} this
576 removeListener: function(eventName, fn, scope) {
577 Ext.EventManager.un(this.dom, eventName, fn, scope || this);
582 * Removes all previous added listeners from this element
583 * @return {Ext.core.Element} this
585 removeAllListeners: function() {
586 Ext.EventManager.removeAll(this.dom);
591 * Recursively removes all previous added listeners from this element and its children
592 * @return {Ext.core.Element} this
594 purgeAllListeners: function() {
595 Ext.EventManager.purgeElement(this);
600 * @private Test if size has a unit, otherwise appends the passed unit string, or the default for this Element.
601 * @param size {Mixed} The size to set
602 * @param units {String} The units to append to a numeric size value
604 addUnits: function(size, units) {
606 // Most common case first: Size is set to a number
607 if (Ext.isNumber(size)) {
608 return size + (units || this.defaultUnit || 'px');
611 // Size set to a value which means "auto"
612 if (size === "" || size == "auto" || size === undefined || size === null) {
616 // Otherwise, warn if it's not a valid CSS measurement
617 if (!unitPattern.test(size)) {
619 if (Ext.isDefined(Ext.global.console)) {
620 Ext.global.console.warn("Warning, size detected as NaN on Element.addUnits.");
629 * Tests various css rules/browsers to determine if this element uses a border box
632 isBorderBox: function() {
633 return Ext.isBorderBox || noBoxAdjust[(this.dom.tagName || "").toLowerCase()];
637 * <p>Removes this element's dom reference. Note that event and cache removal is handled at {@link Ext#removeNode Ext.removeNode}</p>
650 * Sets up event handlers to call the passed functions when the mouse is moved into and out of the Element.
651 * @param {Function} overFn The function to call when the mouse enters the Element.
652 * @param {Function} outFn The function to call when the mouse leaves the Element.
653 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the functions are executed. Defaults to the Element's DOM element.
654 * @param {Object} options (optional) Options for the listener. See {@link Ext.util.Observable#addListener the <tt>options</tt> parameter}.
655 * @return {Ext.core.Element} this
657 hover: function(overFn, outFn, scope, options) {
659 me.on('mouseenter', overFn, scope || me.dom, options);
660 me.on('mouseleave', outFn, scope || me.dom, options);
665 * Returns true if this element is an ancestor of the passed element
666 * @param {HTMLElement/String} el The element to check
667 * @return {Boolean} True if this element is an ancestor of el, else false
669 contains: function(el) {
670 return ! el ? false: Ext.core.Element.isAncestor(this.dom, el.dom ? el.dom: el);
674 * Returns the value of a namespaced attribute from the element's underlying DOM node.
675 * @param {String} namespace The namespace in which to look for the attribute
676 * @param {String} name The attribute name
677 * @return {String} The attribute value
680 getAttributeNS: function(ns, name) {
681 return this.getAttribute(name, ns);
685 * Returns the value of an attribute from the element's underlying DOM node.
686 * @param {String} name The attribute name
687 * @param {String} namespace (optional) The namespace in which to look for the attribute
688 * @return {String} The attribute value
691 getAttribute: (Ext.isIE && !(Ext.isIE9 && document.documentMode === 9)) ?
696 type = typeof d[ns + ":" + name];
697 if (type != 'undefined' && type != 'unknown') {
698 return d[ns + ":" + name] || null;
702 if (name === "for") {
705 return d[name] || null;
706 }: function(name, ns) {
709 return d.getAttributeNS(ns, name) || d.getAttribute(ns + ":" + name);
711 return d.getAttribute(name) || d[name] || null;
715 * Update the innerHTML of this element
716 * @param {String} html The new HTML
717 * @return {Ext.core.Element} this
719 update: function(html) {
721 this.dom.innerHTML = html;
727 var ep = El.prototype;
729 El.addMethods = function(o) {
734 * Appends an event handler (shorthand for {@link #addListener}).
735 * @param {String} eventName The name of event to handle.
736 * @param {Function} fn The handler function the event invokes.
737 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function is executed.
738 * @param {Object} options (optional) An object containing standard {@link #addListener} options
739 * @member Ext.core.Element
742 ep.on = ep.addListener;
745 * Removes an event handler from this element (see {@link #removeListener} for additional notes).
746 * @param {String} eventName The name of the event from which to remove the handler.
747 * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
748 * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
749 * then this must refer to the same object.
750 * @return {Ext.core.Element} this
751 * @member Ext.core.Element
754 ep.un = ep.removeListener;
757 * Removes all previous added listeners from this element
758 * @return {Ext.core.Element} this
759 * @member Ext.core.Element
760 * @method clearListeners
762 ep.clearListeners = ep.removeAllListeners;
765 * Removes this element's dom reference. Note that event and cache removal is handled at {@link Ext#removeNode Ext.removeNode}.
766 * Alias to {@link #remove}.
767 * @member Ext.core.Element
770 ep.destroy = ep.remove;
773 * true to automatically adjust width and height settings for box-model issues (default to true)
775 ep.autoBoxAdjust = true;
778 var unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i,
782 * Retrieves Ext.core.Element objects.
783 * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method
784 * retrieves Ext.core.Element objects which encapsulate DOM elements. To retrieve a Component by
785 * its ID, use {@link Ext.ComponentManager#get}.</p>
786 * <p>Uses simple caching to consistently return the same object. Automatically fixes if an
787 * object was recreated with the same id via AJAX or DOM.</p>
788 * @param {Mixed} el The id of the node, a DOM Node or an existing Element.
789 * @return {Element} The Element object (or null if no matching element was found)
791 * @member Ext.core.Element
794 El.get = function(el) {
801 if (typeof el == "string") {
803 if (! (elm = DOC.getElementById(el))) {
806 if (EC[el] && EC[el].el) {
810 ex = El.addToCache(new El(elm));
813 } else if (el.tagName) {
815 if (! (id = el.id)) {
818 if (EC[id] && EC[id].el) {
822 ex = El.addToCache(new El(el));
825 } else if (el instanceof El) {
827 // refresh dom element in case no longer valid,
828 // catch case where it hasn't been appended
829 // If an el instance is passed, don't pass to getElementById without some kind of id
830 if (Ext.isIE && (el.id == undefined || el.id == '')) {
833 el.dom = DOC.getElementById(el.id) || el.dom;
837 } else if (el.isComposite) {
839 } else if (Ext.isArray(el)) {
840 return El.select(el);
841 } else if (el == DOC) {
842 // create a bogus element object representing the document object
844 var f = function() {};
845 f.prototype = El.prototype;
854 El.addToCache = function(el, id) {
866 // private method for getting and setting element data
867 El.data = function(el, key, value) {
872 var c = EC[el.id].data;
873 if (arguments.length == 2) {
876 return (c[key] = value);
881 // Garbage collection - uncache elements/purge listeners on orphaned elements
882 // so we don't hold a reference and cause the browser to retain them
883 function garbageCollect() {
884 if (!Ext.enableGarbageCollector) {
885 clearInterval(El.collectorThreadId);
893 if (!EC.hasOwnProperty(eid)) {
897 if (o.skipGarbageCollection) {
902 // -------------------------------------------------------
903 // Determining what is garbage:
904 // -------------------------------------------------------
906 // dom node is null, definitely garbage
907 // -------------------------------------------------------
909 // no parentNode == direct orphan, definitely garbage
910 // -------------------------------------------------------
911 // !d.offsetParent && !document.getElementById(eid)
912 // display none elements have no offsetParent so we will
913 // also try to look it up by it's id. However, check
914 // offsetParent first so we don't do unneeded lookups.
915 // This enables collection of elements that are not orphans
916 // directly, but somewhere up the line they have an orphan
918 // -------------------------------------------------------
919 if (!d || !d.parentNode || (!d.offsetParent && !DOC.getElementById(eid))) {
920 if (d && Ext.enableListenerCollection) {
921 Ext.EventManager.removeAll(d);
926 // Cleanup IE Object leaks
930 if (!EC.hasOwnProperty(eid)) {
939 El.collectorThreadId = setInterval(garbageCollect, 30000);
941 var flyFn = function() {};
942 flyFn.prototype = El.prototype;
945 El.Flyweight = function(dom) {
949 El.Flyweight.prototype = new flyFn();
950 El.Flyweight.prototype.isFlyweight = true;
954 * <p>Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
955 * the dom node can be overwritten by other code. Shorthand of {@link Ext.core.Element#fly}</p>
956 * <p>Use this to make one-time references to DOM elements which are not going to be accessed again either by
957 * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link Ext#get Ext.get}
958 * will be more appropriate to take advantage of the caching provided by the Ext.core.Element class.</p>
959 * @param {String/HTMLElement} el The dom node or id
960 * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts
961 * (e.g. internally Ext uses "_global")
962 * @return {Element} The shared Element object (or null if no matching element was found)
963 * @member Ext.core.Element
966 El.fly = function(el, named) {
968 named = named || '_global';
971 (El._flyweights[named] = El._flyweights[named] || new El.Flyweight()).dom = el;
972 ret = El._flyweights[named];
978 * Retrieves Ext.core.Element objects.
979 * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method
980 * retrieves Ext.core.Element objects which encapsulate DOM elements. To retrieve a Component by
981 * its ID, use {@link Ext.ComponentManager#get}.</p>
982 * <p>Uses simple caching to consistently return the same object. Automatically fixes if an
983 * object was recreated with the same id via AJAX or DOM.</p>
984 * Shorthand of {@link Ext.core.Element#get}
985 * @param {Mixed} el The id of the node, a DOM Node or an existing Element.
986 * @return {Element} The Element object (or null if no matching element was found)
993 * <p>Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
994 * the dom node can be overwritten by other code. Shorthand of {@link Ext.core.Element#fly}</p>
995 * <p>Use this to make one-time references to DOM elements which are not going to be accessed again either by
996 * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link Ext#get Ext.get}
997 * will be more appropriate to take advantage of the caching provided by the Ext.core.Element class.</p>
998 * @param {String/HTMLElement} el The dom node or id
999 * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts
1000 * (e.g. internally Ext uses "_global")
1001 * @return {Element} The shared Element object (or null if no matching element was found)
1007 // speedy lookup for elements never to box adjust
1008 var noBoxAdjust = Ext.isStrict ? {
1015 if (Ext.isIE || Ext.isGecko) {
1016 noBoxAdjust['button'] = 1;