📄 core.web.js
字号:
}), /** * Representation of a single library to be loaded within a group */ _Item: Core.extend({ /** URL Of library to load. */ _url: null, /** Containing library group. */ _group: null, /** * Loaded library content (set when retrieved). * @type String */ _content: null, /** * Creates a new library item. * * @param {Core.Web.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 retrieve the library. * * @param e the event */ _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. */ _install: function() { if (Core.Web.Library._loadedLibraries[this._url]) { // If library was already loaded by another invocation, do not load it again. return; } Core.Web.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 Core.Web.HttpConnection(this._url, "GET"); conn.addResponseListener(Core.method(this, this._retrieveListener)); conn.connect(); } }), /** * Loads required libraries and then executes a function. * This is a convenience method for use by applications that * automatically creates a Group and invokes the specified function * once the libraries have loaded. * This operation is asynchronous, this method will return before the specified function has been invoked. * Any libraries which have already been loaded will NOT be re-loaded. * * @param {Array} requiredLibraries the URLs of the libraries which must be loaded before the function can execute * @param {Function} f the function to execute */ exec: function(requiredLibraries, f) { var group = null; for (var i = 0; i < requiredLibraries.length; ++i) { if (!Core.Web.Library._loadedLibraries[requiredLibraries[i]]) { if (group == null) { group = new Core.Web.Library.Group(); } group.add(requiredLibraries[i]); } } if (group == null) { Core.Web.Scheduler.run(f); return; } group.addLoadListener(f); group.load(); }};/** * Namespace for measuring-related operations. * @class */Core.Web.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, /** Estimated scroll bar width. */ SCROLL_WIDTH: 17, /** Estimated scroll bar height. */ SCROLL_HEIGHT: 17, _PARSER: /^(-?\d+(?:\.\d+)?)(.+)?$/, /** * Converts any non-relative extent value to pixels. Returns null in the case of a percentage extent. * * @param {String} value a unitized extent value, e.g., "2px", "5em", etc. * @param {Boolean} horizontal a flag indicating whether the extent is horizontal (true) or vertical (false) * @return the pixel value (may have a fractional part) * @type Number */ extentToPixels: function(extent, horizontal) { var parts = this._PARSER.exec(extent); if (!parts) { throw new Error("Invalid Extent: " + extent); } var value = parseFloat(parts[1]); var units = parts[2] ? parts[2] : "px"; if (!units || units == "px") { return value; } var dpi = horizontal ? Core.Web.Measure._hInch : Core.Web.Measure._vInch; switch (units) { case "%": return null; case "in": return value * (horizontal ? Core.Web.Measure._hInch : Core.Web.Measure._vInch); case "cm": return value * (horizontal ? Core.Web.Measure._hInch : Core.Web.Measure._vInch) / 2.54; case "mm": return value * (horizontal ? Core.Web.Measure._hInch : Core.Web.Measure._vInch) / 25.4; case "pt": return value * (horizontal ? Core.Web.Measure._hInch : Core.Web.Measure._vInch) / 72; case "pc": return value * (horizontal ? Core.Web.Measure._hInch : Core.Web.Measure._vInch) / 6; case "em": return value * (horizontal ? Core.Web.Measure._hEm : Core.Web.Measure._vEm); case "ex": return value * (horizontal ? Core.Web.Measure._hEx : Core.Web.Measure._vEx); } }, /** * Updates internal measures used in converting length units * (e.g., in, mm, ex, and em) to pixels. * Automatically invoked when Core.Web module is initialized. */ _calculateExtentSizes: function() { var containerElement = document.getElementsByTagName("body")[0]; var inchDiv4 = document.createElement("div"); inchDiv4.style.width = "4in"; inchDiv4.style.height = "4in"; containerElement.appendChild(inchDiv4); Core.Web.Measure._hInch = inchDiv4.offsetWidth / 4; Core.Web.Measure._vInch = inchDiv4.offsetHeight / 4; containerElement.removeChild(inchDiv4); var emDiv24 = document.createElement("div"); emDiv24.style.width = "24em"; emDiv24.style.height = "24em"; containerElement.appendChild(emDiv24); Core.Web.Measure._hEm = emDiv24.offsetWidth / 24; Core.Web.Measure._vEm = emDiv24.offsetHeight / 24; containerElement.removeChild(emDiv24); var exDiv24 = document.createElement("div"); exDiv24.style.width = "24ex"; exDiv24.style.height = "24ex"; containerElement.appendChild(exDiv24); Core.Web.Measure._hEx = exDiv24.offsetWidth / 24; Core.Web.Measure._vEx = exDiv24.offsetHeight / 24; containerElement.removeChild(exDiv24); var scrollDiv = document.createElement("div"); scrollDiv.style.cssText = "width:500px;height:100px;overflow:auto;"; var largeDiv = document.createElement("div"); largeDiv.style.cssText = "width:100px;height:200px;"; scrollDiv.appendChild(largeDiv); var testDiv = document.createElement("div"); testDiv.style.cssText = "width:100%;height:10px;"; scrollDiv.appendChild(testDiv); containerElement.appendChild(scrollDiv); var measuredWidth = 500 - testDiv.offsetWidth; if (measuredWidth) { Core.Web.Measure.SCROLL_WIDTH = Core.Web.Measure.SCROLL_HEIGHT = measuredWidth; } containerElement.removeChild(scrollDiv); }, /** * Measures the scrollbar offset of an element, including any * scroll-bar related offsets of its ancestors. * * @param element the element to measure * @return the offset data, with 'left' and 'top' properties specifying the offset amounts * @type Object */ _getScrollOffset: function(element) { var valueT = 0, valueL = 0; do { if (element.scrollLeft || element.scrollTop) { valueT += element.scrollTop || 0; valueL += element.scrollLeft || 0; } element = element.offsetParent; } 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 */ _getCumulativeOffset: function(element) { var valueT = 0, valueL = 0, init = true; do { valueT += element.offsetTop || 0; valueL += element.offsetLeft || 0; if (element.style.borderLeftWidth && !init && Core.Web.Env.MEASURE_OFFSET_EXCLUDES_BORDER) { var borderLeft = Core.Web.Measure.extentToPixels(element.style.borderLeftWidth, true); valueL += borderLeft; if (Core.Web.Env.QUIRK_MEASURE_OFFSET_HIDDEN_BORDER && element.style.overflow == "hidden") { valueL += borderLeft; } } if (element.style.borderTopWidth && !init && Core.Web.Env.MEASURE_OFFSET_EXCLUDES_BORDER) { var borderTop = Core.Web.Measure.extentToPixels(element.style.borderTopWidth, false); valueT += borderTop; if (Core.Web.Env.QUIRK_MEASURE_OFFSET_HIDDEN_BORDER && element.style.overflow == "hidden") { valueT += borderTop; } } init = false; element = element.offsetParent; } while (element); return { left: valueL, top: valueT }; }, /** * 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({ $static: { _initMeasureContainer: function() { // Create off-screen div element for evaluating sizes. this._offscreenDiv = document.createElement("div"); this._offscreenDiv.style.cssText = "position: absolute; top: -1300px; left: -1700px; width: 1600px; height: 1200px;"; document.body.appendChild(this._offscreenDiv); } }, /** * 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. * @param constraints an object containing width and or height properties specifying size of region in which to measure * the element * @constructor */ $construct: function(element, constraints) { if (element === document.body) { return { x: 0, y: 0, height: window.innerHeight || document.documentElement.clientHeight, width: window.innerWidth || document.documentElement.clientWidth }; } var testElement = element; while (testElement && testElement != document) { testElement = testElement.parentNode; } var rendered = testElement == document; var parentNode, nextSibling; if (!rendered) { // Element must be
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -