@materializecss/materialize 1.2.2 → 2.0.1-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.
Files changed (90) hide show
  1. package/Gruntfile.js +68 -313
  2. package/README.md +26 -14
  3. package/dist/css/materialize.css +1009 -1822
  4. package/dist/css/materialize.min.css +2 -8
  5. package/dist/js/materialize.js +8414 -12299
  6. package/dist/js/materialize.min.js +8968 -2
  7. package/dist/js/materialize.min.js.map +1 -0
  8. package/package.json +13 -9
  9. package/sass/components/_badges.scss +12 -2
  10. package/sass/components/_buttons.scss +16 -11
  11. package/sass/components/_cards.scss +14 -9
  12. package/sass/components/_carousel.scss +5 -2
  13. package/sass/components/_chips.scss +3 -3
  14. package/sass/components/_collapsible.scss +22 -8
  15. package/sass/components/_collection.scss +14 -6
  16. package/sass/components/_datepicker.scss +30 -11
  17. package/sass/components/_dropdown.scss +6 -4
  18. package/sass/components/_global.scss +132 -111
  19. package/sass/components/_grid.scss +119 -98
  20. package/sass/components/_modal.scss +3 -3
  21. package/sass/components/_navbar.scss +31 -17
  22. package/sass/components/_normalize.scss +26 -124
  23. package/sass/components/_sidenav.scss +21 -20
  24. package/sass/components/_slider.scss +27 -7
  25. package/sass/components/_table_of_contents.scss +12 -12
  26. package/sass/components/_tabs.scss +47 -16
  27. package/sass/components/_tapTarget.scss +6 -6
  28. package/sass/components/_theme_variables.scss +98 -0
  29. package/sass/components/_timepicker.scss +54 -46
  30. package/sass/components/_toast.scss +3 -3
  31. package/sass/components/_tooltip.scss +4 -5
  32. package/sass/components/_typography.scss +1 -1
  33. package/sass/components/_variables.scss +185 -120
  34. package/sass/components/forms/_checkboxes.scss +9 -9
  35. package/sass/components/forms/_file-input.scss +9 -7
  36. package/sass/components/forms/_input-fields.scss +173 -234
  37. package/sass/components/forms/_radio-buttons.scss +1 -1
  38. package/sass/components/forms/_range.scss +11 -11
  39. package/sass/components/forms/_select.scss +29 -19
  40. package/sass/components/forms/_switches.scss +22 -18
  41. package/sass/materialize.scss +1 -1
  42. package/src/autocomplete.ts +459 -0
  43. package/src/bounding.ts +6 -0
  44. package/{js/buttons.js → src/buttons.ts} +103 -162
  45. package/src/cards.ts +54 -0
  46. package/{js/carousel.js → src/carousel.ts} +137 -262
  47. package/src/characterCounter.ts +88 -0
  48. package/src/chips.ts +350 -0
  49. package/src/collapsible.ts +184 -0
  50. package/{js/component.js → src/component.ts} +6 -19
  51. package/{js/datepicker.js → src/datepicker.ts} +213 -299
  52. package/{js/dropdown.js → src/dropdown.ts} +140 -254
  53. package/src/edges.ts +6 -0
  54. package/src/forms.ts +120 -0
  55. package/src/global.ts +385 -0
  56. package/src/materialbox.ts +348 -0
  57. package/src/modal.ts +256 -0
  58. package/{js/parallax.js → src/parallax.ts} +47 -60
  59. package/{js/pushpin.js → src/pushpin.ts} +19 -47
  60. package/{js/range.js → src/range.ts} +58 -139
  61. package/{js/scrollspy.js → src/scrollspy.ts} +81 -153
  62. package/src/select.ts +448 -0
  63. package/{js/sidenav.js → src/sidenav.ts} +96 -202
  64. package/src/slider.ts +415 -0
  65. package/src/tabs.ts +293 -0
  66. package/src/tapTarget.ts +240 -0
  67. package/{js/timepicker.js → src/timepicker.ts} +268 -272
  68. package/{js/toasts.js → src/toasts.ts} +75 -134
  69. package/{js/tooltip.js → src/tooltip.ts} +59 -96
  70. package/src/waves.ts +70 -0
  71. package/extras/noUiSlider/nouislider.css +0 -404
  72. package/extras/noUiSlider/nouislider.js +0 -2147
  73. package/extras/noUiSlider/nouislider.min.js +0 -1
  74. package/js/anime.min.js +0 -34
  75. package/js/autocomplete.js +0 -479
  76. package/js/cards.js +0 -40
  77. package/js/cash.js +0 -960
  78. package/js/characterCounter.js +0 -136
  79. package/js/chips.js +0 -486
  80. package/js/collapsible.js +0 -275
  81. package/js/forms.js +0 -285
  82. package/js/global.js +0 -428
  83. package/js/materialbox.js +0 -453
  84. package/js/modal.js +0 -382
  85. package/js/select.js +0 -391
  86. package/js/slider.js +0 -497
  87. package/js/tabs.js +0 -402
  88. package/js/tapTarget.js +0 -315
  89. package/js/waves.js +0 -615
  90. package/sass/components/_waves.scss +0 -187
