📄 event.js
字号:
// before the window load notification EU._tryPreloadAttach(); // Remove the listener to assist with the IE memory issue, but not // for other browsers because FF 1.0x does not like it. //if (this.isIE) { //EU._simpleRemove(window, "load", EU._load); //} } }, /** * Fires the DOMReady event listeners the first time the document is * usable. * @method _ready * @static * @private */ _ready: function(e) { var EU = YAHOO.util.Event; if (!EU.DOMReady) { EU.DOMReady=true; // Fire the content ready custom event EU.DOMReadyEvent.fire(); // Remove the DOMContentLoaded (FF/Opera) EU._simpleRemove(document, "DOMContentLoaded", EU._ready); } }, /** * Polling function that runs before the onload event fires, * attempting to attach to DOM Nodes as soon as they are * available * @method _tryPreloadAttach * @static * @private */ _tryPreloadAttach: function() { if (this.locked) { return false; } if (this.isIE) { // Hold off if DOMReady has not fired and check current // readyState to protect against the IE operation aborted // issue. //if (!this.DOMReady || "complete" !== document.readyState) { if (!this.DOMReady) { this.startInterval(); return false; } } this.locked = true; // keep trying until after the page is loaded. We need to // check the page load state prior to trying to bind the // elements so that we can be certain all elements have been // tested appropriately var tryAgain = !loadComplete; if (!tryAgain) { tryAgain = (retryCount > 0); } // onAvailable var notAvail = []; var executeItem = function (el, item) { var scope = el; if (item.override) { if (item.override === true) { scope = item.obj; } else { scope = item.override; } } item.fn.call(scope, item.obj); }; var i,len,item,el; // onAvailable for (i=0,len=onAvailStack.length; i<len; ++i) { item = onAvailStack[i]; if (item && !item.checkReady) { el = this.getEl(item.id); if (el) { executeItem(el, item); onAvailStack[i] = null; } else { notAvail.push(item); } } } // onContentReady for (i=0,len=onAvailStack.length; i<len; ++i) { item = onAvailStack[i]; if (item && item.checkReady) { el = this.getEl(item.id); if (el) { // The element is available, but not necessarily ready // @todo should we test parentNode.nextSibling? if (loadComplete || el.nextSibling) { executeItem(el, item); onAvailStack[i] = null; } } else { notAvail.push(item); } } } retryCount = (notAvail.length === 0) ? 0 : retryCount - 1; if (tryAgain) { // we may need to strip the nulled out items here this.startInterval(); } else { clearInterval(this._interval); this._interval = null; } this.locked = false; return true; }, /** * Removes all listeners attached to the given element via addListener. * Optionally, the node's children can also be purged. * Optionally, you can specify a specific type of event to remove. * @method purgeElement * @param {HTMLElement} el the element to purge * @param {boolean} recurse recursively purge this element's children * as well. Use with caution. * @param {string} sType optional type of listener to purge. If * left out, all listeners will be removed * @static */ purgeElement: function(el, recurse, sType) { var oEl = (YAHOO.lang.isString(el)) ? this.getEl(el) : el; var elListeners = this.getListeners(oEl, sType), i, len; if (elListeners) { for (i=0,len=elListeners.length; i<len ; ++i) { var l = elListeners[i]; // can't use the index on the changing collection this.removeListener(oEl, l.type, l.fn, l.index); //this.removeListener(oEl, l.type, l.fn); } } if (recurse && oEl && oEl.childNodes) { for (i=0,len=oEl.childNodes.length; i<len ; ++i) { this.purgeElement(oEl.childNodes[i], recurse, sType); } } }, /** * Returns all listeners attached to the given element via addListener. * Optionally, you can specify a specific type of event to return. * @method getListeners * @param el {HTMLElement|string} the element or element id to inspect * @param sType {string} optional type of listener to return. If * left out, all listeners will be returned * @return {Object} the listener. Contains the following fields: * type: (string) the type of event * fn: (function) the callback supplied to addListener * obj: (object) the custom object supplied to addListener * adjust: (boolean|object) whether or not to adjust the default scope * scope: (boolean) the derived scope based on the adjust parameter * index: (int) its position in the Event util listener cache * @static */ getListeners: function(el, sType) { var results=[], searchLists; if (!sType) { searchLists = [listeners, unloadListeners]; } else if (sType === "unload") { searchLists = [unloadListeners]; } else { searchLists = [listeners]; } var oEl = (YAHOO.lang.isString(el)) ? this.getEl(el) : el; for (var j=0;j<searchLists.length; j=j+1) { var searchList = searchLists[j]; if (searchList && searchList.length > 0) { for (var i=0,len=searchList.length; i<len ; ++i) { var l = searchList[i]; if ( l && l[this.EL] === oEl && (!sType || sType === l[this.TYPE]) ) { results.push({ type: l[this.TYPE], fn: l[this.FN], obj: l[this.OBJ], adjust: l[this.OVERRIDE], scope: l[this.ADJ_SCOPE], index: i }); } } } } return (results.length) ? results : null; }, /** * Removes all listeners registered by pe.event. Called * automatically during the unload event. * @method _unload * @static * @private */ _unload: function(e) { var EU = YAHOO.util.Event, i, j, l, len, index; // execute and clear stored unload listeners for (i=0,len=unloadListeners.length; i<len; ++i) { l = unloadListeners[i]; if (l) { var scope = window; if (l[EU.ADJ_SCOPE]) { if (l[EU.ADJ_SCOPE] === true) { scope = l[EU.UNLOAD_OBJ]; } else { scope = l[EU.ADJ_SCOPE]; } } l[EU.FN].call(scope, EU.getEvent(e, l[EU.EL]), l[EU.UNLOAD_OBJ] ); unloadListeners[i] = null; l=null; scope=null; } } unloadListeners = null; // call clearAttributes or remove listeners to handle IE memory leaks if (YAHOO.env.ua.ie && listeners && listeners.length > 0) { j = listeners.length; while (j) { index = j-1; l = listeners[index]; if (l) { //try { //l[EU.EL].clearAttributes(); // errors on window objects //} catch(ex) { EU.removeListener(l[EU.EL], l[EU.TYPE], l[EU.FN], index); //} } j--; } l=null; } /* // remove all listeners if (listeners && listeners.length > 0) { j = listeners.length; while (j) { index = j-1; l = listeners[index]; if (l) { EU.removeListener(l[EU.EL], l[EU.TYPE], l[EU.FN], index); } j = j - 1; } l=null; } */ /* // kill legacy events for (i=0,len=legacyEvents.length; i<len; ++i) { // dereference the element //delete legacyEvents[i][0]; legacyEvents[i][0] = null; // delete the array item //delete legacyEvents[i]; legacyEvents[i] = null; } */ legacyEvents = null; EU._simpleRemove(window, "unload", EU._unload); }, /** * Returns scrollLeft * @method _getScrollLeft * @static * @private */ _getScrollLeft: function() { return this._getScroll()[1]; }, /** * Returns scrollTop * @method _getScrollTop * @static * @private */ _getScrollTop: function() { return this._getScroll()[0]; }, /** * Returns the scrollTop and scrollLeft. Used to calculate the * pageX and pageY in Internet Explorer * @method _getScroll * @static * @private */ _getScroll: function() { var dd = document.documentElement, db = document.body; if (dd && (dd.scrollTop || dd.scrollLeft)) { return [dd.scrollTop, dd.scrollLeft]; } else if (db) { return [db.scrollTop, db.scrollLeft]; } else { return [0, 0]; } }, /** * Used by old versions of CustomEvent, restored for backwards * compatibility * @method regCE * @private * @static * @deprecated still here for backwards compatibility */ regCE: function() { // does nothing },/* testIEReady: function (){ var n = document.createElement('p'), ready = false; try { // throws an error until the doc is ready n.doScroll('left'); ready = true; } catch(ex){ // document is not ready } n = null; return ready; },*/ /** * Adds a DOM event directly without the caching, cleanup, scope adj, etc * * @method _simpleAdd * @param {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -