mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
Throught the plugin: https://github.com/jcsmorais/shortcut-buttons-flatpickr import js library via yarn
62 lines
1.5 KiB
Plaintext
62 lines
1.5 KiB
Plaintext
$(document).ready(function(){
|
|
window.FLATPICKR_DATE_DEFAULT = {
|
|
dateFormat: Spree.translations.flatpickr_date_format,
|
|
locale: I18n.locale,
|
|
plugins: [
|
|
ShortcutButtonsPlugin({
|
|
button: [{
|
|
label: "Today"
|
|
}],
|
|
label: "or",
|
|
onClick: (index, fp) => {
|
|
let date;
|
|
switch (index) {
|
|
case 0:
|
|
date = new Date();
|
|
break;
|
|
}
|
|
fp.setDate(date);
|
|
}
|
|
})
|
|
]
|
|
}
|
|
window.FLATPICKR_DATETIME_DEFAULT = Object.assign(
|
|
{},
|
|
window.FLATPICKR_DATE_DEFAULT,
|
|
{
|
|
enableTime: true,
|
|
time_24hr: true,
|
|
plugins: [
|
|
ShortcutButtonsPlugin({
|
|
button: [{
|
|
label: "Now"
|
|
}],
|
|
label: "or",
|
|
onClick: (index, fp) => {
|
|
let date;
|
|
switch (index) {
|
|
case 0:
|
|
date = new Date();
|
|
break;
|
|
}
|
|
fp.setDate(date);
|
|
}
|
|
})
|
|
]
|
|
}
|
|
);
|
|
flatpickr(".datetimepicker", window.FLATPICKR_DATETIME_DEFAULT);
|
|
$('a.close').click(function(event){
|
|
event.preventDefault();
|
|
$(this).parent().slideUp(250);
|
|
});
|
|
|
|
// Spree locates hidden with prev(), which with our current version of jQuery
|
|
// does not locate the hidden field, resulting in the delete failing. This
|
|
// handler updates the hidden field, fixing the problem.
|
|
$('body').on('click', 'a.remove_fields', function() {
|
|
$(this).next("input[type=hidden]").val("1");
|
|
return false;
|
|
});
|
|
});
|