-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #1183 Add flatpickr as a datepicker (atierant)
- Loading branch information
Showing
38 changed files
with
1,497 additions
and
1,752 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,5 @@ import './js/doclinks.js'; | |
|
||
// start the Stimulus application | ||
import './bootstrap'; | ||
|
||
import './js/flatpicker'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'flatpickr'; | ||
import 'flatpickr/dist/flatpickr.css'; | ||
|
||
flatpickr.defaultConfig.animate = window.navigator.userAgent.indexOf('MSIE') === -1; | ||
const locale = $('html').getAttribute('lang') || 'en'; | ||
const Locale = require(`flatpickr/dist/l10n/${locale}.js`).default[locale]; | ||
flatpickr.localize(Locale); | ||
const configs = { | ||
standard: { | ||
enableTime: true, | ||
dateFormat: "Y-m-d H:i", | ||
allowInput: true, | ||
time_24hr: true, | ||
defaultHour: 24, | ||
parseDate: (datestr, format) => { | ||
return flatpickr.parseDate(datestr, format); | ||
}, | ||
formatDate: (date, format, locale) => { | ||
return flatpickr.formatDate(date, format); | ||
} | ||
} | ||
}; | ||
|
||
const flatpickrs = document.querySelectorAll(".flatpickr"); | ||
for (let i = 0; i < flatpickrs.length; i++) { | ||
let element = flatpickrs[i]; | ||
let configValue = configs[element.getAttribute("data-flatpickr-class")] || {}; | ||
// Overrides the default format with the one sent by data attribute | ||
configValue.dateFormat = element.getAttribute("data-date-format") || 'Y-m-d H:i'; | ||
// ...and then initialize the flatpickr | ||
flatpickr(element, configValue); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// setting the value of this variable to an empty data URL is the only working solution | ||
// to load the Bootswatch web fonts locally and avoid loading them from Google servers | ||
// see https://github.com/thomaspark/bootswatch/issues/55#issuecomment-298093182 | ||
$web-font-path: 'data:text/css;base64,'; | ||
|
||
// Make sure the bootstrap-sass and lato fonts are resolved correctly | ||
//$icon-font-path: "~bootstrap-sass/assets/fonts/bootstrap/"; | ||
$lato-font-path: '~lato-font/fonts'; | ||
|
||
$font-default: 17px; | ||
$font-heading: 2.5rem; | ||
$font-title: 1.85rem; | ||
|
||
$secondary-color: #ecf0f1; | ||
$gray-7500: #e9ecec; | ||
|
||
@import "~bootswatch/dist/flatly/variables"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.