forked from jcgertig/date-input-polyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate-input-polyfill.js
More file actions
28 lines (23 loc) · 801 Bytes
/
Copy pathdate-input-polyfill.js
File metadata and controls
28 lines (23 loc) · 801 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
28
import './date-input-polyfill.scss';
import Input from './input.js';
const addPickers = () => {
Input.addPickerToOtherInputs();
// Check if type="date" is supported.
if(!Input.supportsDateInput()) {
Input.addPickerToDateInputs();
}
};
// Run the above code on any <input type="date"> in the document, also on dynamically created ones.
addPickers();
document.addEventListener(`DOMContentLoaded`, () => {
addPickers();
});
// 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`, () => {
addPickers();
});
// Run the above code after a custom event has fired
document.querySelector(`body`).addEventListener(`addDateInputPolyfillPickers`, () => {
addPickers();
});