Skip to content

Commit 4a1d48b

Browse files
committed
feature #1183 Add flatpickr as a datepicker (atierant)
1 parent 5633a63 commit 4a1d48b

38 files changed

+1497
-1752
lines changed

assets/admin.js

-19
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import './styles/admin.scss';
22
import 'typeahead.js';
33
import Bloodhound from "bloodhound-js";
44
import 'bootstrap-tagsinput';
5-
import 'flatpickr';
6-
import 'flatpickr/dist/flatpickr.css';
7-
import moment from 'moment';
85

96
$(function() {
107
// Bootstrap-tagsinput initialization
@@ -27,22 +24,6 @@ $(function() {
2724
}
2825
});
2926
}
30-
31-
const locale = $('#post_publishedAt').data('date-locale');
32-
const Locale = require(`flatpickr/dist/l10n/${locale}.js`).default[locale];
33-
flatpickr.localize(Locale);
34-
35-
$('[data-toggle="datetimepicker"]').flatpickr({
36-
enableTime: true,
37-
dateFormat: $('#post_publishedAt').data('date-format'),
38-
allowInput: true,
39-
parseDate: (datestr, format) => {
40-
return moment(datestr, format, true).toDate();
41-
},
42-
formatDate: (date, format, locale) => {
43-
return moment(date).format(format);
44-
}
45-
});
4627
});
4728

4829
// Handling the modal confirmation message.

assets/app.js

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ import './js/doclinks.js';
1515

1616
// start the Stimulus application
1717
import './bootstrap';
18+
19+
import './js/flatpicker';

assets/js/flatpicker.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import 'flatpickr';
2+
import 'flatpickr/dist/flatpickr.css';
3+
4+
flatpickr.defaultConfig.animate = window.navigator.userAgent.indexOf('MSIE') === -1;
5+
const locale = $('html').getAttribute('lang') || 'en';
6+
const Locale = require(`flatpickr/dist/l10n/${locale}.js`).default[locale];
7+
flatpickr.localize(Locale);
8+
const configs = {
9+
standard: {
10+
enableTime: true,
11+
dateFormat: "Y-m-d H:i",
12+
allowInput: true,
13+
time_24hr: true,
14+
defaultHour: 24,
15+
parseDate: (datestr, format) => {
16+
return flatpickr.parseDate(datestr, format);
17+
},
18+
formatDate: (date, format, locale) => {
19+
return flatpickr.formatDate(date, format);
20+
}
21+
}
22+
};
23+
24+
const flatpickrs = document.querySelectorAll(".flatpickr");
25+
for (let i = 0; i < flatpickrs.length; i++) {
26+
let element = flatpickrs[i];
27+
let configValue = configs[element.getAttribute("data-flatpickr-class")] || {};
28+
// Overrides the default format with the one sent by data attribute
29+
configValue.dateFormat = element.getAttribute("data-date-format") || 'Y-m-d H:i';
30+
// ...and then initialize the flatpickr
31+
flatpickr(element, configValue);
32+
}

assets/styles/_variables.scss

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// setting the value of this variable to an empty data URL is the only working solution
2+
// to load the Bootswatch web fonts locally and avoid loading them from Google servers
3+
// see https://github.com/thomaspark/bootswatch/issues/55#issuecomment-298093182
4+
$web-font-path: 'data:text/css;base64,';
5+
6+
// Make sure the bootstrap-sass and lato fonts are resolved correctly
7+
//$icon-font-path: "~bootstrap-sass/assets/fonts/bootstrap/";
8+
$lato-font-path: '~lato-font/fonts';
9+
10+
$font-default: 17px;
11+
$font-heading: 2.5rem;
12+
$font-title: 1.85rem;
13+
14+
$secondary-color: #ecf0f1;
15+
$gray-7500: #e9ecec;
16+
17+
@import "~bootswatch/dist/flatly/variables";

assets/styles/app.scss

+1-27
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
// setting the value of this variable to an empty data URL is the only working solution
2-
// to load the Bootswatch web fonts locally and avoid loading them from Google servers
3-
// see https://github.com/thomaspark/bootswatch/issues/55#issuecomment-298093182
4-
$web-font-path: 'data:text/css;base64,';
5-
6-
// Make sure the bootstrap-sass and lato fonts are resolved correctly
7-
$icon-font-path: "~bootstrap-sass/assets/fonts/bootstrap/";
8-
$lato-font-path: '~lato-font/fonts';
9-
10-
$font-default: 17px;
11-
$font-heading: 2.5rem;
12-
$font-title: 1.85rem;
13-
14-
$secondary-color: #ecf0f1;
15-
$gray-7500: #e9ecec;
16-
17-
@import "~bootswatch/dist/flatly/variables";
1+
@import "variables";
182

193
// @import "~bootstrap/scss/bootstrap.scss";
204
@import "~bootstrap/scss/functions";
@@ -55,8 +39,6 @@ $gray-7500: #e9ecec;
5539
@import "~bootstrap/scss/utilities";
5640
// @import "~bootstrap/scss/print";
5741

58-
@import "~bootstrap-sass/assets/stylesheets/bootstrap";
59-
6042
@import "~bootswatch/dist/flatly/bootswatch";
6143
@import "~@fortawesome/fontawesome-free/css/all.css";
6244
@import "~@fortawesome/fontawesome-free/css/v4-shims.css";
@@ -124,14 +106,6 @@ a:hover {
124106
------------------------------------------------------------------------- */
125107
.m-b-0 { margin-bottom: 0 }
126108

127-
@media (min-width: $screen-md-min) {
128-
.modal-xl { width: $modal-lg; }
129-
}
130-
131-
@media (min-width: $screen-lg-min) {
132-
.modal-xl { width: $screen-lg-min - 60px; }
133-
}
134-
135109
.badge{
136110
padding: 0.25em 0.4em 0.27em 0.4em
137111
}

0 commit comments

Comments
 (0)