📄 webcore.js
字号:
} } if (propagate) { // Fire event to bubbling listeners. for (var i = 0; i < elementAncestry.length; ++i) { listenerList = WebCore.EventProcessor._bubblingListenerMap.map[elementAncestry[i].__eventProcessorId]; // Set registered target on event. e.registeredTarget = elementAncestry[i]; if (listenerList) { if (!listenerList.fireEvent(e)) { propagate = false; } } if (!propagate) { // Stop propagation if requested. break; } } } // Inform DOM to stop propagation of event, in all cases. // Event will otherwise be re-processed by higher-level elements registered with the event processor. WebCore.DOM.stopEventPropagation(e); }, /** * Unregisters an event handler. * * @param {Element} element the DOM element on which to add the event handler * @param {String} eventType the DOM event type * @param {Function} eventTarget the function to invoke when the event is fired * @param {Boolean} capture true to fire the event during the capturing phase, false to fire the event during * the bubbling phase */ remove: function(element, eventType, eventTarget, capture) { WebCore.EventProcessor._lastId = null; if (!element.__eventProcessorId) { return; } // Obtain correct id->ListenerList mapping based on capture parameter. var listenerMap = capture ? WebCore.EventProcessor._capturingListenerMap : WebCore.EventProcessor._bubblingListenerMap; // Obtain ListenerList based on element id. var listenerList = listenerMap.map[element.__eventProcessorId]; if (listenerList) { // Remove event handler from the ListenerList. listenerList.removeListener(eventType, eventTarget); if (listenerList.isEmpty()) { listenerMap.remove(element.__eventProcessorId); } // Unregister event listener on DOM element if all listeners have been removed. if (!listenerList.hasListeners(eventType)) { WebCore.DOM.removeEventListener(element, eventType, WebCore.EventProcessor._processEvent, false); } } }, /** * Unregister all event handlers from a specific element. * Use of this operation is recommended when disposing of components, it is * more efficient than removing listenerse individually and guarantees proper clean-up. * * @param {Element} the element */ removeAll: function(element) { if (!element.__eventProcessorId) { return; } WebCore.EventProcessor._removeAllImpl(element, WebCore.EventProcessor._capturingListenerMap); WebCore.EventProcessor._removeAllImpl(element, WebCore.EventProcessor._bubblingListenerMap); }, /** * Implementation method for removeAll(). * Removes all capturing or bubbling listeners from a specific element * * @param {Element} the element * @param {Core.Arrays.LargeMap} the map from which the listeners should be removed, either * WebCore.EventProcessor._capturingListenerMap or WebCore.EventProcessor._bubblingListenerMap * @private */ _removeAllImpl: function(element, listenerMap) { var listenerList = listenerMap.map[element.__eventProcessorId]; if (!listenerList) { return; } var types = listenerList.getListenerTypes(); for (var i = 0; i < types.length; ++i) { WebCore.DOM.removeEventListener(element, types[i], WebCore.EventProcessor._processEvent, false); } listenerMap.remove(element.__eventProcessorId); }, /** * toString() implementation for debugging purposes. * Displays contents of capturing and bubbling listener maps. * * @return string represenation of listener maps * @type String */ toString: function() { return "Capturing: " + WebCore.EventProcessor._capturingListenerMap + "\n" + "Bubbling: " + WebCore.EventProcessor._bubblingListenerMap; }};/** * @class * An HTTP connection to the hosting server. This method provides a cross * platform wrapper for XMLHttpRequest and additionally allows method * reference-based listener registration. */WebCore.HttpConnection = Core.extend({ _url: null, _contentType: null, _method: null, _messageObject: null, _listenerList: null, _disposed: false, _xmlHttpRequest: null, /** * Creates a new <code>HttpConnection</code>. * This method simply configures the connection, the connection * will not be opened until <code>connect()</code> is invoked. * * @param {String} url the target URL * @param {String} method the connection method, i.e., GET or POST * @param messageObject the message to send (may be a String or XML DOM) * @param {String} contentType the request content-type * @constructor */ $construct: function(url, method, messageObject, contentType) { this._url = url; this._contentType = contentType; this._method = method; this._messageObject = messageObject; this._listenerList = new Core.ListenerList(); }, /** * Adds a response listener to be notified when a response is received from the connection. * * @param {Function} l the listener to add */ addResponseListener: function(l) { this._listenerList.addListener("response", l); }, /** * Executes the HTTP connection. * This method will return before the HTTP connection has received a response. */ connect: function() { var usingActiveXObject = false; if (window.XMLHttpRequest) { this._xmlHttpRequest = new XMLHttpRequest(); } else if (window.ActiveXObject) { usingActiveXObject = true; this._xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } else { throw "Connect failed: Cannot create XMLHttpRequest."; } var instance = this; // Create closure around instance. this._xmlHttpRequest.onreadystatechange = function() { if (!instance) { return; } try { instance._processReadyStateChange(); } finally { if (instance._disposed) { // Release instance reference to allow garbage collection. instance = null; } } }; this._xmlHttpRequest.open(this._method, this._url, true); if (this._contentType && (usingActiveXObject || this._xmlHttpRequest.setRequestHeader)) { this._xmlHttpRequest.setRequestHeader("Content-Type", this._contentType); } this._xmlHttpRequest.send(this._messageObject ? this._messageObject : null); }, /** * Disposes of the connection. This method must be invoked when the connection * will no longer be used/processed. */ dispose: function() { this._listenerList = null; this._messageObject = null; this._xmlHttpRequest = null; this._disposed = true; }, /** * Returns the response status code of the HTTP connection, if available. * * @return {Integer} the response status code */ getStatus: function() { return this._xmlHttpRequest ? this._xmlHttpRequest.status : null; }, /** * Returns the response as text. * This method may only be invoked from a response handler. * * @return the response, as text */ getResponseText: function() { return this._xmlHttpRequest ? this._xmlHttpRequest.responseText : null; }, /** * Returns the response as an XML DOM. * This method may only be invoked from a response handler. * * @return the response, as an XML DOM */ getResponseXml: function() { return this._xmlHttpRequest ? this._xmlHttpRequest.responseXML : null; }, /** * Event listener for <code>readystatechange</code> events received from * the <code>XMLHttpRequest</code>. */ _processReadyStateChange: function() { if (this._disposed) { return; } if (this._xmlHttpRequest.readyState == 4) { var responseEvent; try { // 0 included as a valid response code for non-served applications. var valid = this._xmlHttpRequest.status == 0 || (this._xmlHttpRequest.status >= 200 && this._xmlHttpRequest.status <= 299); responseEvent = {type: "response", source: this, valid: valid}; } catch (ex) { responseEvent = {type: "response", source: this, valid: false, exception: ex}; } this._listenerList.fireEvent(responseEvent); this.dispose(); } }, /** * Removes a response listener to be notified when a response is received from the connection. * * @param {Function} l the listener to remove */ removeResponseListener: function(l) { this._listenerList.removeListener("response", l); }});/** * @class * Utilities for dynamically loading additional script libraries. * Non-instantiable class. */WebCore.Library = { /** * Set of loaded libraries (keys are library urls, value is true when library has been loaded). * @private */ _loadedLibraries: { }, /** * A representation of a group of libraries to be loaded at the same time. * Libraries will be retrieved asynchronously, and then installed once ALL the libraries have * been retrieved. Installation will be done in the order in which the add() method was * invoked to add libraries to the group (without regard for the order in which the * HTTP server returns the library code). */ Group: Core.extend({ _listenerList: null, _libraries: null, _loadedCount: 0, _totalCount: 0, /** * Creates a new library group. * @constructor */ $construct: function() { this._listenerList = new Core.ListenerList(); this._libraries = []; }, /** * Adds a library to the library group. * Libraries which have previously been loaded will not be loaded again. * * @param libraryUrl the URL from which to retrieve the library. */ add: function(libraryUrl) { if (WebCore.Library._loadedLibraries[libraryUrl]) { // Library already loaded: ignore. return; } var libraryItem = new WebCore.Library._Item(this, libraryUrl); this._libraries.push(libraryItem); }, /** * Adds a listener to be notified when all libraries in the group have been loaded. * * @param {Function} l the listener to add */ addLoadListener: function(l) { this._listenerList.addListener("load", l); }, /** * Notifies listeners of completed library loading. * * @private */ _fireLoadEvent: function() { this._listenerList.fireEvent({type: "load", source: this});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -