-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupFile.js
62 lines (51 loc) · 1.44 KB
/
setupFile.js
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
global.window.resizeTo = (width, height) => {
global.window.outerWidth = width || global.window.outerWidth
global.window.outerHeight = height || global.window.outerHeight
global.window.dispatchEvent(new Event('resize'))
}
global.window.online = () => {
navigator.__defineGetter__('onLine', () => true)
global.window.dispatchEvent(new Event('online'))
}
global.window.offline = () => {
navigator.__defineGetter__('onLine', () => false)
global.window.dispatchEvent(new Event('offline'))
}
global.window.keyPress = key => {
global.window.dispatchEvent(new KeyboardEvent('keydown', { keyCode: key }))
}
let hidden = false
Object.defineProperty(global.window.document, 'hidden', {
configurable: true,
get: function() {
return hidden
}
})
global.window.show = () => {
hidden = false
global.window.document.dispatchEvent(new Event('visibilitychange'))
}
global.window.hide = () => {
hidden = true
global.window.document.dispatchEvent(new Event('visibilitychange'))
}
let pageXOffset = 0
let pageYOffset = 0
Object.defineProperty(global.window, 'pageXOffset', {
configurable: true,
get: function() {
return pageXOffset
}
})
Object.defineProperty(global.window, 'pageYOffset', {
configurable: true,
get: function() {
return pageYOffset
}
})
global.window.scrollTo = (x, y) => {
pageXOffset = x
pageYOffset = y
global.window.dispatchEvent(new UIEvent('scroll'))
}
global.window.requestAnimationFrame = cb => cb()