📄 element.js
字号:
}, /** * Sets up event handlers to call the passed functions when the mouse is moved into and out of the Element. * @param {Function} overFn The function to call when the mouse enters the Element. * @param {Function} outFn The function to call when the mouse leaves the Element. * @param {Object} scope (optional) The scope (<tt>this</tt> reference) in which the functions are executed. Defaults to the Element's DOM element. * @param {Object} options (optional) Options for the listener. See {@link Ext.util.Observable#addListener the <tt>options</tt> parameter}. * @return {Ext.Element} this */ hover : function(overFn, outFn, scope, options){ var me = this; me.on('mouseenter', overFn, scope || me.dom, options); me.on('mouseleave', outFn, scope || me.dom, options); return me; }, /** * Returns true if this element is an ancestor of the passed element * @param {HTMLElement/String} el The element to check * @return {Boolean} True if this element is an ancestor of el, else false */ contains : function(el){ return !el ? false : Ext.lib.Dom.isAncestor(this.dom, el.dom ? el.dom : el); }, /** * Returns the value of a namespaced attribute from the element's underlying DOM node. * @param {String} namespace The namespace in which to look for the attribute * @param {String} name The attribute name * @return {String} The attribute value */ getAttributeNS : Ext.isIE ? function(ns, name){ var d = this.dom, type = typeof d[ns + ":" + name]; if(!Ext.isEmpty(type) && type != 'unknown'){ return d[ns + ":" + name]; } return d[name]; } : function(ns, name){ var d = this.dom; return d.getAttributeNS(ns, name) || d.getAttribute(ns + ":" + name) || d.getAttribute(name) || d[name]; }, update : function(html) { this.dom.innerHTML = html; }};var ep = El.prototype;El.addMethods = function(o){ Ext.apply(ep, o);};/** * Appends an event handler (shorthand for {@link #addListener}). * @param {String} eventName The type of event to handle * @param {Function} fn The handler function the event invokes * @param {Object} scope (optional) The scope (this element) of the handler function * @param {Object} options (optional) An object containing standard {@link #addListener} options * @member Ext.Element * @method on */ep.on = ep.addListener;/** * Removes an event handler from this element (see {@link #removeListener} for additional notes). * @param {String} eventName the type of event to remove * @param {Function} fn the method the event invokes * @param {Object} scope (optional) The scope (The <tt>this</tt> reference) of the handler function. Defaults * to this Element. * @return {Ext.Element} this * @member Ext.Element * @method un */ep.un = ep.removeListener;/** * true to automatically adjust width and height settings for box-model issues (default to true) */ep.autoBoxAdjust = true;// privatevar unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i, docEl;/** * @private */El.cache = {};/** * Retrieves Ext.Element objects. * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method * retrieves Ext.Element objects which encapsulate DOM elements. To retrieve a Component by * its ID, use {@link Ext.ComponentMgr#get}.</p> * <p>Uses simple caching to consistently return the same object. Automatically fixes if an * object was recreated with the same id via AJAX or DOM.</p> * @param {Mixed} el The id of the node, a DOM Node or an existing Element. * @return {Element} The Element object (or null if no matching element was found) * @static * @member Ext.Element * @method get */El.get = function(el){ var ex, elm, id; if(!el){ return null; } if (typeof el == "string") { // element id if (!(elm = DOC.getElementById(el))) { return null; } if (ex = El.cache[el]) { ex.dom = elm; } else { ex = El.cache[el] = new El(elm); } return ex; } else if (el.tagName) { // dom element if(!(id = el.id)){ id = Ext.id(el); } if(ex = El.cache[id]){ ex.dom = el; }else{ ex = El.cache[id] = new El(el); } return ex; } else if (el instanceof El) { if(el != docEl){ el.dom = DOC.getElementById(el.id) || el.dom; // refresh dom element in case no longer valid, // catch case where it hasn't been appended El.cache[el.id] = el; // in case it was created directly with Element(), let's cache it } return el; } else if(el.isComposite) { return el; } else if(Ext.isArray(el)) { return El.select(el); } else if(el == DOC) { // create a bogus element object representing the document object if(!docEl){ var f = function(){}; f.prototype = El.prototype; docEl = new f(); docEl.dom = DOC; } return docEl; } return null;};// private// Garbage collection - uncache elements/purge listeners on orphaned elements// so we don't hold a reference and cause the browser to retain themfunction garbageCollect(){ if(!Ext.enableGarbageCollector){ clearInterval(El.collectorThread); } else { var eid, el, d; for(eid in El.cache){ el = El.cache[eid]; d = el.dom; // ------------------------------------------------------- // Determining what is garbage: // ------------------------------------------------------- // !d // dom node is null, definitely garbage // ------------------------------------------------------- // !d.parentNode // no parentNode == direct orphan, definitely garbage // ------------------------------------------------------- // !d.offsetParent && !document.getElementById(eid) // display none elements have no offsetParent so we will // also try to look it up by it's id. However, check // offsetParent first so we don't do unneeded lookups. // This enables collection of elements that are not orphans // directly, but somewhere up the line they have an orphan // parent. // ------------------------------------------------------- if(!d || !d.parentNode || (!d.offsetParent && !DOC.getElementById(eid))){ delete El.cache[eid]; if(d && Ext.enableListenerCollection){ Ext.EventManager.removeAll(d); } } } }}El.collectorThreadId = setInterval(garbageCollect, 30000);var flyFn = function(){};flyFn.prototype = El.prototype;// dom is optionalEl.Flyweight = function(dom){ this.dom = dom;};El.Flyweight.prototype = new flyFn();El.Flyweight.prototype.isFlyweight = true;El._flyweights = {};/** * <p>Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element - * the dom node can be overwritten by other code. Shorthand of {@link Ext.Element#fly}</p> * <p>Use this to make one-time references to DOM elements which are not going to be accessed again either by * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link Ext#get} * will be more appropriate to take advantage of the caching provided by the Ext.Element class.</p> * @param {String/HTMLElement} el The dom node or id * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts * (e.g. internally Ext uses "_global") * @return {Element} The shared Element object (or null if no matching element was found) * @member Ext.Element * @method fly */El.fly = function(el, named){ var ret = null; named = named || '_global'; if (el = Ext.getDom(el)) { (El._flyweights[named] = El._flyweights[named] || new El.Flyweight()).dom = el; ret = El._flyweights[named]; } return ret;};/** * Retrieves Ext.Element objects. * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method * retrieves Ext.Element objects which encapsulate DOM elements. To retrieve a Component by * its ID, use {@link Ext.ComponentMgr#get}.</p> * <p>Uses simple caching to consistently return the same object. Automatically fixes if an * object was recreated with the same id via AJAX or DOM.</p> * Shorthand of {@link Ext.Element#get} * @param {Mixed} el The id of the node, a DOM Node or an existing Element. * @return {Element} The Element object (or null if no matching element was found) * @member Ext * @method get */Ext.get = El.get;/** * <p>Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element - * the dom node can be overwritten by other code. Shorthand of {@link Ext.Element#fly}</p> * <p>Use this to make one-time references to DOM elements which are not going to be accessed again either by * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link Ext#get} * will be more appropriate to take advantage of the caching provided by the Ext.Element class.</p> * @param {String/HTMLElement} el The dom node or id * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts * (e.g. internally Ext uses "_global") * @return {Element} The shared Element object (or null if no matching element was found) * @member Ext * @method fly */Ext.fly = El.fly;// speedy lookup for elements never to box adjustvar noBoxAdjust = Ext.isStrict ? { select:1} : { input:1, select:1, textarea:1};if(Ext.isIE || Ext.isGecko){ noBoxAdjust['button'] = 1;}Ext.EventManager.on(window, 'unload', function(){ delete El.cache; delete El._flyweights;});})();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -