-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathready.js
More file actions
27 lines (24 loc) · 781 Bytes
/
ready.js
File metadata and controls
27 lines (24 loc) · 781 Bytes
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
// this monkey patched a ready function onto document
// https://gist.github.com/tjbenton/4186f003329c623e53f5d4a31744b054
// adopted to not do the monkey patch
module.exports = function () {
let doc = document
let win = window
let add = 'addEventListener'
let remove = 'removeEventListener'
let loaded = 'DOMContentLoaded'
let load = 'load'
return new Promise(function (resolve) {
if (doc.readyState === 'complete') {
resolve();
} else {
function onReady() {
resolve();
doc[remove](loaded, onReady, true);
win[remove](load, onReady, true);
}
doc[add](loaded, onReady, true);
win[add](load, onReady, true);
}
})
}