forked from serkanyersen/ifvisible.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathifvisible.d.ts
154 lines (128 loc) · 3.74 KB
/
ifvisible.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
interface onEveryReturn {
/**
* Callback function you passed to onEvery
*/
callback: () => void;
/**
* Timer Id of setInterval
*/
code: number;
/**
* Stop the interval, you cannot resume
*/
stop(): boolean;
/**
* Pauses the interval, it's resumable
*/
pause(): boolean;
/**
* Resumes paused interval
*/
resume(): boolean;
}
interface IdleInfo {
/**
* if page idle now?
*/
isIdle: boolean,
/**
* How long was the page idle in milliseconds
*/
idleFor: number,
/**
* How much time left to become idle in milliseconds
*/
timeLeft: number,
/**
* How much time left to become idle represented as percentage
*/
timeLeftPer: string
}
interface IfVisible {
/**
* Registers a callback function to blur event
* @param callback function to run when event fires
*/
blur(callback: () => void): IfVisible;
/**
* Triggers the blur event
*/
blur(): IfVisible;
/**
* Registers a callback function to focus event
* @param callback function to run when event fires
*/
focus(callback: () => void): IfVisible;
/**
* Triggers the focus event
*/
focus(): IfVisible;
/**
* Registers a callback function to idle event
* @param callback function to run when event fires
*/
idle(callback: () => void): IfVisible;
/**
* Triggers the idle event
*/
idle(): IfVisible;
/**
* Registers a callback function to wakeup event
* @param callback function to run when event fires
*/
wakeup(callback: () => void): IfVisible;
/**
* Triggers the wakeup event
*/
wakeup(): IfVisible;
/**
* Register any event
* @param name Name of the event
* @param callback Function to run when event fires
*/
on(name: string, callback: (status?: string) => void): number;
/**
* Unregister given event of name
* @param name name of the event
* @param handler function to remove from registered events
*/
off(name: string, handler: Function): void;
/**
* Unregister all event of given name
* @param name Name to unregister all events of
*/
off(name: string): void;
/**
* Returns the current duration time in milliseconds
*/
getIdleDuration(): number;
/**
* Returns detailed information about current idle status
*/
getIdleInfo(): IdleInfo;
/**
* Given the event, it check if page is in that state for example
* ifvisible.now('idle') return boolean to state if you are idle or not
*/
now(check: string): boolean;
/**
* Tells if page is visible or not at the moment
*/
now(): boolean;
/**
* Utility to run a given function at every given seconds intervals.
* This method is smart and it will stop executing when the page is not active
* @param seconds duration to wait between each interval in seconds
* @param callback callback function run on every iteration
*/
onEvery(seconds: number, callback: () => void): onEveryReturn;
/**
* Let's you change duration that page becomes idle dynamically
* @param seconds new duration in seconds
*/
setIdleDuration(seconds: number): number;
}
declare var ifvisible: IfVisible;
declare module 'ifvisible' {
export = ifvisible;
}