flatpickr_rails 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -21
- data/lib/flatpickr_rails/version.rb +1 -1
- data/vendor/assets/javascripts/flatpickr.js +1506 -0
- data/vendor/assets/javascripts/flatpickr/l10n/ar.js +16 -0
- data/vendor/assets/javascripts/flatpickr/l10n/bg.js +16 -0
- data/vendor/assets/javascripts/flatpickr/l10n/bn.js +16 -0
- data/vendor/assets/javascripts/flatpickr/l10n/cat.js +36 -0
- data/vendor/assets/javascripts/flatpickr/l10n/cs.js +22 -0
- data/vendor/assets/javascripts/flatpickr/l10n/da.js +20 -0
- data/vendor/assets/javascripts/flatpickr/l10n/de.js +16 -0
- data/vendor/assets/javascripts/flatpickr/l10n/es.js +22 -0
- data/vendor/assets/javascripts/flatpickr/l10n/et.js +27 -0
- data/vendor/assets/javascripts/flatpickr/l10n/fa.js +20 -0
- data/vendor/assets/javascripts/flatpickr/l10n/fi.js +22 -0
- data/vendor/assets/javascripts/flatpickr/l10n/fr.js +26 -0
- data/vendor/assets/javascripts/flatpickr/l10n/he.js +16 -0
- data/vendor/assets/javascripts/flatpickr/l10n/hi.js +16 -0
- data/vendor/assets/javascripts/flatpickr/l10n/hr.js +19 -0
- data/vendor/assets/javascripts/flatpickr/l10n/hu.js +27 -0
- data/vendor/assets/javascripts/flatpickr/l10n/id.js +22 -0
- data/vendor/assets/javascripts/flatpickr/l10n/it.js +27 -0
- data/vendor/assets/javascripts/flatpickr/l10n/ja.js +16 -0
- data/vendor/assets/javascripts/flatpickr/l10n/ko.js +20 -0
- data/vendor/assets/javascripts/flatpickr/l10n/ms.js +22 -0
- data/vendor/assets/javascripts/flatpickr/l10n/my.js +22 -0
- data/vendor/assets/javascripts/flatpickr/l10n/nl.js +26 -0
- data/vendor/assets/javascripts/flatpickr/l10n/no.js +20 -0
- data/vendor/assets/javascripts/flatpickr/l10n/pa.js +16 -0
- data/vendor/assets/javascripts/flatpickr/l10n/pl.js +20 -0
- data/vendor/assets/javascripts/flatpickr/l10n/pt.js +16 -0
- data/vendor/assets/javascripts/flatpickr/l10n/ro.js +23 -0
- data/vendor/assets/javascripts/flatpickr/l10n/ru.js +16 -0
- data/vendor/assets/javascripts/flatpickr/l10n/si.js +17 -0
- data/vendor/assets/javascripts/flatpickr/l10n/sq.js +16 -0
- data/vendor/assets/javascripts/flatpickr/l10n/sv.js +22 -0
- data/vendor/assets/javascripts/flatpickr/l10n/tr.js +18 -0
- data/vendor/assets/javascripts/flatpickr/l10n/uk.js +16 -0
- data/vendor/assets/javascripts/flatpickr/l10n/vn.js +19 -0
- data/vendor/assets/javascripts/flatpickr/l10n/zh.js +17 -0
- data/vendor/assets/stylesheets/flatpickr.airbnb.css +1 -0
- data/vendor/assets/stylesheets/flatpickr.base16_flat.css +1 -0
- data/vendor/assets/stylesheets/flatpickr.confetti.css +1 -246
- data/vendor/assets/stylesheets/flatpickr.css +1 -242
- data/vendor/assets/stylesheets/flatpickr.dark.css +1 -243
- data/vendor/assets/stylesheets/flatpickr.material_blue.css +1 -246
- data/vendor/assets/stylesheets/flatpickr.material_green.css +1 -246
- data/vendor/assets/stylesheets/flatpickr.material_orange.css +1 -246
- data/vendor/assets/stylesheets/flatpickr.material_red.css +1 -246
- metadata +42 -6
- data/vendor/assets/javascripts/flatpickr/core.js +0 -1034
- data/vendor/assets/javascripts/flatpickr/index.js +0 -1
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flatpickr_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jiren
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -88,8 +88,45 @@ files:
|
|
88
88
|
- lib/flatpickr_rails/engine.rb
|
89
89
|
- lib/flatpickr_rails/railtie.rb
|
90
90
|
- lib/flatpickr_rails/version.rb
|
91
|
-
- vendor/assets/javascripts/flatpickr
|
92
|
-
- vendor/assets/javascripts/flatpickr/
|
91
|
+
- vendor/assets/javascripts/flatpickr.js
|
92
|
+
- vendor/assets/javascripts/flatpickr/l10n/ar.js
|
93
|
+
- vendor/assets/javascripts/flatpickr/l10n/bg.js
|
94
|
+
- vendor/assets/javascripts/flatpickr/l10n/bn.js
|
95
|
+
- vendor/assets/javascripts/flatpickr/l10n/cat.js
|
96
|
+
- vendor/assets/javascripts/flatpickr/l10n/cs.js
|
97
|
+
- vendor/assets/javascripts/flatpickr/l10n/da.js
|
98
|
+
- vendor/assets/javascripts/flatpickr/l10n/de.js
|
99
|
+
- vendor/assets/javascripts/flatpickr/l10n/es.js
|
100
|
+
- vendor/assets/javascripts/flatpickr/l10n/et.js
|
101
|
+
- vendor/assets/javascripts/flatpickr/l10n/fa.js
|
102
|
+
- vendor/assets/javascripts/flatpickr/l10n/fi.js
|
103
|
+
- vendor/assets/javascripts/flatpickr/l10n/fr.js
|
104
|
+
- vendor/assets/javascripts/flatpickr/l10n/he.js
|
105
|
+
- vendor/assets/javascripts/flatpickr/l10n/hi.js
|
106
|
+
- vendor/assets/javascripts/flatpickr/l10n/hr.js
|
107
|
+
- vendor/assets/javascripts/flatpickr/l10n/hu.js
|
108
|
+
- vendor/assets/javascripts/flatpickr/l10n/id.js
|
109
|
+
- vendor/assets/javascripts/flatpickr/l10n/it.js
|
110
|
+
- vendor/assets/javascripts/flatpickr/l10n/ja.js
|
111
|
+
- vendor/assets/javascripts/flatpickr/l10n/ko.js
|
112
|
+
- vendor/assets/javascripts/flatpickr/l10n/ms.js
|
113
|
+
- vendor/assets/javascripts/flatpickr/l10n/my.js
|
114
|
+
- vendor/assets/javascripts/flatpickr/l10n/nl.js
|
115
|
+
- vendor/assets/javascripts/flatpickr/l10n/no.js
|
116
|
+
- vendor/assets/javascripts/flatpickr/l10n/pa.js
|
117
|
+
- vendor/assets/javascripts/flatpickr/l10n/pl.js
|
118
|
+
- vendor/assets/javascripts/flatpickr/l10n/pt.js
|
119
|
+
- vendor/assets/javascripts/flatpickr/l10n/ro.js
|
120
|
+
- vendor/assets/javascripts/flatpickr/l10n/ru.js
|
121
|
+
- vendor/assets/javascripts/flatpickr/l10n/si.js
|
122
|
+
- vendor/assets/javascripts/flatpickr/l10n/sq.js
|
123
|
+
- vendor/assets/javascripts/flatpickr/l10n/sv.js
|
124
|
+
- vendor/assets/javascripts/flatpickr/l10n/tr.js
|
125
|
+
- vendor/assets/javascripts/flatpickr/l10n/uk.js
|
126
|
+
- vendor/assets/javascripts/flatpickr/l10n/vn.js
|
127
|
+
- vendor/assets/javascripts/flatpickr/l10n/zh.js
|
128
|
+
- vendor/assets/stylesheets/flatpickr.airbnb.css
|
129
|
+
- vendor/assets/stylesheets/flatpickr.base16_flat.css
|
93
130
|
- vendor/assets/stylesheets/flatpickr.confetti.css
|
94
131
|
- vendor/assets/stylesheets/flatpickr.css
|
95
132
|
- vendor/assets/stylesheets/flatpickr.dark.css
|
@@ -117,9 +154,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
154
|
version: '0'
|
118
155
|
requirements: []
|
119
156
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.
|
157
|
+
rubygems_version: 2.5.1
|
121
158
|
signing_key:
|
122
159
|
specification_version: 4
|
123
160
|
summary: A lightweight & powerful datetimepicker gem
|
124
161
|
test_files: []
|
125
|
-
has_rdoc:
|
@@ -1,1034 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
|
4
|
-
|
5
|
-
var flatpickr = function flatpickr(selector, config) {
|
6
|
-
'use strict';
|
7
|
-
|
8
|
-
var elements = void 0,
|
9
|
-
instances = void 0,
|
10
|
-
createInstance = function createInstance(element) {
|
11
|
-
if (element._flatpickr) element._flatpickr.destroy();
|
12
|
-
|
13
|
-
element._flatpickr = new flatpickr.init(element, config);
|
14
|
-
return element._flatpickr;
|
15
|
-
};
|
16
|
-
|
17
|
-
if (selector.nodeName) return createInstance(selector);
|
18
|
-
/*
|
19
|
-
Utilize the performance of native getters if applicable
|
20
|
-
https://jsperf.com/getelementsbyclassname-vs-queryselectorall/18
|
21
|
-
https://jsperf.com/jquery-vs-javascript-performance-comparison/22
|
22
|
-
*/
|
23
|
-
else if (/^\#[a-zA-Z0-9\-\_]*$/.test(selector)) return createInstance(document.getElementById(selector.slice(1)));else if (/^\.[a-zA-Z0-9\-\_]*$/.test(selector)) elements = document.getElementsByClassName(selector.slice(1));else elements = document.querySelectorAll(selector);
|
24
|
-
|
25
|
-
instances = [].slice.call(elements).map(createInstance);
|
26
|
-
|
27
|
-
return {
|
28
|
-
calendars: instances,
|
29
|
-
byID: function byID(id) {
|
30
|
-
for (var i = 0; i < instances.length; i++) {
|
31
|
-
if (instances[i].element.id === id) return instances[i];
|
32
|
-
}
|
33
|
-
}
|
34
|
-
|
35
|
-
};
|
36
|
-
};
|
37
|
-
|
38
|
-
/**
|
39
|
-
* @constructor
|
40
|
-
*/
|
41
|
-
flatpickr.init = function (element, instanceConfig) {
|
42
|
-
'use strict';
|
43
|
-
|
44
|
-
var createElement = function createElement(tag, className, content) {
|
45
|
-
|
46
|
-
var element = document.createElement(tag);
|
47
|
-
|
48
|
-
if (content) element.innerHTML = content;
|
49
|
-
|
50
|
-
if (className) element.className = className;
|
51
|
-
|
52
|
-
return element;
|
53
|
-
};
|
54
|
-
|
55
|
-
function throttle(callback, limit) {
|
56
|
-
var wait = false;
|
57
|
-
return function () {
|
58
|
-
if (!wait) {
|
59
|
-
callback.call();
|
60
|
-
wait = true;
|
61
|
-
setTimeout(function () {
|
62
|
-
wait = false;
|
63
|
-
}, limit);
|
64
|
-
}
|
65
|
-
};
|
66
|
-
}
|
67
|
-
|
68
|
-
// functions
|
69
|
-
var self = this,
|
70
|
-
init,
|
71
|
-
wrap,
|
72
|
-
uDate,
|
73
|
-
equalDates,
|
74
|
-
pad,
|
75
|
-
formatDate,
|
76
|
-
monthToStr,
|
77
|
-
isDisabled,
|
78
|
-
buildMonthNavigation,
|
79
|
-
buildWeekdays,
|
80
|
-
buildCalendar,
|
81
|
-
buildDays,
|
82
|
-
buildWeeks,
|
83
|
-
buildTime,
|
84
|
-
timeWrapper,
|
85
|
-
yearScroll,
|
86
|
-
updateValue,
|
87
|
-
onInput,
|
88
|
-
updateNavigationCurrentMonth,
|
89
|
-
handleYearChange,
|
90
|
-
changeMonth,
|
91
|
-
getDaysinMonth,
|
92
|
-
documentClick,
|
93
|
-
calendarClick,
|
94
|
-
getRandomCalendarIdStr,
|
95
|
-
bind,
|
96
|
-
triggerChange;
|
97
|
-
|
98
|
-
// elements & variables
|
99
|
-
var calendarContainer,
|
100
|
-
navigationCurrentMonth,
|
101
|
-
monthsNav,
|
102
|
-
prevMonthNav,
|
103
|
-
cur_year,
|
104
|
-
cur_month,
|
105
|
-
nextMonthNav,
|
106
|
-
calendar,
|
107
|
-
weekNumbers,
|
108
|
-
currentDate = new Date(),
|
109
|
-
wrapperElement,
|
110
|
-
hourElement,
|
111
|
-
minuteElement,
|
112
|
-
secondElement,
|
113
|
-
am_pm,
|
114
|
-
clickEvt;
|
115
|
-
|
116
|
-
init = function init() {
|
117
|
-
|
118
|
-
instanceConfig = instanceConfig || {};
|
119
|
-
|
120
|
-
self.config = {};
|
121
|
-
self.element = element;
|
122
|
-
|
123
|
-
for (var config in self.defaultConfig) {
|
124
|
-
self.config[config] = instanceConfig[config] || self.element.dataset && self.element.dataset[config.toLowerCase()] || self.element.getAttribute("data-" + config) || self.defaultConfig[config];
|
125
|
-
}self.input = self.config.wrap ? element.querySelector("[data-input]") : element;
|
126
|
-
self.input.classList.add("flatpickr-input");
|
127
|
-
|
128
|
-
if (self.config.defaultDate) self.config.defaultDate = uDate(self.config.defaultDate);
|
129
|
-
|
130
|
-
if (self.input.value || self.config.defaultDate) self.selectedDateObj = uDate(self.config.defaultDate || self.input.value);
|
131
|
-
|
132
|
-
wrap();
|
133
|
-
buildCalendar();
|
134
|
-
bind();
|
135
|
-
|
136
|
-
self.uDate = uDate;
|
137
|
-
|
138
|
-
self.jumpToDate();
|
139
|
-
updateValue();
|
140
|
-
};
|
141
|
-
|
142
|
-
getRandomCalendarIdStr = function getRandomCalendarIdStr() {
|
143
|
-
var randNum = void 0,
|
144
|
-
idStr = void 0;
|
145
|
-
do {
|
146
|
-
randNum = Math.round(Math.random() * Math.pow(10, 10));
|
147
|
-
idStr = 'flatpickr-' + randNum;
|
148
|
-
} while (document.getElementById(idStr) !== null);
|
149
|
-
return idStr;
|
150
|
-
};
|
151
|
-
|
152
|
-
uDate = function uDate(date, timeless) {
|
153
|
-
|
154
|
-
timeless = timeless || false;
|
155
|
-
|
156
|
-
if (date === 'today') {
|
157
|
-
date = new Date();
|
158
|
-
timeless = true;
|
159
|
-
} else if (typeof date === 'string') {
|
160
|
-
|
161
|
-
date = date.trim();
|
162
|
-
|
163
|
-
if (self.config.parseDate) date = self.config.parseDate(date);else if (/^\d\d\d\d\-\d{1,2}\-\d\d$/.test(date))
|
164
|
-
// this utc datestring gets parsed, but incorrectly by Date.parse
|
165
|
-
date = new Date(date.replace(/(\d)-(\d)/g, "$1/$2"));else if (Date.parse(date)) date = new Date(date);else if (/^\d\d\d\d\-\d\d\-\d\d/.test(date)) // disable special utc datestring
|
166
|
-
date = new Date(date.replace(/(\d)-(\d)/g, "$1/$2"));else if (/^(\d?\d):(\d\d)/.test(date)) {
|
167
|
-
// time-only picker
|
168
|
-
var matches = date.match(/^(\d?\d):(\d\d)(:(\d\d))?/);
|
169
|
-
|
170
|
-
var seconds = 0;
|
171
|
-
if (matches[4] !== undefined) seconds = matches[4];
|
172
|
-
|
173
|
-
date = new Date();
|
174
|
-
date.setHours(matches[1], matches[2], seconds, 0);
|
175
|
-
} else {
|
176
|
-
console.error('flatpickr: invalid date string ' + date);
|
177
|
-
console.info(self.element);
|
178
|
-
}
|
179
|
-
}
|
180
|
-
|
181
|
-
if (timeless && date) date.setHours(0, 0, 0, 0);
|
182
|
-
|
183
|
-
if (String(self.config.utc) === 'true' && date && !date.fp_isUTC) date = date.fp_toUTC();
|
184
|
-
|
185
|
-
return date;
|
186
|
-
};
|
187
|
-
|
188
|
-
equalDates = function equalDates(date1, date2) {
|
189
|
-
return date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() && date1.getDate() === date2.getDate();
|
190
|
-
};
|
191
|
-
|
192
|
-
wrap = function wrap() {
|
193
|
-
|
194
|
-
wrapperElement = createElement("div", "flatpickr-wrapper");
|
195
|
-
|
196
|
-
if (self.config.inline || self.config.static) {
|
197
|
-
// Wrap input and place calendar underneath
|
198
|
-
self.element.parentNode.insertBefore(wrapperElement, self.element);
|
199
|
-
wrapperElement.appendChild(self.element);
|
200
|
-
|
201
|
-
wrapperElement.classList.add(self.config.inline ? 'inline' : 'static');
|
202
|
-
} else
|
203
|
-
// Insert at bottom of BODY tag to display outside
|
204
|
-
// of relative positioned elements with css 'overflow: hidden;'
|
205
|
-
// property set.
|
206
|
-
document.body.appendChild(wrapperElement);
|
207
|
-
|
208
|
-
if (self.config.altInput) {
|
209
|
-
// replicate self.element
|
210
|
-
self.altInput = createElement(self.input.nodeName, self.config.altInputClass + " flatpickr-input");
|
211
|
-
self.altInput.placeholder = self.input.placeholder;
|
212
|
-
self.altInput.type = "text";
|
213
|
-
|
214
|
-
self.input.type = 'hidden';
|
215
|
-
self.input.parentNode.insertBefore(self.altInput, self.input.nextSibling);
|
216
|
-
}
|
217
|
-
};
|
218
|
-
|
219
|
-
getDaysinMonth = function getDaysinMonth(givenMonth) {
|
220
|
-
|
221
|
-
var yr = self.currentYear,
|
222
|
-
month = givenMonth || self.currentMonth;
|
223
|
-
|
224
|
-
if (month === 1 && yr % 4 === 0 && yr % 100 !== 0 || yr % 400 === 0) return 29;
|
225
|
-
|
226
|
-
return self.l10n.daysInMonth[month];
|
227
|
-
};
|
228
|
-
|
229
|
-
updateValue = function updateValue() {
|
230
|
-
|
231
|
-
var prev_date = void 0;
|
232
|
-
|
233
|
-
if (self.selectedDateObj && self.config.enableTime) {
|
234
|
-
|
235
|
-
prev_date = self.selectedDateObj.getTime();
|
236
|
-
|
237
|
-
// update time
|
238
|
-
var hours = parseInt(hourElement.value, 10) || 0,
|
239
|
-
minutes = (60 + (parseInt(minuteElement.value, 10) || 0)) % 60,
|
240
|
-
seconds;
|
241
|
-
|
242
|
-
if (self.config.enableSeconds) seconds = (60 + parseInt(secondElement.value, 10) || 0) % 60;
|
243
|
-
|
244
|
-
if (!self.config.time_24hr) hours = hours % 12 + 12 * (am_pm.innerHTML === "PM");
|
245
|
-
|
246
|
-
self.selectedDateObj.setHours(hours, minutes, seconds === undefined ? self.selectedDateObj.getSeconds() : seconds);
|
247
|
-
|
248
|
-
hourElement.value = pad(self.config.time_24hr ? hours : (12 + hours) % 12 + 12 * (hours % 12 === 0));
|
249
|
-
|
250
|
-
minuteElement.value = pad(minutes);
|
251
|
-
|
252
|
-
if (seconds !== undefined) secondElement.value = pad(seconds);
|
253
|
-
}
|
254
|
-
|
255
|
-
if (self.altInput && self.selectedDateObj) self.altInput.value = formatDate(self.config.altFormat);
|
256
|
-
|
257
|
-
if (self.selectedDateObj) self.input.value = formatDate(self.config.dateFormat);
|
258
|
-
|
259
|
-
if (prev_date && self.selectedDateObj.getTime() !== prev_date) {
|
260
|
-
triggerChange();
|
261
|
-
}
|
262
|
-
};
|
263
|
-
|
264
|
-
pad = function pad(num) {
|
265
|
-
return ("0" + num).slice(-2);
|
266
|
-
};
|
267
|
-
|
268
|
-
formatDate = function formatDate(dateFormat) {
|
269
|
-
|
270
|
-
if (self.config.noCalendar) dateFormat = "";
|
271
|
-
|
272
|
-
if (self.config.enableTime) dateFormat += " " + self.config.timeFormat;
|
273
|
-
|
274
|
-
var formattedDate = '',
|
275
|
-
formats = {
|
276
|
-
D: function D() {
|
277
|
-
return self.l10n.weekdays.shorthand[formats.w()];
|
278
|
-
}, // weekday name, short, e.g. Thu
|
279
|
-
F: function F() {
|
280
|
-
return monthToStr(formats.n() - 1, false);
|
281
|
-
}, // full month name e.g. January
|
282
|
-
H: function H() {
|
283
|
-
return pad(self.selectedDateObj.getHours());
|
284
|
-
}, // hours with leading zero e.g. 03
|
285
|
-
J: function J() {
|
286
|
-
return formats.j() + self.l10n.ordinal(formats.j());
|
287
|
-
}, // day (1-30) with ordinal suffix e.g. 1st, 2nd
|
288
|
-
K: function K() {
|
289
|
-
return self.selectedDateObj.getHours() > 11 ? "PM" : "AM";
|
290
|
-
}, // AM/PM
|
291
|
-
M: function M() {
|
292
|
-
return monthToStr(formats.n() - 1, true);
|
293
|
-
}, // shorthand month e.g. Jan
|
294
|
-
S: function S() {
|
295
|
-
return pad(self.selectedDateObj.getSeconds());
|
296
|
-
}, // seconds 00-59
|
297
|
-
U: function U() {
|
298
|
-
return self.selectedDateObj.getTime() / 1000;
|
299
|
-
},
|
300
|
-
Y: function Y() {
|
301
|
-
return self.selectedDateObj.getFullYear();
|
302
|
-
}, // 2016
|
303
|
-
d: function d() {
|
304
|
-
return pad(formats.j());
|
305
|
-
}, // day in month, padded (01-30)
|
306
|
-
h: function h() {
|
307
|
-
return self.selectedDateObj.getHours() % 12 ? self.selectedDateObj.getHours() % 12 : 12;
|
308
|
-
}, // hour from 1-12 (am/pm)
|
309
|
-
i: function i() {
|
310
|
-
return pad(self.selectedDateObj.getMinutes());
|
311
|
-
}, // minutes, padded with leading zero e.g. 09
|
312
|
-
j: function j() {
|
313
|
-
return self.selectedDateObj.getDate();
|
314
|
-
}, // day in month (1-30)
|
315
|
-
l: function l() {
|
316
|
-
return self.l10n.weekdays.longhand[formats.w()];
|
317
|
-
}, // weekday name, full, e.g. Thursday
|
318
|
-
m: function m() {
|
319
|
-
return pad(formats.n());
|
320
|
-
}, // padded month number (01-12)
|
321
|
-
n: function n() {
|
322
|
-
return self.selectedDateObj.getMonth() + 1;
|
323
|
-
}, // the month number (1-12)
|
324
|
-
s: function s() {
|
325
|
-
return self.selectedDateObj.getSeconds();
|
326
|
-
}, // seconds 0-59
|
327
|
-
w: function w() {
|
328
|
-
return self.selectedDateObj.getDay();
|
329
|
-
}, // number of the day of the week
|
330
|
-
y: function y() {
|
331
|
-
return String(formats.Y()).substring(2);
|
332
|
-
} // last two digits of full year e.g. 16 for full year 2016
|
333
|
-
},
|
334
|
-
formatPieces = dateFormat.split('');
|
335
|
-
|
336
|
-
for (var i = 0; i < formatPieces.length; i++) {
|
337
|
-
var c = formatPieces[i];
|
338
|
-
if (formats[c] && formatPieces[i - 1] !== '\\') formattedDate += formats[c]();else if (c !== '\\') formattedDate += c;
|
339
|
-
}
|
340
|
-
|
341
|
-
return formattedDate;
|
342
|
-
};
|
343
|
-
|
344
|
-
monthToStr = function monthToStr(date, shorthand) {
|
345
|
-
return shorthand || self.config.shorthandCurrentMonth ? self.l10n.months.shorthand[date] : self.l10n.months.longhand[date];
|
346
|
-
};
|
347
|
-
|
348
|
-
isDisabled = function isDisabled(check_date) {
|
349
|
-
|
350
|
-
if (self.config.minDate && check_date < self.config.minDate || self.config.maxDate && check_date > self.config.maxDate) return true;
|
351
|
-
|
352
|
-
check_date = uDate(check_date, true); //timeless
|
353
|
-
|
354
|
-
var d = void 0;
|
355
|
-
|
356
|
-
for (var i = 0; i < self.config.disable.length; i++) {
|
357
|
-
|
358
|
-
d = self.config.disable[i];
|
359
|
-
|
360
|
-
if (d instanceof Function && d(check_date)) // disabled by function
|
361
|
-
return true;else if ( // disabled weekday
|
362
|
-
typeof d === 'string' && /^wkd/.test(d) && check_date.getDay() === (parseInt(d.slice(-1)) + self.l10n.firstDayOfWeek - 1) % 7) return true;else if ( // disabled by date string
|
363
|
-
(d instanceof Date || typeof d === 'string' && !/^wkd/.test(d)) && uDate(d, true).getTime() === check_date.getTime()) return true;else if ( // disabled by range
|
364
|
-
(typeof d === 'undefined' ? 'undefined' : _typeof(d)) === 'object' && d.hasOwnProperty("from") && check_date >= uDate(d.from) && check_date <= uDate(d.to)) return true;
|
365
|
-
}
|
366
|
-
|
367
|
-
return false;
|
368
|
-
};
|
369
|
-
|
370
|
-
yearScroll = function yearScroll(event) {
|
371
|
-
event.preventDefault();
|
372
|
-
|
373
|
-
var delta = Math.max(-1, Math.min(1, event.wheelDelta || -event.deltaY));
|
374
|
-
self.currentYear = event.target.value = parseInt(event.target.value, 10) + delta;
|
375
|
-
self.redraw();
|
376
|
-
};
|
377
|
-
|
378
|
-
timeWrapper = function timeWrapper(e) {
|
379
|
-
e.preventDefault();
|
380
|
-
|
381
|
-
var min = parseInt(e.target.min, 10),
|
382
|
-
max = parseInt(e.target.max, 10),
|
383
|
-
step = parseInt(e.target.step, 10),
|
384
|
-
delta = step * Math.max(-1, Math.min(1, e.wheelDelta || -e.deltaY)),
|
385
|
-
newValue = (parseInt(e.target.value, 10) + delta) % (max + (min === 0));
|
386
|
-
|
387
|
-
if (newValue < min) newValue = max + (min === 0) - step * (min === 0);
|
388
|
-
|
389
|
-
e.target.value = pad(newValue);
|
390
|
-
};
|
391
|
-
|
392
|
-
updateNavigationCurrentMonth = function updateNavigationCurrentMonth() {
|
393
|
-
|
394
|
-
cur_month.innerHTML = monthToStr(self.currentMonth) + " ";
|
395
|
-
cur_year.value = self.currentYear;
|
396
|
-
};
|
397
|
-
|
398
|
-
handleYearChange = function handleYearChange() {
|
399
|
-
|
400
|
-
if (self.currentMonth < 0 || self.currentMonth > 11) {
|
401
|
-
|
402
|
-
self.currentYear += self.currentMonth % 11;
|
403
|
-
self.currentMonth = (self.currentMonth + 12) % 12;
|
404
|
-
}
|
405
|
-
};
|
406
|
-
|
407
|
-
documentClick = function documentClick(event) {
|
408
|
-
if (!wrapperElement.classList.contains("open") || wrapperElement.contains(event.target) || event.target === self.element || event.target === self.altInput) return;
|
409
|
-
|
410
|
-
self.close();
|
411
|
-
};
|
412
|
-
|
413
|
-
changeMonth = function changeMonth(offset) {
|
414
|
-
self.currentMonth += offset;
|
415
|
-
|
416
|
-
handleYearChange();
|
417
|
-
updateNavigationCurrentMonth();
|
418
|
-
buildDays();
|
419
|
-
};
|
420
|
-
|
421
|
-
calendarClick = function calendarClick(e) {
|
422
|
-
|
423
|
-
e.preventDefault();
|
424
|
-
|
425
|
-
if (e.target.classList.contains('slot')) {
|
426
|
-
|
427
|
-
self.selectedDateObj = new Date(self.currentYear, self.currentMonth, e.target.innerHTML);
|
428
|
-
|
429
|
-
updateValue();
|
430
|
-
triggerChange();
|
431
|
-
buildDays();
|
432
|
-
|
433
|
-
if (!self.config.inline && !self.config.enableTime) self.close();
|
434
|
-
}
|
435
|
-
};
|
436
|
-
|
437
|
-
buildCalendar = function buildCalendar() {
|
438
|
-
|
439
|
-
calendarContainer = createElement('div', 'flatpickr-calendar');
|
440
|
-
calendarContainer.id = getRandomCalendarIdStr();
|
441
|
-
|
442
|
-
calendar = createElement("div", "flatpickr-days");
|
443
|
-
|
444
|
-
if (!self.config.noCalendar) {
|
445
|
-
buildMonthNavigation();
|
446
|
-
buildWeekdays();
|
447
|
-
|
448
|
-
if (self.config.weekNumbers) buildWeeks();
|
449
|
-
|
450
|
-
buildDays();
|
451
|
-
|
452
|
-
calendarContainer.appendChild(calendar);
|
453
|
-
}
|
454
|
-
|
455
|
-
wrapperElement.appendChild(calendarContainer);
|
456
|
-
|
457
|
-
if (self.config.enableTime) buildTime();
|
458
|
-
};
|
459
|
-
|
460
|
-
buildMonthNavigation = function buildMonthNavigation() {
|
461
|
-
|
462
|
-
monthsNav = createElement("div", "flatpickr-month");
|
463
|
-
|
464
|
-
prevMonthNav = createElement("span", "flatpickr-prev-month", self.config.prevArrow);
|
465
|
-
|
466
|
-
cur_month = createElement("span", "cur_month");
|
467
|
-
|
468
|
-
cur_year = createElement("input", "cur_year");
|
469
|
-
cur_year.type = "number";
|
470
|
-
cur_year.title = self.l10n.scrollTitle;
|
471
|
-
|
472
|
-
nextMonthNav = createElement("span", "flatpickr-next-month", self.config.nextArrow);
|
473
|
-
|
474
|
-
navigationCurrentMonth = createElement('span', 'flatpickr-current-month');
|
475
|
-
navigationCurrentMonth.appendChild(cur_month);
|
476
|
-
navigationCurrentMonth.appendChild(cur_year);
|
477
|
-
|
478
|
-
monthsNav.appendChild(prevMonthNav);
|
479
|
-
monthsNav.appendChild(navigationCurrentMonth);
|
480
|
-
monthsNav.appendChild(nextMonthNav);
|
481
|
-
|
482
|
-
updateNavigationCurrentMonth();
|
483
|
-
calendarContainer.appendChild(monthsNav);
|
484
|
-
};
|
485
|
-
|
486
|
-
buildWeekdays = function buildWeekdays() {
|
487
|
-
|
488
|
-
var weekdayContainer = createElement('div', "flatpickr-weekdays"),
|
489
|
-
firstDayOfWeek = self.l10n.firstDayOfWeek,
|
490
|
-
weekdays = self.l10n.weekdays.shorthand.slice();
|
491
|
-
|
492
|
-
if (firstDayOfWeek > 0 && firstDayOfWeek < weekdays.length) {
|
493
|
-
weekdays = [].concat(weekdays.splice(firstDayOfWeek, weekdays.length), weekdays.splice(0, firstDayOfWeek));
|
494
|
-
}
|
495
|
-
|
496
|
-
weekdayContainer.innerHTML = self.config.weekNumbers ? "<span>" + self.l10n.weekAbbreviation + "</span>" : "";
|
497
|
-
weekdayContainer.innerHTML += '<span>' + weekdays.join('</span><span>') + '</span>';
|
498
|
-
|
499
|
-
calendarContainer.appendChild(weekdayContainer);
|
500
|
-
};
|
501
|
-
|
502
|
-
buildWeeks = function buildWeeks() {
|
503
|
-
|
504
|
-
calendarContainer.classList.add("hasWeeks");
|
505
|
-
|
506
|
-
weekNumbers = createElement("div", 'flatpickr-weeks');
|
507
|
-
calendarContainer.appendChild(weekNumbers);
|
508
|
-
};
|
509
|
-
|
510
|
-
buildDays = function buildDays() {
|
511
|
-
|
512
|
-
var firstOfMonth = (new Date(self.currentYear, self.currentMonth, 1).getDay() - self.l10n.firstDayOfWeek + 7) % 7,
|
513
|
-
numDays = getDaysinMonth(),
|
514
|
-
prevMonthDays = getDaysinMonth((self.currentMonth - 1 + 12) % 12),
|
515
|
-
dayNumber = prevMonthDays + 1 - firstOfMonth,
|
516
|
-
className = void 0,
|
517
|
-
cur_date = void 0,
|
518
|
-
date_is_disabled = void 0;
|
519
|
-
|
520
|
-
if (self.config.weekNumbers && weekNumbers) weekNumbers.innerHTML = '';
|
521
|
-
|
522
|
-
calendar.innerHTML = '';
|
523
|
-
|
524
|
-
self.config.minDate = uDate(self.config.minDate, true);
|
525
|
-
self.config.maxDate = uDate(self.config.maxDate, true);
|
526
|
-
|
527
|
-
// prepend days from the ending of previous month
|
528
|
-
for (; dayNumber <= prevMonthDays; dayNumber++) {
|
529
|
-
calendar.appendChild(createElement("span", "disabled flatpickr-day", dayNumber));
|
530
|
-
} // Start at 1 since there is no 0th day
|
531
|
-
for (dayNumber = 1; dayNumber <= 42 - firstOfMonth; dayNumber++) {
|
532
|
-
|
533
|
-
if (dayNumber <= numDays || dayNumber % 7 === 1) // avoids new date objects for appended dates
|
534
|
-
cur_date = new Date(self.currentYear, self.currentMonth, dayNumber, 0, 0, 0, 0, 0);
|
535
|
-
|
536
|
-
if (self.config.weekNumbers && weekNumbers && dayNumber % 7 === 1) weekNumbers.appendChild(createElement("span", "disabled flatpickr-day", cur_date.fp_getWeek()));
|
537
|
-
|
538
|
-
date_is_disabled = dayNumber > numDays || isDisabled(cur_date);
|
539
|
-
|
540
|
-
className = date_is_disabled ? "disabled flatpickr-day" : "slot flatpickr-day";
|
541
|
-
|
542
|
-
if (!date_is_disabled && equalDates(cur_date, currentDate)) className += ' today';
|
543
|
-
|
544
|
-
if (!date_is_disabled && self.selectedDateObj && equalDates(cur_date, self.selectedDateObj)) className += ' selected';
|
545
|
-
|
546
|
-
calendar.appendChild(createElement("span", className, dayNumber > numDays ? dayNumber % numDays : dayNumber));
|
547
|
-
}
|
548
|
-
};
|
549
|
-
|
550
|
-
buildTime = function buildTime() {
|
551
|
-
|
552
|
-
var timeContainer = createElement("div", "flatpickr-time"),
|
553
|
-
separator = createElement("span", "flatpickr-time-separator", ":");
|
554
|
-
|
555
|
-
hourElement = createElement("input", "flatpickr-hour");
|
556
|
-
minuteElement = createElement("input", "flatpickr-minute");
|
557
|
-
|
558
|
-
hourElement.type = minuteElement.type = "number";
|
559
|
-
|
560
|
-
hourElement.value = self.selectedDateObj ? pad(self.selectedDateObj.getHours()) : 12;
|
561
|
-
|
562
|
-
minuteElement.value = self.selectedDateObj ? pad(self.selectedDateObj.getMinutes()) : "00";
|
563
|
-
|
564
|
-
hourElement.step = self.config.hourIncrement;
|
565
|
-
minuteElement.step = self.config.minuteIncrement;
|
566
|
-
|
567
|
-
hourElement.min = +!self.config.time_24hr; // 0 in 24hr mode, 1 in 12hr mode
|
568
|
-
hourElement.max = self.config.time_24hr ? 23 : 12;
|
569
|
-
|
570
|
-
minuteElement.min = 0;
|
571
|
-
minuteElement.max = 59;
|
572
|
-
|
573
|
-
hourElement.title = minuteElement.title = self.l10n.scrollTitle;
|
574
|
-
|
575
|
-
timeContainer.appendChild(hourElement);
|
576
|
-
timeContainer.appendChild(separator);
|
577
|
-
timeContainer.appendChild(minuteElement);
|
578
|
-
|
579
|
-
if (self.config.enableSeconds) {
|
580
|
-
|
581
|
-
timeContainer.classList.add("has-seconds");
|
582
|
-
|
583
|
-
secondElement = createElement("input", "flatpickr-second");
|
584
|
-
secondElement.type = "number";
|
585
|
-
secondElement.value = self.selectedDateObj ? pad(self.selectedDateObj.getSeconds()) : "00";
|
586
|
-
|
587
|
-
secondElement.step = 5;
|
588
|
-
secondElement.min = 0;
|
589
|
-
secondElement.max = 59;
|
590
|
-
|
591
|
-
timeContainer.appendChild(createElement("span", "flatpickr-time-separator", ":"));
|
592
|
-
timeContainer.appendChild(secondElement);
|
593
|
-
}
|
594
|
-
|
595
|
-
if (!self.config.time_24hr) {
|
596
|
-
// add am_pm if appropriate
|
597
|
-
am_pm = createElement("span", "flatpickr-am-pm", ["AM", "PM"][hourElement.value > 11 | 0]);
|
598
|
-
am_pm.title = self.l10n.toggleTitle;
|
599
|
-
timeContainer.appendChild(am_pm);
|
600
|
-
}
|
601
|
-
|
602
|
-
// picking time only
|
603
|
-
if (self.config.noCalendar && !self.selectedDateObj) self.selectedDateObj = new Date();
|
604
|
-
|
605
|
-
calendarContainer.appendChild(timeContainer);
|
606
|
-
};
|
607
|
-
|
608
|
-
bind = function bind() {
|
609
|
-
|
610
|
-
function am_pm_toggle(e) {
|
611
|
-
e.preventDefault();
|
612
|
-
am_pm.innerHTML = ["AM", "PM"][am_pm.innerHTML === "AM" | 0];
|
613
|
-
}
|
614
|
-
|
615
|
-
if (String(self.config.clickOpens) === 'true') {
|
616
|
-
self.input.addEventListener('focus', self.open);
|
617
|
-
|
618
|
-
if (self.altInput) self.altInput.addEventListener('focus', self.open);
|
619
|
-
}
|
620
|
-
|
621
|
-
if (self.config.allowInput) {
|
622
|
-
if (self.altInput) self.altInput.addEventListener('change', onInput);else self.input.addEventListener('change', onInput);
|
623
|
-
}
|
624
|
-
|
625
|
-
if (self.config.wrap && self.element.querySelector("[data-open]")) self.element.querySelector("[data-open]").addEventListener('click', self.open);
|
626
|
-
|
627
|
-
if (self.config.wrap && self.element.querySelector("[data-close]")) self.element.querySelector("[data-close]").addEventListener('click', self.close);
|
628
|
-
|
629
|
-
if (self.config.wrap && self.element.querySelector("[data-toggle]")) self.element.querySelector("[data-toggle]").addEventListener('click', self.toggle);
|
630
|
-
|
631
|
-
if (self.config.wrap && self.element.querySelector("[data-clear]")) self.element.querySelector("[data-clear]").addEventListener('click', self.clear);
|
632
|
-
|
633
|
-
if (!self.config.noCalendar) {
|
634
|
-
|
635
|
-
prevMonthNav.addEventListener('click', function () {
|
636
|
-
changeMonth(-1);
|
637
|
-
});
|
638
|
-
nextMonthNav.addEventListener('click', function () {
|
639
|
-
changeMonth(1);
|
640
|
-
});
|
641
|
-
|
642
|
-
cur_year.addEventListener('wheel', yearScroll);
|
643
|
-
cur_year.addEventListener("focus", cur_year.select);
|
644
|
-
cur_year.addEventListener("input", function (event) {
|
645
|
-
|
646
|
-
self.currentYear = parseInt(event.target.value, 10);
|
647
|
-
self.redraw();
|
648
|
-
});
|
649
|
-
|
650
|
-
calendar.addEventListener('click', calendarClick);
|
651
|
-
}
|
652
|
-
|
653
|
-
document.addEventListener('click', documentClick, true);
|
654
|
-
document.addEventListener('focus', documentClick, true);
|
655
|
-
|
656
|
-
if (self.config.enableTime) {
|
657
|
-
|
658
|
-
hourElement.addEventListener("wheel", timeWrapper);
|
659
|
-
minuteElement.addEventListener("wheel", timeWrapper);
|
660
|
-
|
661
|
-
hourElement.addEventListener("mouseout", updateValue);
|
662
|
-
minuteElement.addEventListener("mouseout", updateValue);
|
663
|
-
|
664
|
-
hourElement.addEventListener("change", updateValue);
|
665
|
-
minuteElement.addEventListener("change", updateValue);
|
666
|
-
|
667
|
-
hourElement.addEventListener("click", hourElement.select);
|
668
|
-
minuteElement.addEventListener("click", minuteElement.select);
|
669
|
-
|
670
|
-
if (self.config.enableSeconds) {
|
671
|
-
secondElement.addEventListener("wheel", timeWrapper);
|
672
|
-
secondElement.addEventListener("mouseout", updateValue);
|
673
|
-
secondElement.addEventListener("change", updateValue);
|
674
|
-
secondElement.addEventListener("click", secondElement.select);
|
675
|
-
}
|
676
|
-
|
677
|
-
if (!self.config.time_24hr) {
|
678
|
-
am_pm.addEventListener("focus", am_pm.blur);
|
679
|
-
am_pm.addEventListener("click", am_pm_toggle);
|
680
|
-
|
681
|
-
am_pm.addEventListener("wheel", am_pm_toggle);
|
682
|
-
am_pm.addEventListener("mouseout", updateValue);
|
683
|
-
}
|
684
|
-
}
|
685
|
-
|
686
|
-
if (document.createEvent) {
|
687
|
-
clickEvt = document.createEvent("MouseEvent");
|
688
|
-
// without all these args ms edge spergs out
|
689
|
-
clickEvt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
690
|
-
} else clickEvt = new MouseEvent('click', {
|
691
|
-
'view': window,
|
692
|
-
'bubbles': true,
|
693
|
-
'cancelable': true
|
694
|
-
});
|
695
|
-
|
696
|
-
window.addEventListener('resize', throttle(function () {
|
697
|
-
|
698
|
-
if (wrapperElement.classList.contains('open') && !self.input.disabled && !self.config.inline && !self.config.static) self.positionCalendar();
|
699
|
-
}, 150));
|
700
|
-
};
|
701
|
-
|
702
|
-
self.open = function () {
|
703
|
-
|
704
|
-
if (self.input.disabled || self.config.inline) return;
|
705
|
-
|
706
|
-
if (!self.config.static) self.positionCalendar();
|
707
|
-
|
708
|
-
wrapperElement.classList.add('open');
|
709
|
-
|
710
|
-
if (self.altInput) {
|
711
|
-
if (!self.config.allowInput) self.altInput.blur();
|
712
|
-
self.altInput.classList.add('active');
|
713
|
-
} else {
|
714
|
-
if (!self.config.allowInput) self.input.blur();
|
715
|
-
self.input.classList.add('active');
|
716
|
-
}
|
717
|
-
|
718
|
-
if (self.config.onOpen) self.config.onOpen(self.selectedDateObj, self.input.value);
|
719
|
-
};
|
720
|
-
|
721
|
-
// For calendars inserted in BODY (as opposed to inline wrapper)
|
722
|
-
// it's necessary to properly calculate top/left position.
|
723
|
-
self.positionCalendar = function () {
|
724
|
-
|
725
|
-
var input = self.altInput ? self.altInput : self.input,
|
726
|
-
bounds = input.getBoundingClientRect(),
|
727
|
-
|
728
|
-
// account for scroll & input height
|
729
|
-
top = window.pageYOffset + input.offsetHeight + bounds.top,
|
730
|
-
left = window.pageXOffset + bounds.left;
|
731
|
-
|
732
|
-
wrapperElement.style.top = top + 'px';
|
733
|
-
wrapperElement.style.left = left + 'px';
|
734
|
-
};
|
735
|
-
|
736
|
-
self.toggle = function () {
|
737
|
-
if (self.input.disabled) return;
|
738
|
-
|
739
|
-
wrapperElement.classList.toggle('open');
|
740
|
-
self.positionCalendar();
|
741
|
-
|
742
|
-
if (self.altInput) self.altInput.classList.toggle('active');
|
743
|
-
|
744
|
-
self.input.classList.toggle('active');
|
745
|
-
};
|
746
|
-
|
747
|
-
self.close = function () {
|
748
|
-
wrapperElement.classList.remove('open');
|
749
|
-
self.input.classList.remove('active');
|
750
|
-
|
751
|
-
if (self.altInput) self.altInput.classList.remove('active');
|
752
|
-
|
753
|
-
if (self.config.onClose) self.config.onClose(self.selectedDateObj, self.input.value);
|
754
|
-
};
|
755
|
-
|
756
|
-
self.clear = function () {
|
757
|
-
self.input.value = "";
|
758
|
-
self.selectedDateObj = null;
|
759
|
-
self.jumpToDate();
|
760
|
-
};
|
761
|
-
|
762
|
-
triggerChange = function triggerChange() {
|
763
|
-
|
764
|
-
self.input.dispatchEvent(clickEvt);
|
765
|
-
|
766
|
-
if (self.config.onChange) self.config.onChange(self.selectedDateObj, self.input.value);
|
767
|
-
};
|
768
|
-
|
769
|
-
onInput = function onInput(event) {
|
770
|
-
|
771
|
-
self.setDate(self.altInput ? self.altInput.value : self.input.value);
|
772
|
-
};
|
773
|
-
|
774
|
-
self.destroy = function () {
|
775
|
-
|
776
|
-
document.removeEventListener('click', documentClick, false);
|
777
|
-
|
778
|
-
if (self.altInput) self.altInput.parentNode.removeChild(self.altInput);
|
779
|
-
|
780
|
-
if (self.config.inline) {
|
781
|
-
|
782
|
-
var parent = self.element.parentNode,
|
783
|
-
_element = parent.removeChild(self.element);
|
784
|
-
|
785
|
-
parent.removeChild(calendarContainer);
|
786
|
-
parent.parentNode.replaceChild(_element, parent);
|
787
|
-
} else document.getElementsByTagName("body")[0].removeChild(wrapperElement);
|
788
|
-
};
|
789
|
-
|
790
|
-
self.redraw = function () {
|
791
|
-
|
792
|
-
if (self.config.noCalendar) return;
|
793
|
-
|
794
|
-
updateNavigationCurrentMonth();
|
795
|
-
buildDays();
|
796
|
-
};
|
797
|
-
|
798
|
-
self.jumpToDate = function (jumpDate) {
|
799
|
-
|
800
|
-
jumpDate = uDate(jumpDate || self.selectedDateObj || self.config.defaultDate || self.config.minDate || currentDate);
|
801
|
-
|
802
|
-
self.currentYear = jumpDate.getFullYear();
|
803
|
-
self.currentMonth = jumpDate.getMonth();
|
804
|
-
self.redraw();
|
805
|
-
};
|
806
|
-
|
807
|
-
self.setDate = function (date, triggerChangeEvent) {
|
808
|
-
|
809
|
-
date = uDate(date);
|
810
|
-
|
811
|
-
if (date instanceof Date && date.getTime()) {
|
812
|
-
|
813
|
-
self.selectedDateObj = uDate(date);
|
814
|
-
self.jumpToDate(self.selectedDateObj);
|
815
|
-
updateValue();
|
816
|
-
|
817
|
-
if (triggerChangeEvent || false) triggerChange();
|
818
|
-
}
|
819
|
-
};
|
820
|
-
|
821
|
-
self.setTime = function (hour, minute, triggerChangeEvent) {
|
822
|
-
|
823
|
-
if (!self.selectedDateObj) return;
|
824
|
-
|
825
|
-
hourElement.value = parseInt(hour, 10) % 24;
|
826
|
-
minuteElement.value = parseInt(minute || 0, 10) % 60;
|
827
|
-
|
828
|
-
if (!self.config.time_24hr) am_pm.innerHTML = hour > 11 ? "PM" : "AM";
|
829
|
-
|
830
|
-
updateValue();
|
831
|
-
|
832
|
-
if (triggerChangeEvent || false) triggerChange();
|
833
|
-
};
|
834
|
-
|
835
|
-
self.set = function (key, value) {
|
836
|
-
|
837
|
-
if (key in self.config) {
|
838
|
-
self.config[key] = value;
|
839
|
-
self.jumpToDate();
|
840
|
-
}
|
841
|
-
};
|
842
|
-
|
843
|
-
try {
|
844
|
-
init();
|
845
|
-
} catch (error) {
|
846
|
-
console.error(error);console.info(self.element);
|
847
|
-
} // skip and carry on
|
848
|
-
|
849
|
-
return self;
|
850
|
-
};
|
851
|
-
|
852
|
-
flatpickr.init.prototype = {
|
853
|
-
|
854
|
-
l10n: {
|
855
|
-
weekdays: {
|
856
|
-
shorthand: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
857
|
-
longhand: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
|
858
|
-
},
|
859
|
-
months: {
|
860
|
-
shorthand: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
861
|
-
longhand: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
|
862
|
-
},
|
863
|
-
daysInMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
|
864
|
-
firstDayOfWeek: 0,
|
865
|
-
ordinal: function ordinal(nth) {
|
866
|
-
var s = nth % 100;
|
867
|
-
if (s > 3 && s < 21) return "th";
|
868
|
-
switch (s % 10) {
|
869
|
-
case 1:
|
870
|
-
return "st";
|
871
|
-
case 2:
|
872
|
-
return "nd";
|
873
|
-
case 3:
|
874
|
-
return "rd";
|
875
|
-
default:
|
876
|
-
return "th";
|
877
|
-
}
|
878
|
-
},
|
879
|
-
weekAbbreviation: "Wk",
|
880
|
-
scrollTitle: "Scroll to increment",
|
881
|
-
toggleTitle: "Click to toggle"
|
882
|
-
},
|
883
|
-
|
884
|
-
defaultConfig: {
|
885
|
-
/* if true, dates will be parsed, formatted, and displayed in UTC.
|
886
|
-
preloading date strings w/ timezones is recommended but not necessary */
|
887
|
-
utc: false,
|
888
|
-
|
889
|
-
// noCalendar: true will hide the calendar. use for a time picker along w/ enableTime
|
890
|
-
noCalendar: false,
|
891
|
-
|
892
|
-
// wrap: see https://chmln.github.io/flatpickr/#strap
|
893
|
-
wrap: false,
|
894
|
-
|
895
|
-
// enables week numbers
|
896
|
-
weekNumbers: false,
|
897
|
-
|
898
|
-
allowInput: false,
|
899
|
-
|
900
|
-
/* clicking on input opens the date(time)picker. disable if you wish to open the calendar manually with .open() */
|
901
|
-
clickOpens: true,
|
902
|
-
|
903
|
-
// more date format chars at https://chmln.github.io/flatpickr/#dateformat
|
904
|
-
dateFormat: 'Y-m-d',
|
905
|
-
|
906
|
-
// altInput - see https://chmln.github.io/flatpickr/#altinput
|
907
|
-
altInput: false,
|
908
|
-
|
909
|
-
// the created altInput element will have this class.
|
910
|
-
altInputClass: "",
|
911
|
-
|
912
|
-
// same as dateFormat, but for altInput
|
913
|
-
altFormat: "F j, Y", // defaults to e.g. June 10, 2016
|
914
|
-
|
915
|
-
// defaultDate - either a datestring or a date object. used for datetimepicker's initial value
|
916
|
-
defaultDate: null,
|
917
|
-
|
918
|
-
// the minimum date that user can pick (inclusive)
|
919
|
-
minDate: null,
|
920
|
-
|
921
|
-
// the maximum date that user can pick (inclusive)
|
922
|
-
maxDate: null,
|
923
|
-
|
924
|
-
// dateparser that transforms a given string to a date object
|
925
|
-
parseDate: false,
|
926
|
-
|
927
|
-
// see https://chmln.github.io/flatpickr/#disable
|
928
|
-
disable: [],
|
929
|
-
|
930
|
-
// display the short version of month names - e.g. Sep instead of September
|
931
|
-
shorthandCurrentMonth: false,
|
932
|
-
|
933
|
-
// displays calendar inline. see https://chmln.github.io/flatpickr/#inline-calendar
|
934
|
-
inline: false,
|
935
|
-
|
936
|
-
// position calendar inside wrapper and next to the input element
|
937
|
-
// leave at false unless you know what you're doing
|
938
|
-
static: false,
|
939
|
-
|
940
|
-
// code for previous/next icons. this is where you put your custom icon code e.g. fontawesome
|
941
|
-
prevArrow: '<',
|
942
|
-
nextArrow: '>',
|
943
|
-
|
944
|
-
// enables the time picker functionality
|
945
|
-
enableTime: false,
|
946
|
-
|
947
|
-
// enables seconds in the time picker
|
948
|
-
enableSeconds: false,
|
949
|
-
|
950
|
-
// self-explanatory. defaults to e.g. 3:02 PM
|
951
|
-
timeFormat: "h:i K",
|
952
|
-
|
953
|
-
// display time picker in 24 hour mode
|
954
|
-
time_24hr: false,
|
955
|
-
|
956
|
-
// step size used when scrolling/incrementing the hour element
|
957
|
-
hourIncrement: 1,
|
958
|
-
|
959
|
-
// step size used when scrolling/incrementing the minute element
|
960
|
-
minuteIncrement: 5,
|
961
|
-
|
962
|
-
// onChange callback when user selects a date or time
|
963
|
-
onChange: null, //function(dateObj, dateStr){}
|
964
|
-
|
965
|
-
// called every time calendar is opened
|
966
|
-
onOpen: null, // function(dateObj, dateStr){}
|
967
|
-
|
968
|
-
// called every time calendar is closed
|
969
|
-
onClose: null // function(dateObj, dateStr){}
|
970
|
-
}
|
971
|
-
};
|
972
|
-
|
973
|
-
Date.prototype.fp_incr = function (days) {
|
974
|
-
return new Date(this.getFullYear(), this.getMonth(), this.getDate() + parseInt(days, 10));
|
975
|
-
};
|
976
|
-
|
977
|
-
Date.prototype.fp_isUTC = false;
|
978
|
-
Date.prototype.fp_toUTC = function () {
|
979
|
-
|
980
|
-
var new_date = new Date(this.getTime() + this.getTimezoneOffset() * 60000);
|
981
|
-
new_date.fp_isUTC = true;
|
982
|
-
|
983
|
-
return new_date;
|
984
|
-
};
|
985
|
-
|
986
|
-
Date.prototype.fp_getWeek = function () {
|
987
|
-
|
988
|
-
var date = new Date(this.getTime());
|
989
|
-
date.setHours(0, 0, 0, 0);
|
990
|
-
|
991
|
-
// Thursday in current week decides the year.
|
992
|
-
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
|
993
|
-
// January 4 is always in week 1.
|
994
|
-
var week1 = new Date(date.getFullYear(), 0, 4);
|
995
|
-
// Adjust to Thursday in week 1 and count number of weeks from date to week1.
|
996
|
-
return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
|
997
|
-
};
|
998
|
-
|
999
|
-
// classList polyfill
|
1000
|
-
if (!("classList" in document.documentElement) && Object.defineProperty && typeof HTMLElement !== 'undefined') {
|
1001
|
-
Object.defineProperty(HTMLElement.prototype, 'classList', {
|
1002
|
-
get: function get() {
|
1003
|
-
var self = this;
|
1004
|
-
function update(fn) {
|
1005
|
-
return function (value) {
|
1006
|
-
var classes = self.className.split(/\s+/),
|
1007
|
-
index = classes.indexOf(value);
|
1008
|
-
|
1009
|
-
fn(classes, index, value);
|
1010
|
-
self.className = classes.join(" ");
|
1011
|
-
};
|
1012
|
-
}
|
1013
|
-
|
1014
|
-
var ret = {
|
1015
|
-
add: update(function (classes, index, value) {
|
1016
|
-
return ~index || classes.push(value);
|
1017
|
-
}),
|
1018
|
-
remove: update(function (classes, index) {
|
1019
|
-
return ~index && classes.splice(index, 1);
|
1020
|
-
}),
|
1021
|
-
toggle: update(function (classes, index, value) {
|
1022
|
-
return ~index ? classes.splice(index, 1) : classes.push(value);
|
1023
|
-
}),
|
1024
|
-
contains: function contains(value) {
|
1025
|
-
return !!~self.className.split(/\s+/).indexOf(value);
|
1026
|
-
}
|
1027
|
-
};
|
1028
|
-
|
1029
|
-
return ret;
|
1030
|
-
}
|
1031
|
-
});
|
1032
|
-
}
|
1033
|
-
|
1034
|
-
if (typeof module !== 'undefined') module.exports = flatpickr;
|