murph-skeleton/assets/js/admin/modules/datepicker.js

31 lines
620 B
JavaScript
Raw Normal View History

2021-03-24 12:27:07 +01:00
const Datepicker = require('vanillajs-datepicker')
const isDateSupported = () => {
2021-06-15 14:16:07 +02:00
const input = document.createElement('input')
const value = 'a'
2021-03-24 12:27:07 +01:00
2021-06-15 14:16:07 +02:00
input.setAttribute('type', 'date')
input.setAttribute('value', value)
2021-03-24 12:27:07 +01:00
2021-06-15 14:16:07 +02:00
return input.value !== value
2021-03-24 12:27:07 +01:00
}
2021-06-23 09:39:51 +02:00
const createDatePicker = (input) => {
return new Datepicker.Datepicker(input, {
format: 'yyyy-mm-dd'
})
}
2021-03-24 12:27:07 +01:00
module.exports = () => {
2021-06-15 14:16:07 +02:00
if (isDateSupported()) {
return
}
2021-03-24 12:27:07 +01:00
2021-06-15 14:16:07 +02:00
const inputs = document.querySelectorAll('input[type="date"]')
const size = inputs.length
2021-03-24 12:27:07 +01:00
2021-06-23 09:39:51 +02:00
for (let i = 0, c = size; i < c; i++) {
createDatePicker(inputs[i])
2021-06-15 14:16:07 +02:00
}
2021-03-24 12:27:07 +01:00
}