📄 element.js
字号:
// parent scroll-width. // - This child will be drawn over the top of any padding applied to the element, so we // don't need to add that to the childBottom value. Only inline elements will force // the parents' padding to show up below them. if (childPosition == isc.Canvas.ABSOLUTE && (element.style.overflow == isc.Canvas.SCROLL || element.style.overflow == isc.Canvas.AUTO || element.style.overflow == isc.Canvas.HIDDEN)) childBottom -= isc.Element.getBottomMargin(child); if (childBottom > largest) largest = childBottom; } return largest;},// isc.Element.getScrollWidth(element) - See comments for getScrollHeightgetScrollWidth : function (element) { if (element == null) return 0; var width = ((element.scrollWidth != null && element.scrollWidth != "undefined") ? element.scrollWidth : element.offsetWidth); // if we have any position:absolute or position:relative children, find the right-most one var largestRight = this._getPositionedChildrenRight(element); return largestRight > width ? largestRight : width;},// get the largest right coordinate for any explicitly positioned DOM children of this element_getPositionedChildrenRight : function (element) { if (element.childNodes == null) return 0; var largest = 0, // constants for determining whether a DOM node is an element. elementType = document.ELEMENT_NODE || 1, debug = this.logIsDebugEnabled("sizing"); for (var i = 0; i < element.childNodes.length; i++) { var child = element.childNodes.item(i); if (child.nodeType != elementType) continue; var childStyle = isc.Element.getComputedStyle(child, ["position", "display", "left"]); var childLeft = 0; if (childStyle.position == isc.Canvas.ABSOLUTE || childStyle.position == isc.Canvas.RELATIVE) { childLeft = isc.Element.getOffsetLeft(child); } else { // inline content ("position" property unset). We don't inspect this because the // scrollWidth reported by the element includes inline content continue; } var canvas = child.getAttribute("eventProxy"), childVisibleWidth; if (canvas != null && !isc.isAn.emptyString(canvas) && !window[canvas]._retrievingScrollWidth && isc.isA.Function(window[canvas].getVisibleWidth)) { childVisibleWidth = window[canvas].getVisibleWidth(); } else { // For regular DOM elements call isc.Element.getVisibleWidth(element) instead childVisibleWidth = isc.Element.getVisibleWidth(child); } var childRight = childLeft + childVisibleWidth; if (element.style.overflow == isc.Canvas.SCROLL || element.style.overflow == isc.Canvas.HIDDEN || element.style.overflow == isc.Canvas.AUTO) { childRight -= isc.Element.getRightMargin(child); } if (childRight > largest) largest = childRight; //>DEBUG if (debug) { this.logInfo("getChildNodesRight: child node " + i + " of " + element.childNodes.length + " (" + this.echoLeaf(child) + ")" + " left:" + childLeft + ", width: " + childVisibleWidth + ", right:" + childRight, "sizing"); } //<DEBUG } return largest;},getElementRect : function (element) { var body = this.getDocumentBody(), left = this._getLeftOffsetFromElement(element, body), top = this._getTopOffsetFromElement(element, body); var width = 0, height = 0; if (element.style && element.style.overflow == "visible") { width = this.getScrollWidth(element); height = this.getScrollHeight(element); } width = Math.max(element.offsetWidth, element.clientWidth, width); height = Math.max(element.offsetHeight, element.clientHeight, height); return [ left, top, width, height ];},// get the inner width of an arbitrary dom element// Note: we use this for widgets with htmlElement and matchElement set.// Implementation doesn't cache results - don't use this in critical path code as it may be// somewhat slowgetInnerWidth : function (element) { // assume content-box sizing (the default) // If specified style.width will be the available 'inner' width, excluding padding, // margin, border // (ignore element overflow for now) var styleWidth = element.style.width; if (styleWidth != null && !isc.isAn.emptyString(styleWidth)) { styleWidth = parseInt(styleWidth); if (isc.isA.Number(styleWidth)) return styleWidth; } // If width is unspecified - measure how large the element rendered out. // // element.clientWidth will be the width of the element excluding border and margin, // but including padding. Delete the padding thickness to get the widget we want. var clientWidth = element.clientWidth, paddingLeft = parseInt(this.getComputedStyleAttribute("paddingLeft")), paddingRight = parseInt(this.getComputedStyleAttribute("paddingRight")), padding = paddingLeft + paddingRight; if (isc.isA.Number(padding)) clientWidth -= padding; return clientWidth;},getInnerHeight : function (element) { // assume content-box sizing (the default) // If specified style.width will be the available 'inner' width, excluding padding, // margin, border // (ignore element overflow for now) var styleHeight = element.style.height; if (styleHeight != null && !isc.isAn.emptyString(styleHeight)) { styleHeight = parseInt(styleHeight); if (isc.isA.Number(styleHeight)) return styleHeight; } // If height is unspecified - measure how large the element rendered out. var clientHeight = element.clientHeight, paddingTop = parseInt(this.getComputedStyleAttribute("paddingTop")), paddingBottom = parseInt(this.getComputedStyleAttribute("paddingBottom")), padding = paddingTop + paddingBottom; if (isc.isA.Number(padding)) clientHeight -= padding; return clientHeight;},getNativeInnerWidth : function (element) { if (isc.Browser.isMoz) return this.getInnerWidth(element); var width = element.offsetWidth; // 0 or null if (!width) width = this.getInnerWidth(element); return width;},getNativeInnerHeight : function (element) { if (isc.Browser.isMoz) return this.getInnerHeight(element); var height = element.offsetHeight; // 0 or null if (!height) height = this.getInnerHeight(element); return height;},// Methods to get the margin sizes for an elementgetTopMargin : function (element) { if (element != null) { var topMargin; if (element.style != null) topMargin = parseInt(element.style.marginTop); if (isc.isA.Number(topMargin)) return topMargin; if (element.className != null) return isc.Element._getTopMargin(element.className); } return 0;},getBottomMargin : function (element) { if (element != null) { var bottomMargin; if (element.style != null) bottomMargin = parseInt(element.style.marginBottom); if (isc.isA.Number(bottomMargin)) return bottomMargin; if (element.className != null) return isc.Element._getBottomMargin(element.className); } return 0;},getLeftMargin : function (element) { if (element != null) { var leftMargin; if (element.style != null) leftMargin = parseInt(element.style.marginLeft); if (isc.isA.Number(leftMargin)) return leftMargin; if (element.className != null) return isc.Element._getLeftMargin(element.className); } return 0;},getRightMargin : function (element) { if (element != null) { var rightMargin; if (element.style != null) rightMargin = parseInt(element.style.marginRight); if (isc.isA.Number(rightMargin)) return rightMargin; if (element.className != null) return isc.Element._getRightMargin(element.className); } return 0;},getHMarginSize : function (element) { return isc.Element.getLeftMargin(element) + isc.Element.getRightMargin(element);},getVMarginSize : function (element) { return isc.Element.getTopMargin(element) + isc.Element.getBottomMargin(element);},getTopBorderSize : function (element) { if (element == null) return 0; if (isc.Browser.isOpera && element.currentStyle.borderTopStyle == this._$none) return 0; var borderSize = (isc.Browser.isIE || isc.Browser.isOpera ? parseInt(element.currentStyle.borderTopWidth) : parseInt(isc.Element.getComputedStyleAttribute(element, "borderTopWidth")) ); return isNaN(borderSize) ? 0 : borderSize;},getBottomBorderSize : function (element) { if (element == null) return 0; if (isc.Browser.isOpera && element.currentStyle.borderBottomStyle == this._$none) return 0; var borderSize = (isc.Browser.isIE || isc.Browser.isOpera ? parseInt(element.currentStyle.borderBottomWidth) : parseInt(isc.Element.getComputedStyleAttribute(element, "borderBottomWidth")) ); return isNaN(borderSize) ? 0 : borderSize;},getLeftBorderSize : function (element) { if (element == null) return 0; if (isc.Browser.isOpera && element.currentStyle.borderLeftStyle == this._$none) return 0; var borderSize = (isc.Browser.isIE || isc.Browser.isOpera ? parseInt(element.currentStyle.borderLeftWidth) : parseInt(isc.Element.getComputedStyleAttribute(element, "borderLeftWidth")) ); return isNaN(borderSize) ? 0 : borderSize;},getRightBorderSize : function (element) { if (element == null) return 0; if (isc.Browser.isOpera && element.currentStyle.borderRightStyle == this._$none) return 0; var borderSize = (isc.Browser.isIE || isc.Browser.isOpera ? parseInt(element.currentStyle.borderRightWidth) : parseInt(isc.Element.getComputedStyleAttribute(element, "borderRightWidth")) ); return isNaN(borderSize) ? 0 : borderSize;},getVBorderSize : function (element) { return isc.Element.getTopBorderSize(element) + isc.Element.getBottomBorderSize(element);},getHBorderSize : function (element) { return isc.Element.getLeftBorderSize(element) + isc.Element.getRightBorderSize(element);},// getVisibleWidth / getVisibleHeight:// when passed a DOM element, return the drawn size of the element, including any overflow, // border, margin or padding.getVisibleWidth : function (element) { if (element == null) return 0; var overflow = isc.Element.getComputedStyleAttribute(element, "overflow"), width; if (overflow == isc.Canvas.VISIBLE || !isc.isA.Number(parseInt(element.style.width))) { width = isc.Element.getScrollWidth(element) + isc.Element.getHBorderSize(element); } else { // use the specified width width = parseInt(element.style.width); } return width + isc.Element.getHMarginSize(element);},getVisibleHeight : function (element) { if (element == null) return 0; var overflow = isc.Element.getComputedStyleAttribute(element, "overflow"), height; if (overflow == isc.Canvas.VISIBLE || !isc.isA.Number(parseInt(element.style.height))) { height = isc.Element.getScrollHeight(element) + isc.Element.getVBorderSize(element); } else { // use the specified height height = parseInt(element.style.height); } return height + isc.Element.getVMarginSize(element);},// Element.getOffsetLeft()// Takes 'element'// element should be a pointer to a DOM element or the ID for a DOM element// (To get the offsetLeft for a widget use use widget.getOffsetLeft() instead)// Returns the true offsetLeft - the absolute left coordinate with respect to whatever is// reported by the DOM as the offsetParent of the element.getOffsetLeft : function (element) { // Note: This method is used by the canvas instance 'getOffsetLeft()' method to calculate // the offset position. // We work with coordinates / sizes relative to the outside of any margins around our // widgets - do the same with this method. if (element == null) { this.logWarn("getOffsetLeft: passed null element"); return 0; } // IE and Moz both return somewhat unreliable values for element.offsetLeft by default. // Paper over these bugs and differences. var left = element.offsetLeft; // --- caching code: // If we've already calculated a value (based on a reported offsetLeft value), and // the reported value has not changed, return the previously calculated value. // This caching is safe except for cases where an indirect parent's styling changes in a // way that would affect this element's true offsetLeft. if (element._cachedReportedOffsetLeft == left) { return element._cachedCalculatedOffsetLeft;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -