4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-Element'>/**
19 </span> * @class Ext.Element
22 Ext.Element.addMethods((function(){
23 var focusRe = /button|input|textarea|select|object/;
25 <span id='Ext-Element-method-monitorMouseLeave'> /**
26 </span> * Monitors this Element for the mouse leaving. Calls the function after the specified delay only if
27 * the mouse was not moved back into the Element within the delay. If the mouse <i>was</i> moved
28 * back in, the function is not called.
29 * @param {Number} delay The delay <b>in milliseconds</b> to wait for possible mouse re-entry before calling the handler function.
30 * @param {Function} handler The function to call if the mouse remains outside of this Element for the specified time.
31 * @param {Object} scope The scope (<code>this</code> reference) in which the handler function executes. Defaults to this Element.
32 * @return {Object} The listeners object which was added to this element so that monitoring can be stopped. Example usage:<pre><code>
33 // Hide the menu if the mouse moves out for 250ms or more
34 this.mouseLeaveMonitor = this.menuEl.monitorMouseLeave(250, this.hideMenu, this);
37 // Remove mouseleave monitor on menu destroy
38 this.menuEl.un(this.mouseLeaveMonitor);
39 </code></pre>
41 monitorMouseLeave: function(delay, handler, scope) {
45 mouseleave: function(e) {
46 timer = setTimeout(Ext.Function.bind(handler, scope||me, [e]), delay);
48 mouseenter: function() {
58 <span id='Ext-Element-method-swallowEvent'> /**
59 </span> * Stops the specified event(s) from bubbling and optionally prevents the default action
60 * @param {String/String[]} eventName an event / array of events to stop from bubbling
61 * @param {Boolean} preventDefault (optional) true to prevent the default action too
62 * @return {Ext.Element} this
64 swallowEvent : function(eventName, preventDefault) {
73 if (Ext.isArray(eventName)) {
74 Ext.each(eventName, function(e) {
83 <span id='Ext-Element-method-relayEvent'> /**
84 </span> * Create an event handler on this element such that when the event fires and is handled by this element,
85 * it will be relayed to another object (i.e., fired again as if it originated from that object instead).
86 * @param {String} eventName The type of event to relay
87 * @param {Object} object Any object that extends {@link Ext.util.Observable} that will provide the context
88 * for firing the relayed event
90 relayEvent : function(eventName, observable) {
91 this.on(eventName, function(e) {
92 observable.fireEvent(eventName, e);
96 <span id='Ext-Element-method-clean'> /**
97 </span> * Removes Empty, or whitespace filled text nodes. Combines adjacent text nodes.
98 * @param {Boolean} forceReclean (optional) By default the element
99 * keeps track if it has been cleaned already so
100 * you can call this over and over. However, if you update the element and
101 * need to force a reclean, you can pass true.
103 clean : function(forceReclean) {
110 if (Ext.Element.data(dom, 'isCleaned') && forceReclean !== true) {
116 if (n.nodeType == 3) {
117 // Remove empty/whitespace text nodes
118 if (!(/\S/.test(n.nodeValue))) {
120 // Combine adjacent text nodes
121 } else if (nx && nx.nodeType == 3) {
122 n.appendData(Ext.String.trim(nx.data));
135 Ext.Element.data(dom, 'isCleaned', true);
139 <span id='Ext-Element-method-load'> /**
140 </span> * Direct access to the Ext.ElementLoader {@link Ext.ElementLoader#load} method. The method takes the same object
141 * parameter as {@link Ext.ElementLoader#load}
142 * @return {Ext.Element} this
144 load : function(options) {
145 this.getLoader().load(options);
149 <span id='Ext-Element-method-getLoader'> /**
150 </span> * Gets this element's {@link Ext.ElementLoader ElementLoader}
151 * @return {Ext.ElementLoader} The loader
153 getLoader : function() {
155 data = Ext.Element.data,
156 loader = data(dom, 'loader');
159 loader = Ext.create('Ext.ElementLoader', {
162 data(dom, 'loader', loader);
167 <span id='Ext-Element-method-update'> /**
168 </span> * Update the innerHTML of this element, optionally searching for and processing scripts
169 * @param {String} html The new HTML
170 * @param {Boolean} [loadScripts=false] True to look for and process scripts
171 * @param {Function} [callback] For async script loading you can be notified when the update completes
172 * @return {Ext.Element} this
174 update : function(html, loadScripts, callback) {
186 if (loadScripts !== true) {
187 dom.innerHTML = html;
188 Ext.callback(callback, me);
193 html += '<span id="' + id + '"></span>';
195 interval = setInterval(function(){
196 if (!document.getElementById(id)) {
199 clearInterval(interval);
201 hd = DOC.getElementsByTagName("head")[0],
202 re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig,
203 srcRe = /\ssrc=([\'\"])(.*?)\1/i,
204 typeRe = /\stype=([\'\"])(.*?)\1/i,
212 while ((match = re.exec(html))) {
214 srcMatch = attrs ? attrs.match(srcRe) : false;
215 if (srcMatch && srcMatch[2]) {
216 s = DOC.createElement("script");
218 typeMatch = attrs.match(typeRe);
219 if (typeMatch && typeMatch[2]) {
220 s.type = typeMatch[2];
223 } else if (match[2] && match[2].length > 0) {
224 if (window.execScript) {
225 window.execScript(match[2]);
227 window.eval(match[2]);
232 el = DOC.getElementById(id);
236 Ext.callback(callback, me);
238 dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, '');
242 // inherit docs, overridden so we can add removeAnchor
243 removeAllListeners : function() {
245 Ext.EventManager.removeAll(this.dom);
249 <span id='Ext-Element-method-getScopeParent'> /**
250 </span> * Gets the parent node of the current element taking into account Ext.scopeResetCSS
252 * @return {HTMLElement} The parent element
254 getScopeParent: function(){
255 var parent = this.dom.parentNode;
256 return Ext.scopeResetCSS ? parent.parentNode : parent;
259 <span id='Ext-Element-method-createProxy'> /**
260 </span> * Creates a proxy element of this element
261 * @param {String/Object} config The class name of the proxy element or a DomHelper config object
262 * @param {String/HTMLElement} [renderTo] The element or element id to render the proxy to (defaults to document.body)
263 * @param {Boolean} [matchBox=false] True to align and size the proxy to this element now.
264 * @return {Ext.Element} The new proxy element
266 createProxy : function(config, renderTo, matchBox) {
267 config = (typeof config == 'object') ? config : {tag : "div", cls: config};
270 proxy = renderTo ? Ext.DomHelper.append(renderTo, config, true) :
271 Ext.DomHelper.insertBefore(me.dom, config, true);
273 proxy.setVisibilityMode(Ext.Element.DISPLAY);
275 if (matchBox && me.setBox && me.getBox) { // check to make sure Element.position.js is loaded
276 proxy.setBox(me.getBox());
281 <span id='Ext-Element-method-focusable'> /**
282 </span> * Checks whether this element can be focused.
283 * @return {Boolean} True if the element is focusable
285 focusable: function(){
287 nodeName = dom.nodeName.toLowerCase(),
289 hasTabIndex = !isNaN(dom.tabIndex);
292 if (focusRe.test(nodeName)) {
295 canFocus = nodeName == 'a' ? dom.href || hasTabIndex : hasTabIndex;
298 return canFocus && this.isVisible(true);
302 Ext.Element.prototype.clearListeners = Ext.Element.prototype.removeAllListeners;