|
|
@@ -1,27 +1,5 @@
|
|
|
import { createElement, removeElement } from './dom'
|
|
|
|
|
|
-
|
|
|
-// will return null of no scroll parent. will NOT return window/body
|
|
|
-export function getScrollParent(el: HTMLElement): HTMLElement | null {
|
|
|
-
|
|
|
- while (el instanceof HTMLElement) { // will stop when gets to document or null
|
|
|
- let computedStyle = window.getComputedStyle(el)
|
|
|
-
|
|
|
- if (computedStyle.position === 'fixed') {
|
|
|
- break
|
|
|
- }
|
|
|
-
|
|
|
- if ((/(auto|scroll)/).test(computedStyle.overflow + computedStyle.overflowY + computedStyle.overflowX)) {
|
|
|
- return el
|
|
|
- }
|
|
|
-
|
|
|
- el = el.parentNode as HTMLElement
|
|
|
- }
|
|
|
-
|
|
|
- return null
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
export interface EdgeInfo {
|
|
|
borderLeft: number
|
|
|
borderRight: number
|
|
|
@@ -36,6 +14,7 @@ export interface EdgeInfo {
|
|
|
paddingBottom?: number
|
|
|
}
|
|
|
|
|
|
+
|
|
|
export function getEdges(el, getPadding = false): EdgeInfo {
|
|
|
let computedStyle = window.getComputedStyle(el)
|
|
|
let borderLeft = parseInt(computedStyle.borderLeftWidth, 10) || 0
|
|
|
@@ -70,6 +49,7 @@ export function getEdges(el, getPadding = false): EdgeInfo {
|
|
|
return res
|
|
|
}
|
|
|
|
|
|
+
|
|
|
export function getInnerRect(el, goWithinPadding = false) {
|
|
|
let outerRect = el.getBoundingClientRect()
|
|
|
let edges = getEdges(el, goWithinPadding)
|
|
|
@@ -91,6 +71,35 @@ export function getInnerRect(el, goWithinPadding = false) {
|
|
|
}
|
|
|
|
|
|
|
|
|
+export function computeHeightAndMargins(el: HTMLElement) {
|
|
|
+ let computed = window.getComputedStyle(el)
|
|
|
+ return el.offsetHeight +
|
|
|
+ parseInt(computed.marginTop, 10) +
|
|
|
+ parseInt(computed.marginBottom, 10)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// will return null of no scroll parent. will NOT return window/body
|
|
|
+export function getScrollParent(el: HTMLElement): HTMLElement | null {
|
|
|
+
|
|
|
+ while (el instanceof HTMLElement) { // will stop when gets to document or null
|
|
|
+ let computedStyle = window.getComputedStyle(el)
|
|
|
+
|
|
|
+ if (computedStyle.position === 'fixed') {
|
|
|
+ break
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((/(auto|scroll)/).test(computedStyle.overflow + computedStyle.overflowY + computedStyle.overflowX)) {
|
|
|
+ return el
|
|
|
+ }
|
|
|
+
|
|
|
+ el = el.parentNode as HTMLElement
|
|
|
+ }
|
|
|
+
|
|
|
+ return null
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
// The scrollbar width computations in getEdges are sometimes flawed when it comes to
|
|
|
// retina displays, rounding, and IE11. Massage them into a usable value.
|
|
|
function sanitizeScrollbarWidth(width) {
|