2 * @class Ext.core.Element
5 Ext.core.Element.addMethods({
8 * Monitors this Element for the mouse leaving. Calls the function after the specified delay only if
9 * the mouse was not moved back into the Element within the delay. If the mouse <i>was</i> moved
10 * back in, the function is not called.
11 * @param {Number} delay The delay <b>in milliseconds</b> to wait for possible mouse re-entry before calling the handler function.
12 * @param {Function} handler The function to call if the mouse remains outside of this Element for the specified time.
13 * @param {Object} scope The scope (<code>this</code> reference) in which the handler function executes. Defaults to this Element.
14 * @return {Object} The listeners object which was added to this element so that monitoring can be stopped. Example usage:</pre><code>
15 // Hide the menu if the mouse moves out for 250ms or more
16 this.mouseLeaveMonitor = this.menuEl.monitorMouseLeave(250, this.hideMenu, this);
19 // Remove mouseleave monitor on menu destroy
20 this.menuEl.un(this.mouseLeaveMonitor);
23 monitorMouseLeave: function(delay, handler, scope) {
27 mouseleave: function(e) {
28 timer = setTimeout(Ext.Function.bind(handler, scope||me, [e]), delay);
30 mouseenter: function() {
41 * Stops the specified event(s) from bubbling and optionally prevents the default action
42 * @param {String/Array} eventName an event / array of events to stop from bubbling
43 * @param {Boolean} preventDefault (optional) true to prevent the default action too
44 * @return {Ext.core.Element} this
46 swallowEvent : function(eventName, preventDefault) {
55 if (Ext.isArray(eventName)) {
56 Ext.each(eventName, function(e) {
66 * Create an event handler on this element such that when the event fires and is handled by this element,
67 * it will be relayed to another object (i.e., fired again as if it originated from that object instead).
68 * @param {String} eventName The type of event to relay
69 * @param {Object} object Any object that extends {@link Ext.util.Observable} that will provide the context
70 * for firing the relayed event
72 relayEvent : function(eventName, observable) {
73 this.on(eventName, function(e) {
74 observable.fireEvent(eventName, e);
79 * Removes Empty, or whitespace filled text nodes. Combines adjacent text nodes.
80 * @param {Boolean} forceReclean (optional) By default the element
81 * keeps track if it has been cleaned already so
82 * you can call this over and over. However, if you update the element and
83 * need to force a reclean, you can pass true.
85 clean : function(forceReclean) {
92 if (Ext.core.Element.data(dom, 'isCleaned') && forceReclean !== true) {
98 if (n.nodeType == 3) {
99 // Remove empty/whitespace text nodes
100 if (!(/\S/.test(n.nodeValue))) {
102 // Combine adjacent text nodes
103 } else if (nx && nx.nodeType == 3) {
104 n.appendData(Ext.String.trim(nx.data));
117 Ext.core.Element.data(dom, 'isCleaned', true);
122 * Direct access to the Ext.ElementLoader {@link Ext.ElementLoader#load} method. The method takes the same object
123 * parameter as {@link Ext.ElementLoader#load}
124 * @return {Ext.core.Element} this
126 load : function(options) {
127 this.getLoader().load(options);
132 * Gets this element's {@link Ext.ElementLoader ElementLoader}
133 * @return {Ext.ElementLoader} The loader
135 getLoader : function() {
137 data = Ext.core.Element.data,
138 loader = data(dom, 'loader');
141 loader = Ext.create('Ext.ElementLoader', {
144 data(dom, 'loader', loader);
150 * Update the innerHTML of this element, optionally searching for and processing scripts
151 * @param {String} html The new HTML
152 * @param {Boolean} loadScripts (optional) True to look for and process scripts (defaults to false)
153 * @param {Function} callback (optional) For async script loading you can be notified when the update completes
154 * @return {Ext.core.Element} this
156 update : function(html, loadScripts, callback) {
168 if (loadScripts !== true) {
169 dom.innerHTML = html;
170 Ext.callback(callback, me);
175 html += '<span id="' + id + '"></span>';
177 interval = setInterval(function(){
178 if (!document.getElementById(id)) {
181 clearInterval(interval);
183 hd = DOC.getElementsByTagName("head")[0],
184 re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig,
185 srcRe = /\ssrc=([\'\"])(.*?)\1/i,
186 typeRe = /\stype=([\'\"])(.*?)\1/i,
194 while ((match = re.exec(html))) {
196 srcMatch = attrs ? attrs.match(srcRe) : false;
197 if (srcMatch && srcMatch[2]) {
198 s = DOC.createElement("script");
200 typeMatch = attrs.match(typeRe);
201 if (typeMatch && typeMatch[2]) {
202 s.type = typeMatch[2];
205 } else if (match[2] && match[2].length > 0) {
206 if (window.execScript) {
207 window.execScript(match[2]);
209 window.eval(match[2]);
214 el = DOC.getElementById(id);
218 Ext.callback(callback, me);
220 dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, '');
224 // inherit docs, overridden so we can add removeAnchor
225 removeAllListeners : function() {
227 Ext.EventManager.removeAll(this.dom);
232 * Creates a proxy element of this element
233 * @param {String/Object} config The class name of the proxy element or a DomHelper config object
234 * @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body)
235 * @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false)
236 * @return {Ext.core.Element} The new proxy element
238 createProxy : function(config, renderTo, matchBox) {
239 config = (typeof config == 'object') ? config : {tag : "div", cls: config};
242 proxy = renderTo ? Ext.core.DomHelper.append(renderTo, config, true) :
243 Ext.core.DomHelper.insertBefore(me.dom, config, true);
245 proxy.setVisibilityMode(Ext.core.Element.DISPLAY);
247 if (matchBox && me.setBox && me.getBox) { // check to make sure Element.position.js is loaded
248 proxy.setBox(me.getBox());
253 Ext.core.Element.prototype.clearListeners = Ext.core.Element.prototype.removeAllListeners;