X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/0494b8d9b9bb03ab6c22b34dae81261e3cd7e3e6:/src/core/Element-more.js..7a654f8d43fdb43d78b63d90528bed6e86b608cc:/src/core/src/dom/Element-more.js diff --git a/src/core/Element-more.js b/src/core/src/dom/Element-more.js similarity index 54% rename from src/core/Element-more.js rename to src/core/src/dom/Element-more.js index f0f22207..b740293d 100644 --- a/src/core/Element-more.js +++ b/src/core/src/dom/Element-more.js @@ -1,18 +1,47 @@ -/*! - * Ext JS Library 3.3.1 - * Copyright(c) 2006-2010 Sencha Inc. - * licensing@sencha.com - * http://www.sencha.com/license - */ /** - * @class Ext.Element + * @class Ext.core.Element */ -Ext.Element.addMethods({ + +Ext.core.Element.addMethods({ + + /** + * Monitors this Element for the mouse leaving. Calls the function after the specified delay only if + * the mouse was not moved back into the Element within the delay. If the mouse was moved + * back in, the function is not called. + * @param {Number} delay The delay in milliseconds to wait for possible mouse re-entry before calling the handler function. + * @param {Function} handler The function to call if the mouse remains outside of this Element for the specified time. + * @param {Object} scope The scope (this reference) in which the handler function executes. Defaults to this Element. + * @return {Object} The listeners object which was added to this element so that monitoring can be stopped. Example usage: +// Hide the menu if the mouse moves out for 250ms or more +this.mouseLeaveMonitor = this.menuEl.monitorMouseLeave(250, this.hideMenu, this); + +... +// Remove mouseleave monitor on menu destroy +this.menuEl.un(this.mouseLeaveMonitor); + + */ + monitorMouseLeave: function(delay, handler, scope) { + var me = this, + timer, + listeners = { + mouseleave: function(e) { + timer = setTimeout(Ext.Function.bind(handler, scope||me, [e]), delay); + }, + mouseenter: function() { + clearTimeout(timer); + }, + freezeEvent: true + }; + + me.on(listeners); + return listeners; + }, + /** * Stops the specified event(s) from bubbling and optionally prevents the default action * @param {String/Array} eventName an event / array of events to stop from bubbling * @param {Boolean} preventDefault (optional) true to prevent the default action too - * @return {Ext.Element} this + * @return {Ext.core.Element} this */ swallowEvent : function(eventName, preventDefault) { var me = this; @@ -47,7 +76,7 @@ Ext.Element.addMethods({ }, /** - * Removes worthless text nodes + * Removes Empty, or whitespace filled text nodes. Combines adjacent text nodes. * @param {Boolean} forceReclean (optional) By default the element * keeps track if it has been cleaned already so * you can call this over and over. However, if you update the element and @@ -57,44 +86,64 @@ Ext.Element.addMethods({ var me = this, dom = me.dom, n = dom.firstChild, + nx, ni = -1; - if (Ext.Element.data(dom, 'isCleaned') && forceReclean !== true) { + if (Ext.core.Element.data(dom, 'isCleaned') && forceReclean !== true) { return me; } while (n) { - var nx = n.nextSibling; - if (n.nodeType == 3 && !(/\S/.test(n.nodeValue))) { - dom.removeChild(n); + nx = n.nextSibling; + if (n.nodeType == 3) { + // Remove empty/whitespace text nodes + if (!(/\S/.test(n.nodeValue))) { + dom.removeChild(n); + // Combine adjacent text nodes + } else if (nx && nx.nodeType == 3) { + n.appendData(Ext.String.trim(nx.data)); + dom.removeChild(nx); + nx = n.nextSibling; + n.nodeIndex = ++ni; + } } else { + // Recursively clean + Ext.fly(n).clean(); n.nodeIndex = ++ni; } n = nx; } - - Ext.Element.data(dom, 'isCleaned', true); + + Ext.core.Element.data(dom, 'isCleaned', true); return me; }, /** - * Direct access to the Updater {@link Ext.Updater#update} method. The method takes the same object - * parameter as {@link Ext.Updater#update} - * @return {Ext.Element} this + * Direct access to the Ext.ElementLoader {@link Ext.ElementLoader#load} method. The method takes the same object + * parameter as {@link Ext.ElementLoader#load} + * @return {Ext.core.Element} this */ - load : function() { - var updateManager = this.getUpdater(); - updateManager.update.apply(updateManager, arguments); - + load : function(options) { + this.getLoader().load(options); return this; }, /** - * Gets this element's {@link Ext.Updater Updater} - * @return {Ext.Updater} The Updater + * Gets this element's {@link Ext.ElementLoader ElementLoader} + * @return {Ext.ElementLoader} The loader */ - getUpdater : function() { - return this.updateManager || (this.updateManager = new Ext.Updater(this)); + getLoader : function() { + var dom = this.dom, + data = Ext.core.Element.data, + loader = data(dom, 'loader'); + + if (!loader) { + loader = Ext.create('Ext.ElementLoader', { + target: this + }); + data(dom, 'loader', loader); + } + return loader; }, /** @@ -102,28 +151,34 @@ Ext.Element.addMethods({ * @param {String} html The new HTML * @param {Boolean} loadScripts (optional) True to look for and process scripts (defaults to false) * @param {Function} callback (optional) For async script loading you can be notified when the update completes - * @return {Ext.Element} this + * @return {Ext.core.Element} this */ update : function(html, loadScripts, callback) { - if (!this.dom) { - return this; + var me = this, + id, + dom, + interval; + + if (!me.dom) { + return me; } - html = html || ""; + html = html || ''; + dom = me.dom; if (loadScripts !== true) { - this.dom.innerHTML = html; - if (typeof callback == 'function') { - callback(); - } - return this; + dom.innerHTML = html; + Ext.callback(callback, me); + return me; } - var id = Ext.id(), - dom = this.dom; - + id = Ext.id(); html += ''; - Ext.lib.Event.onAvailable(id, function() { + interval = setInterval(function(){ + if (!document.getElementById(id)) { + return false; + } + clearInterval(interval); var DOC = document, hd = DOC.getElementsByTagName("head")[0], re = /(?:]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig, @@ -160,13 +215,10 @@ Ext.Element.addMethods({ if (el) { Ext.removeNode(el); } - - if (typeof callback == 'function') { - callback(); - } - }); - dom.innerHTML = html.replace(/(?:)((\n|\r|.)*?)(?:<\/script>)/ig, ""); - return this; + Ext.callback(callback, me); + }, 20); + dom.innerHTML = html.replace(/(?:)((\n|\r|.)*?)(?:<\/script>)/ig, ''); + return me; }, // inherit docs, overridden so we can add removeAnchor @@ -181,20 +233,21 @@ Ext.Element.addMethods({ * @param {String/Object} config The class name of the proxy element or a DomHelper config object * @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body) * @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false) - * @return {Ext.Element} The new proxy element + * @return {Ext.core.Element} The new proxy element */ createProxy : function(config, renderTo, matchBox) { config = (typeof config == 'object') ? config : {tag : "div", cls: config}; var me = this, - proxy = renderTo ? Ext.DomHelper.append(renderTo, config, true) : - Ext.DomHelper.insertBefore(me.dom, config, true); + proxy = renderTo ? Ext.core.DomHelper.append(renderTo, config, true) : + Ext.core.DomHelper.insertBefore(me.dom, config, true); + proxy.setVisibilityMode(Ext.core.Element.DISPLAY); + proxy.hide(); if (matchBox && me.setBox && me.getBox) { // check to make sure Element.position.js is loaded proxy.setBox(me.getBox()); } return proxy; } }); - -Ext.Element.prototype.getUpdateManager = Ext.Element.prototype.getUpdater; +Ext.core.Element.prototype.clearListeners = Ext.core.Element.prototype.removeAllListeners;