forked from brianblakely/nodep-date-input-polyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodep-date-input-polyfill.js
36 lines (30 loc) · 942 Bytes
/
nodep-date-input-polyfill.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
import './nodep-date-input-polyfill.scss';
import Picker from './picker.js';
import Input from './input.js';
// Run the above code on any <input type="date"> in the document, also on dynamically created ones.
// Check if type="date" is supported.
if(!Input.supportsDateInput()) {
const init = ()=> {
Picker.instance = new Picker();
Input.addPickerToDateInputs();
// This is also on mousedown event so it will capture new inputs that might
// be added to the DOM dynamically.
document.querySelector(`body`).addEventListener(`mousedown`, ()=> {
Input.addPickerToDateInputs();
});
};
if(document.readyState === `complete`) {
init();
} else {
let DOMContentLoaded = false;
document.addEventListener(`DOMContentLoaded`, ()=> {
DOMContentLoaded = true;
init();
});
window.addEventListener(`load`, ()=> {
if(!DOMContentLoaded) {
init();
}
});
}
}