3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">/**
\r
10 * <p>Encapsulates a DOM element, adding simple DOM manipulation facilities, normalizing for browser differences.</p>
\r
11 * <p>All instances of this class inherit the methods of {@link Ext.Fx} making visual effects easily available to all DOM elements.</p>
\r
12 * <p>Note that the events documented in this class are not Ext events, they encapsulate browser events. To
\r
13 * access the underlying browser event, see {@link Ext.EventObject#browserEvent}. Some older
\r
14 * browsers may not support the full range of events. Which events are supported is beyond the control of ExtJs.</p>
\r
18 var el = Ext.get("my-div");
\r
20 // by DOM element reference
\r
21 var el = Ext.get(myDivElement);
\r
23 * <b>Animations</b><br />
\r
24 * <p>When an element is manipulated, by default there is no animation.</p>
\r
26 var el = Ext.get("my-div");
\r
31 * <p>Many of the functions for manipulating an element have an optional "animate" parameter. This
\r
32 * parameter can be specified as boolean (<tt>true</tt>) for default animation effects.</p>
\r
34 // default animation
\r
35 el.setWidth(100, true);
\r
38 * <p>To configure the effects, an object literal with animation options to use as the Element animation
\r
39 * configuration object can also be specified. Note that the supported Element animation configuration
\r
40 * options are a subset of the {@link Ext.Fx} animation options specific to Fx effects. The supported
\r
41 * Element animation configuration options are:</p>
\r
43 Option Default Description
\r
44 --------- -------- ---------------------------------------------
\r
45 {@link Ext.Fx#duration duration} .35 The duration of the animation in seconds
\r
46 {@link Ext.Fx#easing easing} easeOut The easing method
\r
47 {@link Ext.Fx#callback callback} none A function to execute when the anim completes
\r
48 {@link Ext.Fx#scope scope} this The scope (this) of the callback function
\r
52 // Element animation options object
\r
54 {@link Ext.Fx#duration duration}: 1,
\r
55 {@link Ext.Fx#easing easing}: 'elasticIn',
\r
56 {@link Ext.Fx#callback callback}: this.foo,
\r
57 {@link Ext.Fx#scope scope}: this
\r
59 // animation with some options set
\r
60 el.setWidth(100, opt);
\r
62 * <p>The Element animation object being used for the animation will be set on the options
\r
63 * object as "anim", which allows you to stop or manipulate the animation. Here is an example:</p>
\r
65 // using the "anim" property to get the Anim object
\r
66 if(opt.anim.isAnimated()){
\r
70 * <p>Also see the <tt>{@link #animate}</tt> method for another animation technique.</p>
\r
71 * <p><b> Composite (Collections of) Elements</b></p>
\r
72 * <p>For working with collections of Elements, see {@link Ext.CompositeElement}</p>
\r
73 * @constructor Create a new Element directly.
\r
74 * @param {String/HTMLElement} element
\r
75 * @param {Boolean} forceNew (optional) By default the constructor checks to see if there is already an instance of this element in the cache and if there is it returns the same instance. This will skip that check (useful for extending this class).
\r
80 Ext.Element = function(element, forceNew){
\r
81 var dom = typeof element == "string" ?
\r
82 DOC.getElementById(element) : element,
\r
85 if(!dom) return null;
\r
89 if(!forceNew && id && Ext.Element.cache[id]){ // element object already exists
\r
90 return Ext.Element.cache[id];
\r
93 <div id="prop-Ext.Element-dom"></div>/**
\r
99 <div id="prop-Ext.Element-id"></div>/**
\r
100 * The DOM element ID
\r
103 this.id = id || Ext.id(dom);
\r
106 var D = Ext.lib.Dom,
\r
107 DH = Ext.DomHelper,
\r
113 <div id="method-Ext.Element-set"></div>/**
\r
114 * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
\r
115 * @param {Object} o The object with the attributes
\r
116 * @param {Boolean} useSet (optional) false to override the default setAttribute to use expandos.
\r
117 * @return {Ext.Element} this
\r
119 set : function(o, useSet){
\r
126 if (attr != "style" && !Ext.isFunction(val)) {
\r
127 if (attr == "cls" ) {
\r
128 el.className = val;
\r
129 } else if (o.hasOwnProperty(attr)) {
\r
130 if (useSet || !!el.setAttribute) el.setAttribute(attr, val);
\r
131 else el[attr] = val;
\r
136 Ext.DomHelper.applyStyles(el, o.style);
\r
142 <div id="event-Ext.Element-click"></div>/**
\r
144 * Fires when a mouse click is detected within the element.
\r
145 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
146 * @param {HtmlElement} t The target of the event.
\r
147 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
149 <div id="event-Ext.Element-dblclick"></div>/**
\r
151 * Fires when a mouse double click is detected within the element.
\r
152 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
153 * @param {HtmlElement} t The target of the event.
\r
154 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
156 <div id="event-Ext.Element-mousedown"></div>/**
\r
158 * Fires when a mousedown is detected within the element.
\r
159 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
160 * @param {HtmlElement} t The target of the event.
\r
161 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
163 <div id="event-Ext.Element-mouseup"></div>/**
\r
165 * Fires when a mouseup is detected within the element.
\r
166 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
167 * @param {HtmlElement} t The target of the event.
\r
168 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
170 <div id="event-Ext.Element-mouseover"></div>/**
\r
172 * Fires when a mouseover is detected within the element.
\r
173 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
174 * @param {HtmlElement} t The target of the event.
\r
175 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
177 <div id="event-Ext.Element-mousemove"></div>/**
\r
179 * Fires when a mousemove is detected with the element.
\r
180 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
181 * @param {HtmlElement} t The target of the event.
\r
182 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
184 <div id="event-Ext.Element-mouseout"></div>/**
\r
186 * Fires when a mouseout is detected with the element.
\r
187 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
188 * @param {HtmlElement} t The target of the event.
\r
189 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
191 <div id="event-Ext.Element-mouseenter"></div>/**
\r
192 * @event mouseenter
\r
193 * Fires when the mouse enters the element.
\r
194 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
195 * @param {HtmlElement} t The target of the event.
\r
196 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
198 <div id="event-Ext.Element-mouseleave"></div>/**
\r
199 * @event mouseleave
\r
200 * Fires when the mouse leaves the element.
\r
201 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
202 * @param {HtmlElement} t The target of the event.
\r
203 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
207 <div id="event-Ext.Element-keypress"></div>/**
\r
209 * Fires when a keypress is detected within the element.
\r
210 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
211 * @param {HtmlElement} t The target of the event.
\r
212 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
214 <div id="event-Ext.Element-keydown"></div>/**
\r
216 * Fires when a keydown is detected within the element.
\r
217 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
218 * @param {HtmlElement} t The target of the event.
\r
219 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
221 <div id="event-Ext.Element-keyup"></div>/**
\r
223 * Fires when a keyup is detected within the element.
\r
224 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
225 * @param {HtmlElement} t The target of the event.
\r
226 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
230 // HTML frame/object events
\r
231 <div id="event-Ext.Element-load"></div>/**
\r
233 * Fires when the user agent finishes loading all content within the element. Only supported by window, frames, objects and images.
\r
234 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
235 * @param {HtmlElement} t The target of the event.
\r
236 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
238 <div id="event-Ext.Element-unload"></div>/**
\r
240 * Fires when the user agent removes all content from a window or frame. For elements, it fires when the target element or any of its content has been removed.
\r
241 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
242 * @param {HtmlElement} t The target of the event.
\r
243 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
245 <div id="event-Ext.Element-abort"></div>/**
\r
247 * Fires when an object/image is stopped from loading before completely loaded.
\r
248 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
249 * @param {HtmlElement} t The target of the event.
\r
250 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
252 <div id="event-Ext.Element-error"></div>/**
\r
254 * Fires when an object/image/frame cannot be loaded properly.
\r
255 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
256 * @param {HtmlElement} t The target of the event.
\r
257 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
259 <div id="event-Ext.Element-resize"></div>/**
\r
261 * Fires when a document view is resized.
\r
262 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
263 * @param {HtmlElement} t The target of the event.
\r
264 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
266 <div id="event-Ext.Element-scroll"></div>/**
\r
268 * Fires when a document view is scrolled.
\r
269 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
270 * @param {HtmlElement} t The target of the event.
\r
271 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
275 <div id="event-Ext.Element-select"></div>/**
\r
277 * Fires when a user selects some text in a text field, including input and textarea.
\r
278 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
279 * @param {HtmlElement} t The target of the event.
\r
280 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
282 <div id="event-Ext.Element-change"></div>/**
\r
284 * Fires when a control loses the input focus and its value has been modified since gaining focus.
\r
285 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
286 * @param {HtmlElement} t The target of the event.
\r
287 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
289 <div id="event-Ext.Element-submit"></div>/**
\r
291 * Fires when a form is submitted.
\r
292 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
293 * @param {HtmlElement} t The target of the event.
\r
294 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
296 <div id="event-Ext.Element-reset"></div>/**
\r
298 * Fires when a form is reset.
\r
299 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
300 * @param {HtmlElement} t The target of the event.
\r
301 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
303 <div id="event-Ext.Element-focus"></div>/**
\r
305 * Fires when an element receives focus either via the pointing device or by tab navigation.
\r
306 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
307 * @param {HtmlElement} t The target of the event.
\r
308 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
310 <div id="event-Ext.Element-blur"></div>/**
\r
312 * Fires when an element loses focus either via the pointing device or by tabbing navigation.
\r
313 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
314 * @param {HtmlElement} t The target of the event.
\r
315 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
318 // User Interface events
\r
319 <div id="event-Ext.Element-DOMFocusIn"></div>/**
\r
320 * @event DOMFocusIn
\r
321 * Where supported. Similar to HTML focus event, but can be applied to any focusable element.
\r
322 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
323 * @param {HtmlElement} t The target of the event.
\r
324 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
326 <div id="event-Ext.Element-DOMFocusOut"></div>/**
\r
327 * @event DOMFocusOut
\r
328 * Where supported. Similar to HTML blur event, but can be applied to any focusable element.
\r
329 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
330 * @param {HtmlElement} t The target of the event.
\r
331 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
333 <div id="event-Ext.Element-DOMActivate"></div>/**
\r
334 * @event DOMActivate
\r
335 * Where supported. Fires when an element is activated, for instance, through a mouse click or a keypress.
\r
336 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
337 * @param {HtmlElement} t The target of the event.
\r
338 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
341 // DOM Mutation events
\r
342 <div id="event-Ext.Element-DOMSubtreeModified"></div>/**
\r
343 * @event DOMSubtreeModified
\r
344 * Where supported. Fires when the subtree is modified.
\r
345 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
346 * @param {HtmlElement} t The target of the event.
\r
347 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
349 <div id="event-Ext.Element-DOMNodeInserted"></div>/**
\r
350 * @event DOMNodeInserted
\r
351 * Where supported. Fires when a node has been added as a child of another node.
\r
352 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
353 * @param {HtmlElement} t The target of the event.
\r
354 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
356 <div id="event-Ext.Element-DOMNodeRemoved"></div>/**
\r
357 * @event DOMNodeRemoved
\r
358 * Where supported. Fires when a descendant node of the element is removed.
\r
359 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
360 * @param {HtmlElement} t The target of the event.
\r
361 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
363 <div id="event-Ext.Element-DOMNodeRemovedFromDocument"></div>/**
\r
364 * @event DOMNodeRemovedFromDocument
\r
365 * Where supported. Fires when a node is being removed from a document.
\r
366 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
367 * @param {HtmlElement} t The target of the event.
\r
368 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
370 <div id="event-Ext.Element-DOMNodeInsertedIntoDocument"></div>/**
\r
371 * @event DOMNodeInsertedIntoDocument
\r
372 * Where supported. Fires when a node is being inserted into a document.
\r
373 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
374 * @param {HtmlElement} t The target of the event.
\r
375 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
377 <div id="event-Ext.Element-DOMAttrModified"></div>/**
\r
378 * @event DOMAttrModified
\r
379 * Where supported. Fires when an attribute has been modified.
\r
380 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
381 * @param {HtmlElement} t The target of the event.
\r
382 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
384 <div id="event-Ext.Element-DOMCharacterDataModified"></div>/**
\r
385 * @event DOMCharacterDataModified
\r
386 * Where supported. Fires when the character data has been modified.
\r
387 * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
\r
388 * @param {HtmlElement} t The target of the event.
\r
389 * @param {Object} o The options configuration passed to the {@link #addListener} call.
\r
392 <div id="prop-Ext.Element-defaultUnit"></div>/**
\r
393 * The default unit to append to CSS values where a unit isn't provided (defaults to px).
\r
396 defaultUnit : "px",
\r
398 <div id="method-Ext.Element-is"></div>/**
\r
399 * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
\r
400 * @param {String} selector The simple selector to test
\r
401 * @return {Boolean} True if this element matches the selector, else false
\r
403 is : function(simpleSelector){
\r
404 return Ext.DomQuery.is(this.dom, simpleSelector);
\r
407 <div id="method-Ext.Element-focus"></div>/**
\r
408 * Tries to focus the element. Any exceptions are caught and ignored.
\r
409 * @param {Number} defer (optional) Milliseconds to defer the focus
\r
410 * @return {Ext.Element} this
\r
412 focus : function(defer, /* private */ dom) {
\r
414 dom = dom || me.dom;
\r
417 me.focus.defer(defer, null, [null, dom]);
\r
425 <div id="method-Ext.Element-blur"></div>/**
\r
426 * Tries to blur the element. Any exceptions are caught and ignored.
\r
427 * @return {Ext.Element} this
\r
429 blur : function() {
\r
436 <div id="method-Ext.Element-getValue"></div>/**
\r
437 * Returns the value of the "value" attribute
\r
438 * @param {Boolean} asNumber true to parse the value as a number
\r
439 * @return {String/Number}
\r
441 getValue : function(asNumber){
\r
442 var val = this.dom.value;
\r
443 return asNumber ? parseInt(val, 10) : val;
\r
446 <div id="method-Ext.Element-addListener"></div>/**
\r
447 * Appends an event handler to this element. The shorthand version {@link #on} is equivalent.
\r
448 * @param {String} eventName The type of event to handle
\r
449 * @param {Function} fn The handler function the event invokes. This function is passed
\r
450 * the following parameters:<ul>
\r
451 * <li><b>evt</b> : EventObject<div class="sub-desc">The {@link Ext.EventObject EventObject} describing the event.</div></li>
\r
452 * <li><b>el</b> : Element<div class="sub-desc">The {@link Ext.Element Element} which was the target of the event.
\r
453 * Note that this may be filtered by using the <tt>delegate</tt> option.</div></li>
\r
454 * <li><b>o</b> : Object<div class="sub-desc">The options object from the addListener call.</div></li>
\r
456 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the handler function is executed.
\r
457 * <b>If omitted, defaults to this Element.</b>.
\r
458 * @param {Object} options (optional) An object containing handler configuration properties.
\r
459 * This may contain any of the following properties:<ul>
\r
460 * <li><b>scope</b> Object : <div class="sub-desc">The scope (<code><b>this</b></code> reference) in which the handler function is executed.
\r
461 * <b>If omitted, defaults to this Element.</b></div></li>
\r
462 * <li><b>delegate</b> String: <div class="sub-desc">A simple selector to filter the target or look for a descendant of the target. See below for additional details.</div></li>
\r
463 * <li><b>stopEvent</b> Boolean: <div class="sub-desc">True to stop the event. That is stop propagation, and prevent the default action.</div></li>
\r
464 * <li><b>preventDefault</b> Boolean: <div class="sub-desc">True to prevent the default action</div></li>
\r
465 * <li><b>stopPropagation</b> Boolean: <div class="sub-desc">True to prevent event propagation</div></li>
\r
466 * <li><b>normalized</b> Boolean: <div class="sub-desc">False to pass a browser event to the handler function instead of an Ext.EventObject</div></li>
\r
467 * <li><b>target</b> Ext.Element: <div class="sub-desc">Only call the handler if the event was fired on the target Element, <i>not</i> if the event was bubbled up from a child node.</div></li>
\r
468 * <li><b>delay</b> Number: <div class="sub-desc">The number of milliseconds to delay the invocation of the handler after the event fires.</div></li>
\r
469 * <li><b>single</b> Boolean: <div class="sub-desc">True to add a handler to handle just the next firing of the event, and then remove itself.</div></li>
\r
470 * <li><b>buffer</b> Number: <div class="sub-desc">Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed
\r
471 * by the specified number of milliseconds. If the event fires again within that time, the original
\r
472 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</div></li>
\r
475 * <b>Combining Options</b><br>
\r
476 * In the following examples, the shorthand form {@link #on} is used rather than the more verbose
\r
477 * addListener. The two are equivalent. Using the options argument, it is possible to combine different
\r
478 * types of listeners:<br>
\r
480 * A delayed, one-time listener that auto stops the event and adds a custom argument (forumId) to the
\r
481 * options object. The options object is available as the third parameter in the handler function.<div style="margin: 5px 20px 20px;">
\r
483 el.on('click', this.onClick, this, {
\r
488 });</code></pre></p>
\r
490 * <b>Attaching multiple handlers in 1 call</b><br>
\r
491 * The method also allows for a single argument to be passed which is a config object containing properties
\r
492 * which specify multiple handlers.</p>
\r
502 fn: this.onMouseOver,
\r
506 fn: this.onMouseOut,
\r
511 * Or a shorthand syntax:<br>
\r
512 * Code:<pre><code></p>
\r
514 'click' : this.onClick,
\r
515 'mouseover' : this.onMouseOver,
\r
516 'mouseout' : this.onMouseOut,
\r
519 * </code></pre></p>
\r
520 * <p><b>delegate</b></p>
\r
521 * <p>This is a configuration option that you can pass along when registering a handler for
\r
522 * an event to assist with event delegation. Event delegation is a technique that is used to
\r
523 * reduce memory consumption and prevent exposure to memory-leaks. By registering an event
\r
524 * for a container element as opposed to each element within a container. By setting this
\r
525 * configuration option to a simple selector, the target element will be filtered to look for
\r
526 * a descendant of the target.
\r
527 * For example:<pre><code>
\r
528 // using this markup:
\r
530 <p id='p1'>paragraph one</p>
\r
531 <p id='p2' class='clickable'>paragraph two</p>
\r
532 <p id='p3'>paragraph three</p>
\r
534 // utilize event delegation to registering just one handler on the container element:
\r
535 el = Ext.get('elId');
\r
540 console.info(t.id); // 'p2'
\r
544 // filter the target element to be a descendant with the class 'clickable'
\r
545 delegate: '.clickable'
\r
548 * </code></pre></p>
\r
549 * @return {Ext.Element} this
\r
551 addListener : function(eventName, fn, scope, options){
\r
552 Ext.EventManager.on(this.dom, eventName, fn, scope || this, options);
\r
556 <div id="method-Ext.Element-removeListener"></div>/**
\r
557 * Removes an event handler from this element. The shorthand version {@link #un} is equivalent.
\r
558 * <b>Note</b>: if a <i>scope</i> was explicitly specified when {@link #addListener adding} the
\r
559 * listener, the same scope must be specified here.
\r
562 el.removeListener('click', this.handlerFn);
\r
564 el.un('click', this.handlerFn);
\r
566 * @param {String} eventName the type of event to remove
\r
567 * @param {Function} fn the method the event invokes
\r
568 * @param {Object} scope (optional) The scope (The <tt>this</tt> reference) of the handler function. Defaults
\r
570 * @return {Ext.Element} this
\r
572 removeListener : function(eventName, fn, scope){
\r
573 Ext.EventManager.removeListener(this.dom, eventName, fn, scope || this);
\r
577 <div id="method-Ext.Element-removeAllListeners"></div>/**
\r
578 * Removes all previous added listeners from this element
\r
579 * @return {Ext.Element} this
\r
581 removeAllListeners : function(){
\r
582 Ext.EventManager.removeAll(this.dom);
\r
587 * @private Test if size has a unit, otherwise appends the default
\r
589 addUnits : function(size){
\r
590 if(size === "" || size == "auto" || size === undefined){
\r
592 } else if(!isNaN(size) || !unitPattern.test(size)){
\r
593 size = size + (this.defaultUnit || 'px');
\r
598 <div id="method-Ext.Element-load"></div>/**
\r
599 * <p>Updates the <a href="http://developer.mozilla.org/en/DOM/element.innerHTML">innerHTML</a> of this Element
\r
600 * from a specified URL. Note that this is subject to the <a href="http://en.wikipedia.org/wiki/Same_origin_policy">Same Origin Policy</a></p>
\r
601 * <p>Updating innerHTML of an element will <b>not</b> execute embedded <tt><script></tt> elements. This is a browser restriction.</p>
\r
602 * @param {Mixed} options. Either a sring containing the URL from which to load the HTML, or an {@link Ext.Ajax#request} options object specifying
\r
603 * exactly how to request the HTML.
\r
604 * @return {Ext.Element} this
\r
606 load : function(url, params, cb){
\r
607 Ext.Ajax.request(Ext.apply({
\r
609 url: url.url || url,
\r
612 indicatorText: url.indicatorText || ''
\r
613 }, Ext.isObject(url) ? url : {}));
\r
617 <div id="method-Ext.Element-isBorderBox"></div>/**
\r
618 * Tests various css rules/browsers to determine if this element uses a border box
\r
619 * @return {Boolean}
\r
621 isBorderBox : function(){
\r
622 return noBoxAdjust[(this.dom.tagName || "").toLowerCase()] || Ext.isBorderBox;
\r
625 <div id="method-Ext.Element-remove"></div>/**
\r
626 * Removes this element from the DOM and deletes it from the cache
\r
628 remove : function(){
\r
632 me.removeAllListeners();
\r
633 delete El.cache[dom.id];
\r
634 delete El.dataCache[dom.id]
\r
635 Ext.removeNode(dom);
\r
638 <div id="method-Ext.Element-hover"></div>/**
\r
639 * Sets up event handlers to call the passed functions when the mouse is moved into and out of the Element.
\r
640 * @param {Function} overFn The function to call when the mouse enters the Element.
\r
641 * @param {Function} outFn The function to call when the mouse leaves the Element.
\r
642 * @param {Object} scope (optional) The scope (<tt>this</tt> reference) in which the functions are executed. Defaults to the Element's DOM element.
\r
643 * @param {Object} options (optional) Options for the listener. See {@link Ext.util.Observable#addListener the <tt>options</tt> parameter}.
\r
644 * @return {Ext.Element} this
\r
646 hover : function(overFn, outFn, scope, options){
\r
648 me.on('mouseenter', overFn, scope || me.dom, options);
\r
649 me.on('mouseleave', outFn, scope || me.dom, options);
\r
653 <div id="method-Ext.Element-contains"></div>/**
\r
654 * Returns true if this element is an ancestor of the passed element
\r
655 * @param {HTMLElement/String} el The element to check
\r
656 * @return {Boolean} True if this element is an ancestor of el, else false
\r
658 contains : function(el){
\r
659 return !el ? false : Ext.lib.Dom.isAncestor(this.dom, el.dom ? el.dom : el);
\r
662 <div id="method-Ext.Element-getAttributeNS"></div>/**
\r
663 * Returns the value of a namespaced attribute from the element's underlying DOM node.
\r
664 * @param {String} namespace The namespace in which to look for the attribute
\r
665 * @param {String} name The attribute name
\r
666 * @return {String} The attribute value
\r
669 getAttributeNS : function(ns, name){
\r
670 return this.getAttribute(name, ns);
\r
673 <div id="method-Ext.Element-getAttribute"></div>/**
\r
674 * Returns the value of an attribute from the element's underlying DOM node.
\r
675 * @param {String} name The attribute name
\r
676 * @param {String} namespace (optional) The namespace in which to look for the attribute
\r
677 * @return {String} The attribute value
\r
679 getAttribute : Ext.isIE ? function(name, ns){
\r
681 type = typeof d[ns + ":" + name];
\r
683 if(['undefined', 'unknown'].indexOf(type) == -1){
\r
684 return d[ns + ":" + name];
\r
687 } : function(name, ns){
\r
689 return d.getAttributeNS(ns, name) || d.getAttribute(ns + ":" + name) || d.getAttribute(name) || d[name];
\r
692 <div id="method-Ext.Element-update"></div>/**
\r
693 * Update the innerHTML of this element
\r
694 * @param {String} html The new HTML
\r
695 * @return {Ext.Element} this
\r
697 update : function(html) {
\r
698 this.dom.innerHTML = html;
\r
703 var ep = El.prototype;
\r
705 El.addMethods = function(o){
\r
709 <div id="method-Ext.Element-on"></div>/**
\r
710 * Appends an event handler (shorthand for {@link #addListener}).
\r
711 * @param {String} eventName The type of event to handle
\r
712 * @param {Function} fn The handler function the event invokes
\r
713 * @param {Object} scope (optional) The scope (this element) of the handler function
\r
714 * @param {Object} options (optional) An object containing standard {@link #addListener} options
\r
715 * @member Ext.Element
\r
718 ep.on = ep.addListener;
\r
720 <div id="method-Ext.Element-un"></div>/**
\r
721 * Removes an event handler from this element (see {@link #removeListener} for additional notes).
\r
722 * @param {String} eventName the type of event to remove
\r
723 * @param {Function} fn the method the event invokes
\r
724 * @param {Object} scope (optional) The scope (The <tt>this</tt> reference) of the handler function. Defaults
\r
726 * @return {Ext.Element} this
\r
727 * @member Ext.Element
\r
730 ep.un = ep.removeListener;
\r
732 <div id="prop-Ext.Element-autoBoxAdjust"></div>/**
\r
733 * true to automatically adjust width and height settings for box-model issues (default to true)
\r
735 ep.autoBoxAdjust = true;
\r
738 var unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i,
\r
747 <div id="method-Ext.Element-get"></div>/**
\r
748 * Retrieves Ext.Element objects.
\r
749 * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method
\r
750 * retrieves Ext.Element objects which encapsulate DOM elements. To retrieve a Component by
\r
751 * its ID, use {@link Ext.ComponentMgr#get}.</p>
\r
752 * <p>Uses simple caching to consistently return the same object. Automatically fixes if an
\r
753 * object was recreated with the same id via AJAX or DOM.</p>
\r
754 * @param {Mixed} el The id of the node, a DOM Node or an existing Element.
\r
755 * @return {Element} The Element object (or null if no matching element was found)
\r
757 * @member Ext.Element
\r
760 El.get = function(el){
\r
764 if(!el){ return null; }
\r
765 if (typeof el == "string") { // element id
\r
766 if (!(elm = DOC.getElementById(el))) {
\r
769 if (ex = El.cache[el]) {
\r
772 ex = El.cache[el] = new El(elm);
\r
775 } else if (el.tagName) { // dom element
\r
779 if(ex = El.cache[id]){
\r
782 ex = El.cache[id] = new El(el);
\r
785 } else if (el instanceof El) {
\r
787 el.dom = DOC.getElementById(el.id) || el.dom; // refresh dom element in case no longer valid,
\r
788 // catch case where it hasn't been appended
\r
789 El.cache[el.id] = el; // in case it was created directly with Element(), let's cache it
\r
792 } else if(el.isComposite) {
\r
794 } else if(Ext.isArray(el)) {
\r
795 return El.select(el);
\r
796 } else if(el == DOC) {
\r
797 // create a bogus element object representing the document object
\r
799 var f = function(){};
\r
800 f.prototype = El.prototype;
\r
809 // private method for getting and setting element data
\r
810 El.data = function(el, key, value){
\r
811 var c = El.dataCache[el.id];
\r
813 c = El.dataCache[el.id] = {};
\r
815 if(arguments.length == 2){
\r
823 // Garbage collection - uncache elements/purge listeners on orphaned elements
\r
824 // so we don't hold a reference and cause the browser to retain them
\r
825 function garbageCollect(){
\r
826 if(!Ext.enableGarbageCollector){
\r
827 clearInterval(El.collectorThread);
\r
833 for(eid in El.cache){
\r
834 el = El.cache[eid];
\r
836 // -------------------------------------------------------
\r
837 // Determining what is garbage:
\r
838 // -------------------------------------------------------
\r
840 // dom node is null, definitely garbage
\r
841 // -------------------------------------------------------
\r
843 // no parentNode == direct orphan, definitely garbage
\r
844 // -------------------------------------------------------
\r
845 // !d.offsetParent && !document.getElementById(eid)
\r
846 // display none elements have no offsetParent so we will
\r
847 // also try to look it up by it's id. However, check
\r
848 // offsetParent first so we don't do unneeded lookups.
\r
849 // This enables collection of elements that are not orphans
\r
850 // directly, but somewhere up the line they have an orphan
\r
852 // -------------------------------------------------------
\r
853 if(!d || !d.parentNode || (!d.offsetParent && !DOC.getElementById(eid))){
\r
854 delete El.cache[eid];
\r
855 if(d && Ext.enableListenerCollection){
\r
856 Ext.EventManager.removeAll(d);
\r
862 El.collectorThreadId = setInterval(garbageCollect, 30000);
\r
864 var flyFn = function(){};
\r
865 flyFn.prototype = El.prototype;
\r
868 El.Flyweight = function(dom){
\r
872 El.Flyweight.prototype = new flyFn();
\r
873 El.Flyweight.prototype.isFlyweight = true;
\r
874 El._flyweights = {};
\r
876 <div id="method-Ext.Element-fly"></div>/**
\r
877 * <p>Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
\r
878 * the dom node can be overwritten by other code. Shorthand of {@link Ext.Element#fly}</p>
\r
879 * <p>Use this to make one-time references to DOM elements which are not going to be accessed again either by
\r
880 * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link Ext#get}
\r
881 * will be more appropriate to take advantage of the caching provided by the Ext.Element class.</p>
\r
882 * @param {String/HTMLElement} el The dom node or id
\r
883 * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts
\r
884 * (e.g. internally Ext uses "_global")
\r
885 * @return {Element} The shared Element object (or null if no matching element was found)
\r
886 * @member Ext.Element
\r
889 El.fly = function(el, named){
\r
891 named = named || '_global';
\r
893 if (el = Ext.getDom(el)) {
\r
894 (El._flyweights[named] = El._flyweights[named] || new El.Flyweight()).dom = el;
\r
895 ret = El._flyweights[named];
\r
900 <div id="method-Ext-get"></div>/**
\r
901 * Retrieves Ext.Element objects.
\r
902 * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method
\r
903 * retrieves Ext.Element objects which encapsulate DOM elements. To retrieve a Component by
\r
904 * its ID, use {@link Ext.ComponentMgr#get}.</p>
\r
905 * <p>Uses simple caching to consistently return the same object. Automatically fixes if an
\r
906 * object was recreated with the same id via AJAX or DOM.</p>
\r
907 * Shorthand of {@link Ext.Element#get}
\r
908 * @param {Mixed} el The id of the node, a DOM Node or an existing Element.
\r
909 * @return {Element} The Element object (or null if no matching element was found)
\r
915 <div id="method-Ext-fly"></div>/**
\r
916 * <p>Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
\r
917 * the dom node can be overwritten by other code. Shorthand of {@link Ext.Element#fly}</p>
\r
918 * <p>Use this to make one-time references to DOM elements which are not going to be accessed again either by
\r
919 * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link Ext#get}
\r
920 * will be more appropriate to take advantage of the caching provided by the Ext.Element class.</p>
\r
921 * @param {String/HTMLElement} el The dom node or id
\r
922 * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts
\r
923 * (e.g. internally Ext uses "_global")
\r
924 * @return {Element} The shared Element object (or null if no matching element was found)
\r
930 // speedy lookup for elements never to box adjust
\r
931 var noBoxAdjust = Ext.isStrict ? {
\r
934 input:1, select:1, textarea:1
\r
936 if(Ext.isIE || Ext.isGecko){
\r
937 noBoxAdjust['button'] = 1;
\r
941 Ext.EventManager.on(window, 'unload', function(){
\r
943 delete El.dataCache;
\r
944 delete El._flyweights;
\r