Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions date-input-polyfill.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import './date-input-polyfill.scss';
import Input from './input.js';

const addPickers = () => {
// Only initialise if there is an input with type="date" in the document
if (typeof document.querySelectorAll !== 'undefined' && !document.querySelectorAll('input[type="date"]').length) {
return;
}
// Only initialise if the current browser does not support type="date" natively
const isDateSupported = function () {
var i = document.createElement("input");
i.setAttribute("type", "date");
return i.type !== "text";
};
if (isDateSupported()) {
return;
}
// Only now do we need to load dependencies
const Input = require('./input.js').default;

Input.addPickerToOtherInputs();
// Check if type="date" is supported.
if(!Input.supportsDateInput()) {
Expand All @@ -18,6 +33,8 @@ document.addEventListener(`DOMContentLoaded`, () => {

// 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();
});
if (document.body) {
document.querySelector(`body`).addEventListener(`mousedown`, () => {
addPickers();
});
}