@@ -1,131 +1,127 @@
1
- (function($) {
2
- 'use strict';
3
-
4
- let _defaults = {
5
- // Close when date is selected
6
- autoClose: false,
7
-
8
- // the default output format for the input field value
9
- format: 'mmm dd, yyyy',
10
-
11
- // Used to create date object from current input string
12
- parse: null,
13
-
14
- // The initial date to view when first opened
15
- defaultDate: null,
16
-
17
- // Make the `defaultDate` the initial selected value
18
- setDefaultDate: false,
19
-
20
- disableWeekends: false,
21
-
22
- disableDayFn: null,
23
-
24
- // First day of week (0: Sunday, 1: Monday etc)
25
- firstDay: 0,
26
-
27
- // The earliest date that can be selected
28
- minDate: null,
29
- // Thelatest date that can be selected
30
- maxDate: null,
31
-
32
- // Number of years either side, or array of upper/lower range
33
- yearRange: 10,
34
-
35
- // used internally (don't config outside)
36
- minYear: 0,
37
- maxYear: 9999,
38
- minMonth: undefined,
39
- maxMonth: undefined,
40
-
41
- startRange: null,
42
- endRange: null,
43
-
44
- isRTL: false,
45
-
46
- // Render the month after year in the calendar title
47
- showMonthAfterYear: false,
48
-
49
- // Render days of the calendar grid that fall in the next or previous month
50
- showDaysInNextAndPreviousMonths: false,
51
-
52
- // Specify a DOM element to render the calendar in
53
- container: null,
54
-
55
- // Show clear button
56
- showClearBtn: false,
57
-
58
- // internationalization
59
- i18n: {
60
- cancel: 'Cancel',
61
- clear: 'Clear',
62
- done: 'Ok',
63
- previousMonth: '‹',
64
- nextMonth: '›',
65
- months: [
66
- 'January',
67
- 'February',
68
- 'March',
69
- 'April',
70
- 'May',
71
- 'June',
72
- 'July',
73
- 'August',
74
- 'September',
75
- 'October',
76
- 'November',
77
- 'December'
78
- ],
79
- monthsShort: [
80
- 'Jan',
81
- 'Feb',
82
- 'Mar',
83
- 'Apr',
84
- 'May',
85
- 'Jun',
86
- 'Jul',
87
- 'Aug',
88
- 'Sep',
89
- 'Oct',
90
- 'Nov',
91
- 'Dec'
92
- ],
93
- weekdays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
94
- weekdaysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
95
- weekdaysAbbrev: ['S', 'M', 'T', 'W', 'T', 'F', 'S']
96
- },
97
-
98
- // events array
99
- events: [],
100
-
101
- // callback function
102
- onSelect: null,
103
- onOpen: null,
104
- onClose: null,
105
- onDraw: null
106
- };
107
-
108
- /**
109
- * @class
110
- *
111
- */
112
- class Datepicker extends Component {
113
- /**
114
- * Construct Datepicker instance and set up overlay
115
- * @constructor
116
- * @param {Element} el
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.el.M_Datepicker = 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 = $.extend({}, Datepicker.defaults.i18n, 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
- } else {
147
+ }
148
+ else {
153
149
  this.gotoDate(defDate);
154
150
  }
155
- } else {
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
- $(this.modalEl).remove();
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
- M.FormSelect.getInstance(oldYearSelect).destroy();
211
+ FormSelect.getInstance(oldYearSelect).destroy();
230
212
  }
231
213
  let oldMonthSelect = this.calendarEl.querySelector('.orig-select-month');
232
214
  if (oldMonthSelect) {
233
- M.FormSelect.getInstance(oldMonthSelect).destroy();
215
+ FormSelect.getInstance(oldMonthSelect).destroy();
234
216
  }
235
217
  }
236
218
 
237
219
  _insertHTMLIntoDOM() {
238
220
  if (this.options.showClearBtn) {
239
- $(this.clearBtn).css({ visibility: '' });
240
- this.clearBtn.innerHTML = this.options.i18n.clear;
221
+ this.clearBtn.style.visibility = '';
222
+ this.clearBtn.innerText = this.options.i18n.clear;
241
223
  }
242
-
243
- this.doneBtn.innerHTML = this.options.i18n.done;
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.$modalEl.appendTo(this.options.container);
251
- } else {
252
- this.$modalEl.insertBefore(this.el);
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 = M.Modal.init(this.modalEl, {
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
- return format(this.date);
269
- }
270
-
271
- if (!Datepicker._isDate(this.date)) {
272
- return '';
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
- } else if (Datepicker._isDate(max) && date > max) {
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.$el.trigger('change', { firedBy: 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 ($.isArray(opts.yearRange)) {
561
+ if (Array.isArray(opts.yearRange)) {
605
562
  i = opts.yearRange[0];
606
563
  j = opts.yearRange[1] + 1;
607
- } else {
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 fill="#000000" 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>';
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 fill="#000000" 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>';
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
- * refresh the HTML
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
- M.FormSelect.init(yearSelect, {
661
+ FormSelect.init(yearSelect, {
712
662
  classes: 'select-year',
713
663
  dropdownOptions: { container: document.body, constrainWidth: false }
714
664
  });
715
- M.FormSelect.init(monthSelect, {
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
- this.$modalEl = $(Datepicker._template);
756
- this.modalEl = this.$modalEl[0];
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
- return;
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
- $target.hasClass('datepicker-day-button') &&
834
- !$target.hasClass('is-empty') &&
835
- !$target.parent().hasClass('is-disabled')
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
- } else if ($target.closest('.month-prev').length) {
788
+ }
789
+ else if (target.closest('.month-prev')) {
848
790
  this.prevMonth();
849
- } else if ($target.closest('.month-next').length) {
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.firedBy === this) {
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
- if (Datepicker._isDate(date)) {
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
- Datepicker._template = [
958
- '<div class= "modal datepicker-modal">',
959
- '<div class="modal-content datepicker-container">',
960
- '<div class="datepicker-date-display">',
961
- '<span class="year-text"></span>',
962
- '<span class="date-text"></span>',
963
- '</div>',
964
- '<div class="datepicker-calendar-container">',
965
- '<div class="datepicker-calendar"></div>',
966
- '<div class="datepicker-footer">',
967
- '<button class="btn-flat datepicker-clear waves-effect" style="visibility: hidden;" type="button"></button>',
968
- '<div class="confirmation-btns">',
969
- '<button class="btn-flat datepicker-cancel waves-effect" type="button"></button>',
970
- '<button class="btn-flat datepicker-done waves-effect" type="button"></button>',
971
- '</div>',
972
- '</div>',
973
- '</div>',
974
- '</div>',
975
- '</div>'
976
- ].join('');
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
+ }