]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/misc/utils.ts
Fix upnext, refactor avatar menu, add to playlist overflow
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / misc / utils.ts
index f26240d216eee3461aab8d85eb20f12326d386b0..b1d1fc0b5257a7f3d4c5795e5c8727cab9ab7810 100644 (file)
@@ -169,6 +169,26 @@ function importModule (path: string) {
   })
 }
 
+function isInViewport (el: HTMLElement) {
+  const bounding = el.getBoundingClientRect()
+  return (
+      bounding.top >= 0 &&
+      bounding.left >= 0 &&
+      bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
+      bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
+  )
+}
+
+function isXPercentInViewport (el: HTMLElement, percentVisible: number) {
+  const rect = el.getBoundingClientRect()
+  const windowHeight = (window.innerHeight || document.documentElement.clientHeight)
+
+  return !(
+    Math.floor(100 - (((rect.top >= 0 ? 0 : rect.top) / +-(rect.height / 1)) * 100)) < percentVisible ||
+    Math.floor(100 - ((rect.bottom - windowHeight) / rect.height) * 100) < percentVisible
+  )
+}
+
 export {
   sortBy,
   durationToString,
@@ -183,5 +203,7 @@ export {
   objectLineFeedToHtml,
   removeElementFromArray,
   importModule,
-  scrollToTop
+  scrollToTop,
+  isInViewport,
+  isXPercentInViewport
 }