diff options
author | Chocobozzz <me@florianbigard.com> | 2021-08-19 09:24:29 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-25 11:24:11 +0200 |
commit | dd24f1bb0a4b252e5342b251ba36853364da7b8e (patch) | |
tree | 41a9506d07413f056fb90425705e258f96fdc77d /client/src/app/helpers/utils/ui.ts | |
parent | 2e80d256cc75b4b02c8efc3d3e4cdf57ddf401a8 (diff) | |
download | PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.tar.gz PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.tar.zst PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.zip |
Add video filters to common video pages
Diffstat (limited to 'client/src/app/helpers/utils/ui.ts')
-rw-r--r-- | client/src/app/helpers/utils/ui.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/client/src/app/helpers/utils/ui.ts b/client/src/app/helpers/utils/ui.ts new file mode 100644 index 000000000..ac8298926 --- /dev/null +++ b/client/src/app/helpers/utils/ui.ts | |||
@@ -0,0 +1,33 @@ | |||
1 | function scrollToTop (behavior: 'auto' | 'smooth' = 'auto') { | ||
2 | window.scrollTo({ | ||
3 | left: 0, | ||
4 | top: 0, | ||
5 | behavior | ||
6 | }) | ||
7 | } | ||
8 | |||
9 | function isInViewport (el: HTMLElement) { | ||
10 | const bounding = el.getBoundingClientRect() | ||
11 | return ( | ||
12 | bounding.top >= 0 && | ||
13 | bounding.left >= 0 && | ||
14 | bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) && | ||
15 | bounding.right <= (window.innerWidth || document.documentElement.clientWidth) | ||
16 | ) | ||
17 | } | ||
18 | |||
19 | function isXPercentInViewport (el: HTMLElement, percentVisible: number) { | ||
20 | const rect = el.getBoundingClientRect() | ||
21 | const windowHeight = (window.innerHeight || document.documentElement.clientHeight) | ||
22 | |||
23 | return !( | ||
24 | Math.floor(100 - (((rect.top >= 0 ? 0 : rect.top) / +-(rect.height / 1)) * 100)) < percentVisible || | ||
25 | Math.floor(100 - ((rect.bottom - windowHeight) / rect.height) * 100) < percentVisible | ||
26 | ) | ||
27 | } | ||
28 | |||
29 | export { | ||
30 | scrollToTop, | ||
31 | isInViewport, | ||
32 | isXPercentInViewport | ||
33 | } | ||