Quellcode durchsuchen

move dom-geom around

Adam Shaw vor 8 Jahren
Ursprung
Commit
ff92ffbd7a
6 geänderte Dateien mit 38 neuen und 38 gelöschten Zeilen
  1. 2 1
      src/Calendar.ts
  2. 2 2
      src/exports.ts
  3. 31 22
      src/util/dom-geom.ts
  4. 0 11
      src/util/dom.ts
  5. 2 1
      src/util/misc.ts
  6. 1 1
      tests/example-repos/typescript-example

+ 2 - 1
src/Calendar.ts

@@ -1,6 +1,7 @@
 import * as moment from 'moment'
 import { capitaliseFirstLetter, debounce } from './util/misc'
-import { createElement, removeElement, applyStyle, prependToElement, computeHeightAndMargins } from './util/dom'
+import { createElement, removeElement, applyStyle, prependToElement } from './util/dom'
+import { computeHeightAndMargins } from './util/dom-geom'
 import { listenBySelector } from './util/dom-event'
 import { globalDefaults, englishDefaults, rtlDefaults } from './options'
 import Iterator from './common/Iterator'

+ 2 - 2
src/exports.ts

@@ -61,7 +61,6 @@ export {
   appendToElement,
   applyStyle,
   applyStyleProp,
-  computeHeightAndMargins,
   elementMatches,
   queryChild,
   queryChildren
@@ -75,7 +74,8 @@ export {
 
 export {
   getInnerRect,
-  getEdges
+  getEdges,
+  computeHeightAndMargins
 } from './util/dom-geom'
 
 export {

+ 31 - 22
src/util/dom-geom.ts

@@ -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) {

+ 0 - 11
src/util/dom.ts

@@ -219,14 +219,3 @@ export function applyStyleProp(el: HTMLElement, name: string, val) {
     el.style[name] = val
   }
 }
-
-
-// Dimensions
-// ----------------------------------------------------------------------------------------------------------------
-
-export function computeHeightAndMargins(el: HTMLElement) {
-  let computed = window.getComputedStyle(el)
-  return el.offsetHeight +
-    parseInt(computed.marginTop, 10) +
-    parseInt(computed.marginBottom, 10)
-}

+ 2 - 1
src/util/misc.ts

@@ -1,4 +1,5 @@
-import { applyStyle, computeHeightAndMargins } from './dom'
+import { applyStyle } from './dom'
+import { computeHeightAndMargins } from './dom-geom'
 import { preventDefault } from './dom-event'
 
 

+ 1 - 1
tests/example-repos/typescript-example

@@ -1 +1 @@
-Subproject commit 6847d0f903047b45582bf275483c78674bc37ee2
+Subproject commit 72891cccdcf0f1b4b30f2aa9b23a38ced64b57a5