4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../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-core-Element'>/**
19 </span> * @class Ext.core.Element
22 Ext.core.Element.addMethods({
24 <span id='Ext-core-Element-method-monitorMouseLeave'> /**
25 </span> * Monitors this Element for the mouse leaving. Calls the function after the specified delay only if
26 * the mouse was not moved back into the Element within the delay. If the mouse <i>was</i> moved
27 * back in, the function is not called.
28 * @param {Number} delay The delay <b>in milliseconds</b> to wait for possible mouse re-entry before calling the handler function.
29 * @param {Function} handler The function to call if the mouse remains outside of this Element for the specified time.
30 * @param {Object} scope The scope (<code>this</code> reference) in which the handler function executes. Defaults to this Element.
31 * @return {Object} The listeners object which was added to this element so that monitoring can be stopped. Example usage:</pre><code>
32 // Hide the menu if the mouse moves out for 250ms or more
33 this.mouseLeaveMonitor = this.menuEl.monitorMouseLeave(250, this.hideMenu, this);
36 // Remove mouseleave monitor on menu destroy
37 this.menuEl.un(this.mouseLeaveMonitor);
38 </code></pre>
40 monitorMouseLeave: function(delay, handler, scope) {
44 mouseleave: function(e) {
45 timer = setTimeout(Ext.Function.bind(handler, scope||me, [e]), delay);
47 mouseenter: function() {
57 <span id='Ext-core-Element-method-swallowEvent'> /**
58 </span> * Stops the specified event(s) from bubbling and optionally prevents the default action
59 * @param {String/Array} eventName an event / array of events to stop from bubbling
60 * @param {Boolean} preventDefault (optional) true to prevent the default action too
61 * @return {Ext.core.Element} this
63 swallowEvent : function(eventName, preventDefault) {
72 if (Ext.isArray(eventName)) {
73 Ext.each(eventName, function(e) {
82 <span id='Ext-core-Element-method-relayEvent'> /**
83 </span> * Create an event handler on this element such that when the event fires and is handled by this element,
84 * it will be relayed to another object (i.e., fired again as if it originated from that object instead).
85 * @param {String} eventName The type of event to relay
86 * @param {Object} object Any object that extends {@link Ext.util.Observable} that will provide the context
87 * for firing the relayed event
89 relayEvent : function(eventName, observable) {
90 this.on(eventName, function(e) {
91 observable.fireEvent(eventName, e);
95 <span id='Ext-core-Element-method-clean'> /**
96 </span> * Removes Empty, or whitespace filled text nodes. Combines adjacent text nodes.
97 * @param {Boolean} forceReclean (optional) By default the element
98 * keeps track if it has been cleaned already so
99 * you can call this over and over. However, if you update the element and
100 * need to force a reclean, you can pass true.
102 clean : function(forceReclean) {
109 if (Ext.core.Element.data(dom, 'isCleaned') && forceReclean !== true) {
115 if (n.nodeType == 3) {
116 // Remove empty/whitespace text nodes
117 if (!(/\S/.test(n.nodeValue))) {
119 // Combine adjacent text nodes
120 } else if (nx && nx.nodeType == 3) {
121 n.appendData(Ext.String.trim(nx.data));
134 Ext.core.Element.data(dom, 'isCleaned', true);
138 <span id='Ext-core-Element-method-load'> /**
139 </span> * Direct access to the Ext.ElementLoader {@link Ext.ElementLoader#load} method. The method takes the same object
140 * parameter as {@link Ext.ElementLoader#load}
141 * @return {Ext.core.Element} this
143 load : function(options) {
144 this.getLoader().load(options);
148 <span id='Ext-core-Element-method-getLoader'> /**
149 </span> * Gets this element's {@link Ext.ElementLoader ElementLoader}
150 * @return {Ext.ElementLoader} The loader
152 getLoader : function() {
154 data = Ext.core.Element.data,
155 loader = data(dom, 'loader');
158 loader = Ext.create('Ext.ElementLoader', {
161 data(dom, 'loader', loader);
166 <span id='Ext-core-Element-method-update'> /**
167 </span> * Update the innerHTML of this element, optionally searching for and processing scripts
168 * @param {String} html The new HTML
169 * @param {Boolean} loadScripts (optional) True to look for and process scripts (defaults to false)
170 * @param {Function} callback (optional) For async script loading you can be notified when the update completes
171 * @return {Ext.core.Element} this
173 update : function(html, loadScripts, callback) {
185 if (loadScripts !== true) {
186 dom.innerHTML = html;
187 Ext.callback(callback, me);
192 html += '<span id="' + id + '"></span>';
194 interval = setInterval(function(){
195 if (!document.getElementById(id)) {
198 clearInterval(interval);
200 hd = DOC.getElementsByTagName("head")[0],
201 re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig,
202 srcRe = /\ssrc=([\'\"])(.*?)\1/i,
203 typeRe = /\stype=([\'\"])(.*?)\1/i,
211 while ((match = re.exec(html))) {
213 srcMatch = attrs ? attrs.match(srcRe) : false;
214 if (srcMatch && srcMatch[2]) {
215 s = DOC.createElement("script");
217 typeMatch = attrs.match(typeRe);
218 if (typeMatch && typeMatch[2]) {
219 s.type = typeMatch[2];
222 } else if (match[2] && match[2].length > 0) {
223 if (window.execScript) {
224 window.execScript(match[2]);
226 window.eval(match[2]);
231 el = DOC.getElementById(id);
235 Ext.callback(callback, me);
237 dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, '');
241 // inherit docs, overridden so we can add removeAnchor
242 removeAllListeners : function() {
244 Ext.EventManager.removeAll(this.dom);
248 <span id='Ext-core-Element-method-createProxy'> /**
249 </span> * Creates a proxy element of this element
250 * @param {String/Object} config The class name of the proxy element or a DomHelper config object
251 * @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body)
252 * @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false)
253 * @return {Ext.core.Element} The new proxy element
255 createProxy : function(config, renderTo, matchBox) {
256 config = (typeof config == 'object') ? config : {tag : "div", cls: config};
259 proxy = renderTo ? Ext.core.DomHelper.append(renderTo, config, true) :
260 Ext.core.DomHelper.insertBefore(me.dom, config, true);
262 proxy.setVisibilityMode(Ext.core.Element.DISPLAY);
264 if (matchBox && me.setBox && me.getBox) { // check to make sure Element.position.js is loaded
265 proxy.setBox(me.getBox());
270 Ext.core.Element.prototype.clearListeners = Ext.core.Element.prototype.removeAllListeners;