📄 webcore.js
字号:
}, /** * Determines if this library group contains any new (not previously loaded) * libraries. * * @return true if any new libraries exist * @type Boolean */ hasNewLibraries: function() { return this._libraries.length > 0; }, /** * Installs all libraries in the group. * This method is invoked once all libraries have been successfully * retrieved. It will invoke any registered load listeners * once the libraries have been installed. * * @private */ _install: function() { for (var i = 0; i < this._libraries.length; ++i) { try { this._libraries[i]._install(); } catch (ex) { throw new Error("Exception installing library \"" + this._libraries[i]._url + "\"; " + ex); } } this._fireLoadEvent(); }, /** * Event listener invoked when a single library has been successfully retrieved. * When all libraries have been retrieved, this method will invoke _install(). * @private */ _notifyRetrieved: function() { ++this._loadedCount; if (this._loadedCount == this._totalCount) { this._install(); } }, /** * Initializes library loading. When this method is invoked * the libraries will be asynchronously loaded. This method * will return before the libraries have been loaded. * Once this method has been invoked, add() may no longer * be invoked. */ load: function() { this._totalCount = this._libraries.length; for (var i = 0; i < this._libraries.length; ++i) { this._libraries[i]._retrieve(); } }, /** * Removes a listener from being notified when all libraries in the group have been loaded. * * @param {Function} l the listener to remove */ removeLoadListener: function(l) { this._listenerList.removeListener("load", l); } }), /** * @class * Representation of a single library to be loaded within a group * * @private */ _Item: Core.extend({ _url: null, _group: null, _content: null, /** * Creates a new library item. * * @param {WebCore.Library.Group} group the library group in which the item is contained * @param {String} url the URL from which the library may be retrieved * @constructor */ $construct: function(group, url) { this._url = url; this._group = group; }, /** * Event listener for response from the HttpConnection used to retrive the library. * * @param e the event * @private */ _retrieveListener: function(e) { if (!e.valid) { throw new Error("Invalid HTTP response from library request: " + e.source.getStatus()); } this._content = e.source.getResponseText(); this._group._notifyRetrieved(); }, /** * Installs the library. * The library must have been loaded before invoking this method. * @private */ _install: function() { WebCore.Library._loadedLibraries[this._url] = true; if (this._content == null) { throw new Error("Attempt to install library when no content has been loaded."); } // Execute content to install library. eval(this._content); }, /** * Asynchronously retrieves the library. * This method will invoke the retrieve listener when the library has been completed, * it will return before the library has been retrieved. */ _retrieve: function() { var conn = new WebCore.HttpConnection(this._url, "GET"); conn.addResponseListener(Core.method(this, this._retrieveListener)); conn.connect(); } })};/** * @class * Namespace for measuring-related operations. * Do not instantiate. */WebCore.Measure = { _scrollElements: ["div", "body"], /** Size of one inch in horizontal pixels. */ _hInch: 96, /** Size of one inch in vertical pixels. */ _vInch: 96, /** Size of one 'ex' in horizontal pixels. */ _hEx: 7, /** Size of one 'ex' in vertical pixels. */ _vEx: 7, /** Size of one 'em' in horizontal pixels. */ _hEm: 13.3333, /** Size of one 'em' in vertical pixels. */ _vEm: 13.3333, /** * Converts any non-relative extent value to pixels. * * @param {Number} value the value to convert * @param {String} the units, one of the following values: in, cm, mm, pt, pc, em, ex * @return the pixel value (may have a fractional part) * @type Number */ extentToPixels: function(value, units, horizontal) { if (!units || units == "px") { return value; } var dpi = horizontal ? WebCore.Measure._hInch : WebCore.Measure._vInch; switch (units) { case "%": return null; case "in": return value * (horizontal ? WebCore.Measure._hInch : WebCore.Measure._vInch); case "cm": return value * (horizontal ? WebCore.Measure._hInch : WebCore.Measure._vInch) / 2.54; case "mm": return value * (horizontal ? WebCore.Measure._hInch : WebCore.Measure._vInch) / 25.4; case "pt": return value * (horizontal ? WebCore.Measure._hInch : WebCore.Measure._vInch) / 72; case "pc": return value * (horizontal ? WebCore.Measure._hInch : WebCore.Measure._vInch) / 6; case "em": return value * (horizontal ? WebCore.Measure._hEm : WebCore.Measure._vEm); case "ex": return value * (horizontal ? WebCore.Measure._hEx : WebCore.Measure._vEx); } }, /** * Updates internal measures used in converting length units * (e.g., in, mm, ex, and em) to pixels. * Automatically invoked when WebCore module is initialized. * @private */ _calculateExtentSizes: function() { var containerElement = document.getElementsByTagName("body")[0]; var inchDiv4 = document.createElement("div"); inchDiv4.style.width = "4in"; inchDiv4.style.height = "4in"; containerElement.appendChild(inchDiv4); WebCore.Measure._hInch = inchDiv4.offsetWidth / 4; WebCore.Measure._vInch = inchDiv4.offsetHeight / 4; containerElement.removeChild(inchDiv4); var emDiv24 = document.createElement("div"); emDiv24.style.width = "24em"; emDiv24.style.height = "24em"; containerElement.appendChild(emDiv24); WebCore.Measure._hEm = emDiv24.offsetWidth / 24; WebCore.Measure._vEm = emDiv24.offsetHeight / 24; containerElement.removeChild(emDiv24); var exDiv24 = document.createElement("div"); exDiv24.style.width = "24ex"; exDiv24.style.height = "24ex"; containerElement.appendChild(exDiv24); WebCore.Measure._hEx = exDiv24.offsetWidth / 24; WebCore.Measure._vEx = exDiv24.offsetHeight / 24; containerElement.removeChild(exDiv24); }, /** * Measures the scrollbar offset of an element, including any * scroll-bar related offsets of its ancestors. * * @param element the elemnt to measure * @return the offset data, with 'left' and 'top' properties specifying the offset amounts * @type Object * @private */ _getScrollOffset: function(element) { var valueT = 0, valueL = 0; do { if ((element.scrollLeft || element.scrollTop) && element.nodeName.toLowerCase() in this._scrollElements) { valueT += element.scrollTop || 0; valueL += element.scrollLeft || 0; } element = element.parentNode; } while (element); return { left: valueL, top: valueT }; }, /** * Measures the cumulative offset of an element. * * @param element the element to measure * @return the offset data, with 'left' and 'top' properties specifying the offset amounts * @type Object * @private */ _getCumulativeOffset: function(element) { var valueT = 0, valueL = 0; do { valueT += element.offsetTop || 0; valueL += element.offsetLeft || 0; element = element.offsetParent; } while (element); return { left: valueL, top: valueT }; }, /** * @class * Measures the boundaries of an element,i.e., its left and top position and/or * width and height. If the element is not attached to the rendered DOM hierarchy, * the element will be temporarily removed from its hierarchy and placed in an * off-screen buffer for measuring. */ Bounds: Core.extend({ /** * The width of the element, in pixels. * @type Integer */ width: null, /** * The height of the element, in pixels. * @type Integer */ height: null, /** * The top coordinate of the element, in pixels relative to the upper-left corner of the interior of the window. * @type Integer */ top: null, /** * The left coordinate of the element, in pixels relative to the upper-left corner of the interior of the window. * @type Integer */ left: null, /** * Creates a new Bounds object to calculate the size and/or position of an element. * * @param element the element to measure. * @constructor */ $construct: function(element) { var testElement = element; while (testElement && testElement != document) { testElement = testElement.parentNode; } var rendered = testElement == document; // Create off-screen div element for evaluating sizes if necessary. if (!WebCore.Measure.Bounds._offscreenDiv) { WebCore.Measure.Bounds._offscreenDiv = document.createElement("div"); WebCore.Measure.Bounds._offscreenDiv.style.cssText = "position: absolute; top: -1700px; left: -1300px; width: 1600px; height: 1200px;"; } var parentNode, nextSibling; if (!rendered) { document.body.appendChild(WebCore.Measure.Bounds._offscreenDiv); // Element must be added to off-screen element for measuring. // Store parent node and next sibling such that element may be replaced into proper position // once off-screen measurement has been completed. parentNode = element.parentNode; nextSibling = element.nextSibling; // Remove element from parent. if (parentNode) { parentNode.removeChild(element); } // Append element to measuring container DIV. WebCore.Measure.Bounds._offscreenDiv.appendChild(element); } // Store width and height of element. this.width = element.offsetWidth; this.height = element.offsetHeight; if (!rendered) { // Replace off-screen measured element in previous location. WebCore.Measure.Bounds._offscreenDiv.removeChild(element); if (parentNode) { parentNode.insertBefore(element, nextSibling); } document.body.removeChild(WebCore.Measure.Bounds._offscreenDiv); } // Determine top and left positions of element if rendered on-screen. if (rendered) { var cumulativeOffset = WebCore.Measure._getCumulativeOffset(element);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -