]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/core/wrappers/screen.service.ts
Migrate to $localize
[github/Chocobozzz/PeerTube.git] / client / src / app / core / wrappers / screen.service.ts
CommitLineData
fc11a44e 1import { Injectable } from '@angular/core'
bbe0f064
C
2
3@Injectable()
4export class ScreenService {
7034b3c9 5 isBroadcastMessageDisplayed = false
6
bbe0f064 7 private windowInnerWidth: number
fc11a44e
C
8 private lastFunctionCallTime: number
9 private cacheForMs = 500
bbe0f064 10
fc11a44e
C
11 constructor () {
12 this.refreshWindowInnerWidth()
bbe0f064
C
13 }
14
8544d8f5
K
15 isInSmallView (marginLeft = 0) {
16 if (marginLeft > 0) {
17 const contentWidth = this.getWindowInnerWidth() - marginLeft
18 return contentWidth < 800
19 }
20
8ff3f883 21 return this.getWindowInnerWidth() < 800
bbe0f064
C
22 }
23
3b20bdd6
RK
24 isInMediumView () {
25 return this.getWindowInnerWidth() < 1100
26 }
27
bbe0f064 28 isInMobileView () {
fc11a44e
C
29 return this.getWindowInnerWidth() < 500
30 }
31
8dfceec4
C
32 isInTouchScreen () {
33 return 'ontouchstart' in window || navigator.msMaxTouchPoints
34 }
35
6eb62c33
C
36 getNumberOfAvailableMiniatures () {
37 const screenWidth = this.getWindowInnerWidth()
38
39 let numberOfVideos = 1
40
cf78883c
C
41 if (screenWidth > 1850) numberOfVideos = 7
42 else if (screenWidth > 1600) numberOfVideos = 6
43 else if (screenWidth > 1370) numberOfVideos = 5
44 else if (screenWidth > 1100) numberOfVideos = 4
45 else if (screenWidth > 850) numberOfVideos = 3
6eb62c33
C
46
47 return numberOfVideos
48 }
49
fc11a44e 50 // Cache window inner width, because it's an expensive call
6eb62c33 51 getWindowInnerWidth () {
fc11a44e
C
52 if (this.cacheWindowInnerWidthExpired()) this.refreshWindowInnerWidth()
53
54 return this.windowInnerWidth
55 }
56
57 private refreshWindowInnerWidth () {
58 this.lastFunctionCallTime = new Date().getTime()
59
60 this.windowInnerWidth = window.innerWidth
61 }
62
63 private cacheWindowInnerWidthExpired () {
3a0fb65c
C
64 if (!this.lastFunctionCallTime) return true
65
fc11a44e 66 return new Date().getTime() > (this.lastFunctionCallTime + this.cacheForMs)
bbe0f064
C
67 }
68}