@materializecss/materialize 1.2.2 → 2.0.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Gruntfile.js +68 -313
- package/README.md +2 -2
- package/dist/css/materialize.css +1009 -1822
- package/dist/css/materialize.min.css +2 -8
- package/dist/js/materialize.js +8402 -12300
- package/dist/js/materialize.min.js +3 -2
- package/dist/js/materialize.min.js.map +1 -0
- package/package.json +13 -9
- package/sass/components/_badges.scss +12 -2
- package/sass/components/_buttons.scss +16 -11
- package/sass/components/_cards.scss +14 -9
- package/sass/components/_carousel.scss +5 -2
- package/sass/components/_chips.scss +3 -3
- package/sass/components/_collapsible.scss +22 -8
- package/sass/components/_collection.scss +14 -6
- package/sass/components/_datepicker.scss +30 -11
- package/sass/components/_dropdown.scss +6 -4
- package/sass/components/_global.scss +132 -111
- package/sass/components/_grid.scss +119 -98
- package/sass/components/_modal.scss +3 -3
- package/sass/components/_navbar.scss +31 -17
- package/sass/components/_normalize.scss +26 -124
- package/sass/components/_sidenav.scss +21 -20
- package/sass/components/_slider.scss +27 -7
- package/sass/components/_table_of_contents.scss +12 -12
- package/sass/components/_tabs.scss +47 -16
- package/sass/components/_tapTarget.scss +6 -6
- package/sass/components/_timepicker.scss +54 -46
- package/sass/components/_toast.scss +3 -3
- package/sass/components/_tooltip.scss +4 -5
- package/sass/components/_typography.scss +1 -1
- package/sass/components/_variables.scss +185 -120
- package/sass/components/forms/_checkboxes.scss +9 -9
- package/sass/components/forms/_file-input.scss +9 -7
- package/sass/components/forms/_input-fields.scss +173 -234
- package/sass/components/forms/_radio-buttons.scss +1 -1
- package/sass/components/forms/_range.scss +11 -11
- package/sass/components/forms/_select.scss +29 -19
- package/sass/components/forms/_switches.scss +22 -18
- package/sass/materialize.scss +1 -1
- package/src/autocomplete.ts +459 -0
- package/src/bounding.ts +6 -0
- package/{js/buttons.js → src/buttons.ts} +103 -162
- package/src/cards.ts +54 -0
- package/{js/carousel.js → src/carousel.ts} +137 -262
- package/src/characterCounter.ts +88 -0
- package/src/chips.ts +350 -0
- package/src/collapsible.ts +184 -0
- package/{js/component.js → src/component.ts} +6 -19
- package/{js/datepicker.js → src/datepicker.ts} +213 -299
- package/{js/dropdown.js → src/dropdown.ts} +140 -254
- package/src/edges.ts +6 -0
- package/src/forms.ts +120 -0
- package/src/global.ts +385 -0
- package/src/materialbox.ts +348 -0
- package/src/modal.ts +256 -0
- package/{js/parallax.js → src/parallax.ts} +47 -60
- package/{js/pushpin.js → src/pushpin.ts} +19 -47
- package/{js/range.js → src/range.ts} +58 -139
- package/{js/scrollspy.js → src/scrollspy.ts} +81 -153
- package/src/select.ts +448 -0
- package/{js/sidenav.js → src/sidenav.ts} +96 -202
- package/src/slider.ts +415 -0
- package/src/tabs.ts +290 -0
- package/src/tapTarget.ts +240 -0
- package/{js/timepicker.js → src/timepicker.ts} +268 -272
- package/{js/toasts.js → src/toasts.ts} +75 -134
- package/{js/tooltip.js → src/tooltip.ts} +59 -96
- package/src/waves.ts +70 -0
- package/extras/noUiSlider/nouislider.css +0 -404
- package/extras/noUiSlider/nouislider.js +0 -2147
- package/extras/noUiSlider/nouislider.min.js +0 -1
- package/js/anime.min.js +0 -34
- package/js/autocomplete.js +0 -479
- package/js/cards.js +0 -40
- package/js/cash.js +0 -960
- package/js/characterCounter.js +0 -136
- package/js/chips.js +0 -486
- package/js/collapsible.js +0 -275
- package/js/forms.js +0 -285
- package/js/global.js +0 -428
- package/js/materialbox.js +0 -453
- package/js/modal.js +0 -382
- package/js/select.js +0 -391
- package/js/slider.js +0 -497
- package/js/tabs.js +0 -402
- package/js/tapTarget.js +0 -315
- package/js/waves.js +0 -615
- package/sass/components/_waves.scss +0 -187
|
@@ -1,131 +1,127 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
* @param {Object} options
|
|
118
|
-
*/
|
|
1
|
+
import { Component } from "./component";
|
|
2
|
+
import { M } from "./global";
|
|
3
|
+
import { Modal } from "./modal";
|
|
4
|
+
import { FormSelect } from "./select";
|
|
5
|
+
|
|
6
|
+
let _defaults = {
|
|
7
|
+
// Close when date is selected
|
|
8
|
+
autoClose: false,
|
|
9
|
+
// the default output format for the input field value
|
|
10
|
+
format: 'mmm dd, yyyy',
|
|
11
|
+
// Used to create date object from current input string
|
|
12
|
+
parse: null,
|
|
13
|
+
// The initial date to view when first opened
|
|
14
|
+
defaultDate: null,
|
|
15
|
+
// Make the `defaultDate` the initial selected value
|
|
16
|
+
setDefaultDate: false,
|
|
17
|
+
disableWeekends: false,
|
|
18
|
+
disableDayFn: null,
|
|
19
|
+
// First day of week (0: Sunday, 1: Monday etc)
|
|
20
|
+
firstDay: 0,
|
|
21
|
+
// The earliest date that can be selected
|
|
22
|
+
minDate: null,
|
|
23
|
+
// Thelatest date that can be selected
|
|
24
|
+
maxDate: null,
|
|
25
|
+
// Number of years either side, or array of upper/lower range
|
|
26
|
+
yearRange: 10,
|
|
27
|
+
// used internally (don't config outside)
|
|
28
|
+
minYear: 0,
|
|
29
|
+
maxYear: 9999,
|
|
30
|
+
minMonth: undefined,
|
|
31
|
+
maxMonth: undefined,
|
|
32
|
+
startRange: null,
|
|
33
|
+
endRange: null,
|
|
34
|
+
isRTL: false,
|
|
35
|
+
// Render the month after year in the calendar title
|
|
36
|
+
showMonthAfterYear: false,
|
|
37
|
+
// Render days of the calendar grid that fall in the next or previous month
|
|
38
|
+
showDaysInNextAndPreviousMonths: false,
|
|
39
|
+
// Specify a DOM element to render the calendar in
|
|
40
|
+
container: null,
|
|
41
|
+
// Show clear button
|
|
42
|
+
showClearBtn: false,
|
|
43
|
+
// internationalization
|
|
44
|
+
i18n: {
|
|
45
|
+
cancel: 'Cancel',
|
|
46
|
+
clear: 'Clear',
|
|
47
|
+
done: 'Ok',
|
|
48
|
+
previousMonth: '‹',
|
|
49
|
+
nextMonth: '›',
|
|
50
|
+
months: [
|
|
51
|
+
'January',
|
|
52
|
+
'February',
|
|
53
|
+
'March',
|
|
54
|
+
'April',
|
|
55
|
+
'May',
|
|
56
|
+
'June',
|
|
57
|
+
'July',
|
|
58
|
+
'August',
|
|
59
|
+
'September',
|
|
60
|
+
'October',
|
|
61
|
+
'November',
|
|
62
|
+
'December'
|
|
63
|
+
],
|
|
64
|
+
monthsShort: [
|
|
65
|
+
'Jan',
|
|
66
|
+
'Feb',
|
|
67
|
+
'Mar',
|
|
68
|
+
'Apr',
|
|
69
|
+
'May',
|
|
70
|
+
'Jun',
|
|
71
|
+
'Jul',
|
|
72
|
+
'Aug',
|
|
73
|
+
'Sep',
|
|
74
|
+
'Oct',
|
|
75
|
+
'Nov',
|
|
76
|
+
'Dec'
|
|
77
|
+
],
|
|
78
|
+
weekdays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
|
79
|
+
weekdaysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
|
80
|
+
weekdaysAbbrev: ['S', 'M', 'T', 'W', 'T', 'F', 'S']
|
|
81
|
+
},
|
|
82
|
+
// events array
|
|
83
|
+
events: [],
|
|
84
|
+
// callback function
|
|
85
|
+
onSelect: null,
|
|
86
|
+
onOpen: null,
|
|
87
|
+
onClose: null,
|
|
88
|
+
onDraw: null
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export class Datepicker extends Component {
|
|
92
|
+
el: HTMLInputElement
|
|
93
|
+
id: string;
|
|
94
|
+
isOpen: boolean;
|
|
95
|
+
modal: Modal;
|
|
96
|
+
calendarEl: HTMLElement;
|
|
97
|
+
clearBtn: HTMLElement;
|
|
98
|
+
doneBtn: HTMLElement;
|
|
99
|
+
cancelBtn: HTMLElement;
|
|
100
|
+
modalEl: HTMLElement;
|
|
101
|
+
yearTextEl: HTMLElement;
|
|
102
|
+
dateTextEl: HTMLElement;
|
|
103
|
+
date: any;
|
|
104
|
+
formats: any;
|
|
105
|
+
calendars: any;
|
|
106
|
+
private _y: any;
|
|
107
|
+
private _m: any;
|
|
108
|
+
private _handleInputKeydownBound: any;
|
|
109
|
+
private _handleInputClickBound: any;
|
|
110
|
+
private _handleInputChangeBound: any;
|
|
111
|
+
private _handleCalendarClickBound: any;
|
|
112
|
+
private _finishSelectionBound: any;
|
|
113
|
+
private _closeBound: any;
|
|
114
|
+
private _handleClearClickBound: any;
|
|
115
|
+
static _template: string;
|
|
116
|
+
|
|
119
117
|
constructor(el, options) {
|
|
120
118
|
super(Datepicker, el, options);
|
|
121
|
-
|
|
122
|
-
this.
|
|
123
|
-
|
|
124
|
-
this.options = $.extend({}, Datepicker.defaults, options);
|
|
119
|
+
(this.el as any).M_Datepicker = this;
|
|
120
|
+
this.options = {...Datepicker.defaults, ...options};
|
|
125
121
|
|
|
126
122
|
// make sure i18n defaults are not lost when only few i18n option properties are passed
|
|
127
123
|
if (!!options && options.hasOwnProperty('i18n') && typeof options.i18n === 'object') {
|
|
128
|
-
this.options.i18n =
|
|
124
|
+
this.options.i18n = {...Datepicker.defaults.i18n, ...options.i18n};
|
|
129
125
|
}
|
|
130
126
|
|
|
131
127
|
// Remove time component from minDate and maxDate options
|
|
@@ -137,7 +133,6 @@
|
|
|
137
133
|
this._setupVariables();
|
|
138
134
|
this._insertHTMLIntoDOM();
|
|
139
135
|
this._setupModal();
|
|
140
|
-
|
|
141
136
|
this._setupEventHandlers();
|
|
142
137
|
|
|
143
138
|
if (!this.options.defaultDate) {
|
|
@@ -149,17 +144,14 @@
|
|
|
149
144
|
if (this.options.setDefaultDate) {
|
|
150
145
|
this.setDate(defDate, true);
|
|
151
146
|
this.setInputValue();
|
|
152
|
-
}
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
153
149
|
this.gotoDate(defDate);
|
|
154
150
|
}
|
|
155
|
-
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
156
153
|
this.gotoDate(new Date());
|
|
157
154
|
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Describes open/close state of datepicker
|
|
161
|
-
* @type {Boolean}
|
|
162
|
-
*/
|
|
163
155
|
this.isOpen = false;
|
|
164
156
|
}
|
|
165
157
|
|
|
@@ -198,94 +190,74 @@
|
|
|
198
190
|
static _compareDates(a, b) {
|
|
199
191
|
// weak date comparison (use setToStartOfDay(date) to ensure correct result)
|
|
200
192
|
return a.getTime() === b.getTime();
|
|
201
|
-
}
|
|
193
|
+
}
|
|
202
194
|
|
|
203
|
-
static _setToStartOfDay(date) {
|
|
204
|
-
if (Datepicker._isDate(date)) date.setHours(0, 0, 0, 0);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Get Instance
|
|
209
|
-
*/
|
|
210
195
|
static getInstance(el) {
|
|
211
196
|
let domElem = !!el.jquery ? el[0] : el;
|
|
212
197
|
return domElem.M_Datepicker;
|
|
213
198
|
}
|
|
214
199
|
|
|
215
|
-
/**
|
|
216
|
-
* Teardown component
|
|
217
|
-
*/
|
|
218
200
|
destroy() {
|
|
219
201
|
this._removeEventHandlers();
|
|
220
202
|
this.modal.destroy();
|
|
221
|
-
|
|
203
|
+
this.modalEl.remove();
|
|
222
204
|
this.destroySelects();
|
|
223
|
-
this.el.M_Datepicker = undefined;
|
|
205
|
+
(this.el as any).M_Datepicker = undefined;
|
|
224
206
|
}
|
|
225
207
|
|
|
226
208
|
destroySelects() {
|
|
227
209
|
let oldYearSelect = this.calendarEl.querySelector('.orig-select-year');
|
|
228
210
|
if (oldYearSelect) {
|
|
229
|
-
|
|
211
|
+
FormSelect.getInstance(oldYearSelect).destroy();
|
|
230
212
|
}
|
|
231
213
|
let oldMonthSelect = this.calendarEl.querySelector('.orig-select-month');
|
|
232
214
|
if (oldMonthSelect) {
|
|
233
|
-
|
|
215
|
+
FormSelect.getInstance(oldMonthSelect).destroy();
|
|
234
216
|
}
|
|
235
217
|
}
|
|
236
218
|
|
|
237
219
|
_insertHTMLIntoDOM() {
|
|
238
220
|
if (this.options.showClearBtn) {
|
|
239
|
-
|
|
240
|
-
this.clearBtn.
|
|
221
|
+
this.clearBtn.style.visibility = '';
|
|
222
|
+
this.clearBtn.innerText = this.options.i18n.clear;
|
|
241
223
|
}
|
|
242
|
-
|
|
243
|
-
this.
|
|
244
|
-
this.cancelBtn.innerHTML = this.options.i18n.cancel;
|
|
224
|
+
this.doneBtn.innerText = this.options.i18n.done;
|
|
225
|
+
this.cancelBtn.innerText = this.options.i18n.cancel;
|
|
245
226
|
|
|
246
227
|
if (this.options.container) {
|
|
247
228
|
const optEl = this.options.container;
|
|
248
229
|
this.options.container =
|
|
249
230
|
optEl instanceof HTMLElement ? optEl : document.querySelector(optEl);
|
|
250
|
-
this
|
|
251
|
-
}
|
|
252
|
-
|
|
231
|
+
this.options.container.append(this.modalEl);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
//this.modalEl.before(this.el);
|
|
235
|
+
this.el.parentElement.appendChild(this.modalEl);
|
|
253
236
|
}
|
|
254
237
|
}
|
|
255
238
|
|
|
256
239
|
_setupModal() {
|
|
257
240
|
this.modalEl.id = 'modal-' + this.id;
|
|
258
|
-
this.modal =
|
|
241
|
+
this.modal = Modal.init(this.modalEl, {
|
|
259
242
|
onCloseEnd: () => {
|
|
260
243
|
this.isOpen = false;
|
|
261
244
|
}
|
|
262
245
|
});
|
|
263
246
|
}
|
|
264
247
|
|
|
265
|
-
toString(format) {
|
|
248
|
+
toString(format: string | ((d: Date) => string) = null): string {
|
|
266
249
|
format = format || this.options.format;
|
|
267
|
-
if (typeof format === 'function')
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
let formatArray = format.split(/(d{1,4}|m{1,4}|y{4}|yy|!.)/g);
|
|
276
|
-
let formattedDate = formatArray
|
|
277
|
-
.map((label) => {
|
|
278
|
-
if (this.formats[label]) {
|
|
279
|
-
return this.formats[label]();
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return label;
|
|
283
|
-
})
|
|
250
|
+
if (typeof format === 'function') return format(this.date);
|
|
251
|
+
if (!Datepicker._isDate(this.date)) return '';
|
|
252
|
+
// String Format
|
|
253
|
+
const formatArray = format.split(/(d{1,4}|m{1,4}|y{4}|yy|!.)/g);
|
|
254
|
+
const formattedDate = formatArray
|
|
255
|
+
.map(label => this.formats[label] ? this.formats[label]() : label)
|
|
284
256
|
.join('');
|
|
285
257
|
return formattedDate;
|
|
286
258
|
}
|
|
287
259
|
|
|
288
|
-
setDate(date, preventOnSelect) {
|
|
260
|
+
setDate(date, preventOnSelect: boolean = false) {
|
|
289
261
|
if (!date) {
|
|
290
262
|
this.date = null;
|
|
291
263
|
this._renderDateDisplay();
|
|
@@ -297,23 +269,18 @@
|
|
|
297
269
|
if (!Datepicker._isDate(date)) {
|
|
298
270
|
return;
|
|
299
271
|
}
|
|
300
|
-
|
|
301
272
|
let min = this.options.minDate,
|
|
302
273
|
max = this.options.maxDate;
|
|
303
|
-
|
|
304
274
|
if (Datepicker._isDate(min) && date < min) {
|
|
305
275
|
date = min;
|
|
306
|
-
}
|
|
276
|
+
}
|
|
277
|
+
else if (Datepicker._isDate(max) && date > max) {
|
|
307
278
|
date = max;
|
|
308
279
|
}
|
|
309
|
-
|
|
310
280
|
this.date = new Date(date.getTime());
|
|
311
|
-
|
|
312
281
|
this._renderDateDisplay();
|
|
313
|
-
|
|
314
282
|
Datepicker._setToStartOfDay(this.date);
|
|
315
283
|
this.gotoDate(this.date);
|
|
316
|
-
|
|
317
284
|
if (!preventOnSelect && typeof this.options.onSelect === 'function') {
|
|
318
285
|
this.options.onSelect.call(this, this.date);
|
|
319
286
|
}
|
|
@@ -321,7 +288,7 @@
|
|
|
321
288
|
|
|
322
289
|
setInputValue() {
|
|
323
290
|
this.el.value = this.toString();
|
|
324
|
-
this
|
|
291
|
+
this.el.dispatchEvent(new CustomEvent('change', {detail: {firedBy: this}}));
|
|
325
292
|
}
|
|
326
293
|
|
|
327
294
|
_renderDateDisplay() {
|
|
@@ -334,16 +301,11 @@
|
|
|
334
301
|
this.dateTextEl.innerHTML = `${day}, ${month} ${date}`;
|
|
335
302
|
}
|
|
336
303
|
|
|
337
|
-
/**
|
|
338
|
-
* change view to a specific date
|
|
339
|
-
*/
|
|
340
304
|
gotoDate(date) {
|
|
341
305
|
let newCalendar = true;
|
|
342
|
-
|
|
343
306
|
if (!Datepicker._isDate(date)) {
|
|
344
307
|
return;
|
|
345
308
|
}
|
|
346
|
-
|
|
347
309
|
if (this.calendars) {
|
|
348
310
|
let firstVisibleDate = new Date(this.calendars[0].year, this.calendars[0].month, 1),
|
|
349
311
|
lastVisibleDate = new Date(
|
|
@@ -358,7 +320,6 @@
|
|
|
358
320
|
newCalendar =
|
|
359
321
|
visibleDate < firstVisibleDate.getTime() || lastVisibleDate.getTime() < visibleDate;
|
|
360
322
|
}
|
|
361
|
-
|
|
362
323
|
if (newCalendar) {
|
|
363
324
|
this.calendars = [
|
|
364
325
|
{
|
|
@@ -367,7 +328,6 @@
|
|
|
367
328
|
}
|
|
368
329
|
];
|
|
369
330
|
}
|
|
370
|
-
|
|
371
331
|
this.adjustCalendars();
|
|
372
332
|
}
|
|
373
333
|
|
|
@@ -596,15 +556,13 @@
|
|
|
596
556
|
);
|
|
597
557
|
}
|
|
598
558
|
|
|
599
|
-
monthHtml =
|
|
600
|
-
'<select class="datepicker-select orig-select-month" tabindex="-1">' +
|
|
601
|
-
arr.join('') +
|
|
602
|
-
'</select>';
|
|
559
|
+
monthHtml = '<select class="datepicker-select orig-select-month" tabindex="-1">'+arr.join('')+'</select>';
|
|
603
560
|
|
|
604
|
-
if (
|
|
561
|
+
if (Array.isArray(opts.yearRange)) {
|
|
605
562
|
i = opts.yearRange[0];
|
|
606
563
|
j = opts.yearRange[1] + 1;
|
|
607
|
-
}
|
|
564
|
+
}
|
|
565
|
+
else {
|
|
608
566
|
i = year - opts.yearRange;
|
|
609
567
|
j = 1 + year + opts.yearRange;
|
|
610
568
|
}
|
|
@@ -614,19 +572,15 @@
|
|
|
614
572
|
arr.push(`<option value="${i}" ${i === year ? 'selected="selected"' : ''}>${i}</option>`);
|
|
615
573
|
}
|
|
616
574
|
}
|
|
617
|
-
if (opts.yearRangeReverse)
|
|
618
|
-
arr.reverse();
|
|
619
|
-
}
|
|
575
|
+
if (opts.yearRangeReverse) arr.reverse();
|
|
620
576
|
|
|
621
|
-
yearHtml = `<select class="datepicker-select orig-select-year" tabindex="-1">${arr.join(
|
|
622
|
-
''
|
|
623
|
-
)}</select>`;
|
|
577
|
+
yearHtml = `<select class="datepicker-select orig-select-year" tabindex="-1">${arr.join('')}</select>`;
|
|
624
578
|
|
|
625
579
|
let leftArrow =
|
|
626
|
-
'<svg
|
|
580
|
+
'<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M15.41 16.09l-4.58-4.59 4.58-4.59L14 5.5l-6 6 6 6z"/><path d="M0-.5h24v24H0z" fill="none"/></svg>';
|
|
627
581
|
html += `<button class="month-prev${
|
|
628
582
|
prev ? '' : ' is-disabled'
|
|
629
|
-
}" type="button">${leftArrow}</button>`;
|
|
583
|
+
} btn-flat" type="button">${leftArrow}</button>`;
|
|
630
584
|
|
|
631
585
|
html += '<div class="selects-container">';
|
|
632
586
|
if (opts.showMonthAfterYear) {
|
|
@@ -645,21 +599,17 @@
|
|
|
645
599
|
}
|
|
646
600
|
|
|
647
601
|
let rightArrow =
|
|
648
|
-
'<svg
|
|
602
|
+
'<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"/><path d="M0-.25h24v24H0z" fill="none"/></svg>';
|
|
649
603
|
html += `<button class="month-next${
|
|
650
604
|
next ? '' : ' is-disabled'
|
|
651
|
-
}" type="button">${rightArrow}</button>`;
|
|
605
|
+
} btn-flat" type="button">${rightArrow}</button>`;
|
|
652
606
|
|
|
653
607
|
return (html += '</div>');
|
|
654
608
|
}
|
|
655
609
|
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
draw(force) {
|
|
660
|
-
if (!this.isOpen && !force) {
|
|
661
|
-
return;
|
|
662
|
-
}
|
|
610
|
+
// refresh HTML
|
|
611
|
+
draw(force: boolean = false) {
|
|
612
|
+
if (!this.isOpen && !force) return;
|
|
663
613
|
let opts = this.options,
|
|
664
614
|
minYear = opts.minYear,
|
|
665
615
|
maxYear = opts.maxYear,
|
|
@@ -708,11 +658,11 @@
|
|
|
708
658
|
// Init Materialize Select
|
|
709
659
|
let yearSelect = this.calendarEl.querySelector('.orig-select-year');
|
|
710
660
|
let monthSelect = this.calendarEl.querySelector('.orig-select-month');
|
|
711
|
-
|
|
661
|
+
FormSelect.init(yearSelect, {
|
|
712
662
|
classes: 'select-year',
|
|
713
663
|
dropdownOptions: { container: document.body, constrainWidth: false }
|
|
714
664
|
});
|
|
715
|
-
|
|
665
|
+
FormSelect.init(monthSelect, {
|
|
716
666
|
classes: 'select-month',
|
|
717
667
|
dropdownOptions: { container: document.body, constrainWidth: false }
|
|
718
668
|
});
|
|
@@ -726,9 +676,6 @@
|
|
|
726
676
|
}
|
|
727
677
|
}
|
|
728
678
|
|
|
729
|
-
/**
|
|
730
|
-
* Setup Event Handlers
|
|
731
|
-
*/
|
|
732
679
|
_setupEventHandlers() {
|
|
733
680
|
this._handleInputKeydownBound = this._handleInputKeydown.bind(this);
|
|
734
681
|
this._handleInputClickBound = this._handleInputClick.bind(this);
|
|
@@ -752,11 +699,11 @@
|
|
|
752
699
|
}
|
|
753
700
|
|
|
754
701
|
_setupVariables() {
|
|
755
|
-
|
|
756
|
-
|
|
702
|
+
const template = document.createElement('template');
|
|
703
|
+
template.innerHTML = Datepicker._template.trim();
|
|
704
|
+
this.modalEl = <HTMLElement>template.content.firstChild;
|
|
757
705
|
|
|
758
706
|
this.calendarEl = this.modalEl.querySelector('.datepicker-calendar');
|
|
759
|
-
|
|
760
707
|
this.yearTextEl = this.modalEl.querySelector('.year-text');
|
|
761
708
|
this.dateTextEl = this.modalEl.querySelector('.date-text');
|
|
762
709
|
if (this.options.showClearBtn) {
|
|
@@ -801,9 +748,6 @@
|
|
|
801
748
|
};
|
|
802
749
|
}
|
|
803
750
|
|
|
804
|
-
/**
|
|
805
|
-
* Remove Event Handlers
|
|
806
|
-
*/
|
|
807
751
|
_removeEventHandlers() {
|
|
808
752
|
this.el.removeEventListener('click', this._handleInputClickBound);
|
|
809
753
|
this.el.removeEventListener('keydown', this._handleInputKeydownBound);
|
|
@@ -823,17 +767,14 @@
|
|
|
823
767
|
}
|
|
824
768
|
|
|
825
769
|
_handleCalendarClick(e) {
|
|
826
|
-
if (!this.isOpen)
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
let $target = $(e.target);
|
|
831
|
-
if (!$target.hasClass('is-disabled')) {
|
|
770
|
+
if (!this.isOpen) return;
|
|
771
|
+
const target = <HTMLElement>(e.target);
|
|
772
|
+
if (!target.classList.contains('is-disabled')) {
|
|
832
773
|
if (
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
) {
|
|
774
|
+
target.classList.contains('datepicker-day-button') &&
|
|
775
|
+
!target.classList.contains('is-empty') &&
|
|
776
|
+
!target.parentElement.classList.contains('is-disabled')
|
|
777
|
+
) {
|
|
837
778
|
this.setDate(
|
|
838
779
|
new Date(
|
|
839
780
|
e.target.getAttribute('data-year'),
|
|
@@ -844,9 +785,11 @@
|
|
|
844
785
|
if (this.options.autoClose) {
|
|
845
786
|
this._finishSelection();
|
|
846
787
|
}
|
|
847
|
-
}
|
|
788
|
+
}
|
|
789
|
+
else if (target.closest('.month-prev')) {
|
|
848
790
|
this.prevMonth();
|
|
849
|
-
}
|
|
791
|
+
}
|
|
792
|
+
else if (target.closest('.month-next')) {
|
|
850
793
|
this.nextMonth();
|
|
851
794
|
}
|
|
852
795
|
}
|
|
@@ -866,9 +809,7 @@
|
|
|
866
809
|
this.gotoYear(e.target.value);
|
|
867
810
|
}
|
|
868
811
|
|
|
869
|
-
|
|
870
|
-
* change view to a specific month (zero-index, e.g. 0: January)
|
|
871
|
-
*/
|
|
812
|
+
// change view to a specific month (zero-index, e.g. 0: January)
|
|
872
813
|
gotoMonth(month) {
|
|
873
814
|
if (!isNaN(month)) {
|
|
874
815
|
this.calendars[0].month = parseInt(month, 10);
|
|
@@ -876,9 +817,7 @@
|
|
|
876
817
|
}
|
|
877
818
|
}
|
|
878
819
|
|
|
879
|
-
|
|
880
|
-
* change view to a specific full year (e.g. "2012")
|
|
881
|
-
*/
|
|
820
|
+
// change view to a specific full year (e.g. "2012")
|
|
882
821
|
gotoYear(year) {
|
|
883
822
|
if (!isNaN(year)) {
|
|
884
823
|
this.calendars[0].year = parseInt(year, 10);
|
|
@@ -886,25 +825,20 @@
|
|
|
886
825
|
}
|
|
887
826
|
}
|
|
888
827
|
|
|
889
|
-
_handleInputChange(e) {
|
|
828
|
+
_handleInputChange(e: Event) {
|
|
890
829
|
let date;
|
|
891
|
-
|
|
892
830
|
// Prevent change event from being fired when triggered by the plugin
|
|
893
|
-
if (e
|
|
894
|
-
return;
|
|
895
|
-
}
|
|
831
|
+
if (e['detail']?.firedBy === this) return;
|
|
896
832
|
if (this.options.parse) {
|
|
897
833
|
date = this.options.parse(this.el.value, this.options.format);
|
|
898
|
-
} else {
|
|
899
|
-
date = new Date(Date.parse(this.el.value));
|
|
900
834
|
}
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
this.setDate(date);
|
|
835
|
+
else {
|
|
836
|
+
date = new Date(Date.parse(this.el.value));
|
|
904
837
|
}
|
|
838
|
+
if (Datepicker._isDate(date)) this.setDate(date);
|
|
905
839
|
}
|
|
906
840
|
|
|
907
|
-
renderDayName(opts, day, abbr) {
|
|
841
|
+
renderDayName(opts, day, abbr: boolean = false) {
|
|
908
842
|
day += opts.firstDay;
|
|
909
843
|
while (day >= 7) {
|
|
910
844
|
day -= 7;
|
|
@@ -912,39 +846,25 @@
|
|
|
912
846
|
return abbr ? opts.i18n.weekdaysAbbrev[day] : opts.i18n.weekdays[day];
|
|
913
847
|
}
|
|
914
848
|
|
|
915
|
-
|
|
916
|
-
* Set input value to the selected date and close Datepicker
|
|
917
|
-
*/
|
|
849
|
+
// Set input value to the selected date and close Datepicker
|
|
918
850
|
_finishSelection() {
|
|
919
851
|
this.setInputValue();
|
|
920
852
|
this.close();
|
|
921
853
|
}
|
|
922
854
|
|
|
923
|
-
/**
|
|
924
|
-
* Open Datepicker
|
|
925
|
-
*/
|
|
926
855
|
open() {
|
|
927
|
-
if (this.isOpen)
|
|
928
|
-
return;
|
|
929
|
-
}
|
|
930
|
-
|
|
856
|
+
if (this.isOpen) return;
|
|
931
857
|
this.isOpen = true;
|
|
932
858
|
if (typeof this.options.onOpen === 'function') {
|
|
933
859
|
this.options.onOpen.call(this);
|
|
934
860
|
}
|
|
935
861
|
this.draw();
|
|
936
|
-
this.modal.open();
|
|
862
|
+
this.modal.open(undefined);
|
|
937
863
|
return this;
|
|
938
864
|
}
|
|
939
865
|
|
|
940
|
-
/**
|
|
941
|
-
* Close Datepicker
|
|
942
|
-
*/
|
|
943
866
|
close() {
|
|
944
|
-
if (!this.isOpen)
|
|
945
|
-
return;
|
|
946
|
-
}
|
|
947
|
-
|
|
867
|
+
if (!this.isOpen) return;
|
|
948
868
|
this.isOpen = false;
|
|
949
869
|
if (typeof this.options.onClose === 'function') {
|
|
950
870
|
this.options.onClose.call(this);
|
|
@@ -952,32 +872,26 @@
|
|
|
952
872
|
this.modal.close();
|
|
953
873
|
return this;
|
|
954
874
|
}
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
M.Datepicker = Datepicker;
|
|
979
|
-
|
|
980
|
-
if (M.jQueryLoaded) {
|
|
981
|
-
M.initializeJqueryWrapper(Datepicker, 'datepicker', 'M_Datepicker');
|
|
982
|
-
}
|
|
983
|
-
})(cash);
|
|
875
|
+
|
|
876
|
+
static {
|
|
877
|
+
Datepicker._template = `
|
|
878
|
+
<div class="modal datepicker-modal">
|
|
879
|
+
<div class="modal-content datepicker-container">
|
|
880
|
+
<div class="datepicker-date-display">
|
|
881
|
+
<span class="year-text"></span>
|
|
882
|
+
<span class="date-text"></span>
|
|
883
|
+
</div>
|
|
884
|
+
<div class="datepicker-calendar-container">
|
|
885
|
+
<div class="datepicker-calendar"></div>
|
|
886
|
+
<div class="datepicker-footer">
|
|
887
|
+
<button class="btn-flat datepicker-clear waves-effect" style="visibility: hidden;" type="button"></button>
|
|
888
|
+
<div class="confirmation-btns">
|
|
889
|
+
<button class="btn-flat datepicker-cancel waves-effect" type="button"></button>
|
|
890
|
+
<button class="btn-flat datepicker-done waves-effect" type="button"></button>
|
|
891
|
+
</div>
|
|
892
|
+
</div>
|
|
893
|
+
</div>
|
|
894
|
+
</div>
|
|
895
|
+
</div>`;
|
|
896
|
+
}
|
|
897
|
+
}
|