@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,54 +1,91 @@
1
- (function($) {
2
- 'use strict';
3
-
4
- let _defaults = {
5
- dialRadius: 135,
6
- outerRadius: 105,
7
- innerRadius: 70,
8
- tickRadius: 20,
9
- duration: 350,
10
- container: null,
11
- defaultTime: 'now', // default time, 'now' or '13:14' e.g.
12
- fromNow: 0, // Millisecond offset from the defaultTime
13
- showClearBtn: false,
14
-
15
- // internationalization
16
- i18n: {
17
- cancel: 'Cancel',
18
- clear: 'Clear',
19
- done: 'Ok'
20
- },
21
-
22
- autoClose: false, // auto close when minute is selected
23
- twelveHour: true, // change to 12 hour AM/PM clock from 24 hour
24
- vibrate: true, // vibrate the device when dragging clock hand
25
-
26
- // Callbacks
27
- onOpenStart: null,
28
- onOpenEnd: null,
29
- onCloseStart: null,
30
- onCloseEnd: null,
31
- onSelect: null
32
- };
33
-
34
- /**
35
- * @class
36
- *
37
- */
38
- class Timepicker extends Component {
1
+ import { Component } from "./component";
2
+ import { M } from "./global";
3
+ import { Modal } from "./modal";
4
+
5
+ let _defaults = {
6
+ dialRadius: 135,
7
+ outerRadius: 105,
8
+ innerRadius: 70,
9
+ tickRadius: 20,
10
+ duration: 350,
11
+ container: null,
12
+ defaultTime: 'now', // default time, 'now' or '13:14' e.g.
13
+ fromNow: 0, // Millisecond offset from the defaultTime
14
+ showClearBtn: false,
15
+ // internationalization
16
+ i18n: {
17
+ cancel: 'Cancel',
18
+ clear: 'Clear',
19
+ done: 'Ok'
20
+ },
21
+ autoClose: false, // auto close when minute is selected
22
+ twelveHour: true, // change to 12 hour AM/PM clock from 24 hour
23
+ vibrate: true, // vibrate the device when dragging clock hand
24
+ // Callbacks
25
+ onOpenStart: null,
26
+ onOpenEnd: null,
27
+ onCloseStart: null,
28
+ onCloseEnd: null,
29
+ onSelect: null
30
+ };
31
+
32
+ type Point = {
33
+ x: number,
34
+ y: number
35
+ };
36
+
37
+ export class Timepicker extends Component {
38
+ el: HTMLInputElement;
39
+ id: string;
40
+ modal: Modal;
41
+ modalEl: HTMLElement;
42
+ private _handleInputKeydownBound: any;
43
+ private _handleInputClickBound: any;
44
+ private _handleClockClickStartBound: any;
45
+ private _handleDocumentClickMoveBound: any;
46
+ private _handleDocumentClickEndBound: any;
47
+ private _inputFromTextFieldBound: any;
48
+ plate: any;
49
+ digitalClock: any;
50
+ inputHours: HTMLInputElement;
51
+ inputMinutes: HTMLInputElement;
52
+ x0: number;
53
+ y0: number;
54
+ moved: boolean;
55
+ dx: number;
56
+ dy: number;
57
+ currentView: string;
58
+ hand: any;
59
+ minutesView: HTMLElement;
60
+ hours: any;
61
+ minutes: any;
62
+ time: string;
63
+ amOrPm: any;
64
+ static _template: any;
65
+ isOpen: boolean;
66
+ vibrate: string;
67
+ _canvas: HTMLElement;
68
+ hoursView: any;
69
+ spanAmPm: HTMLSpanElement;
70
+ footer: HTMLElement;
71
+ private _amBtn: HTMLElement;
72
+ private _pmBtn: HTMLElement;
73
+ bg: Element;
74
+ bearing: Element;
75
+ g: Element;
76
+ toggleViewTimer: string | number | NodeJS.Timeout;
77
+ canvas: any;
78
+ vibrateTimer: any;
79
+
39
80
  constructor(el, options) {
40
81
  super(Timepicker, el, options);
41
-
42
- this.el.M_Timepicker = this;
43
-
44
- this.options = $.extend({}, Timepicker.defaults, options);
45
-
82
+ (this.el as any).M_Timepicker = this;
83
+ this.options = {...Timepicker.defaults, ...options};
46
84
  this.id = M.guid();
47
85
  this._insertHTMLIntoDOM();
48
86
  this._setupModal();
49
87
  this._setupVariables();
50
88
  this._setupEventHandlers();
51
-
52
89
  this._clockSetup();
53
90
  this._pickerSetup();
54
91
  }
@@ -70,18 +107,7 @@
70
107
  return document.createElementNS(svgNS, name);
71
108
  }
72
109
 
73
- /**
74
- * @typedef {Object} Point
75
- * @property {number} x The X Coordinate
76
- * @property {number} y The Y Coordinate
77
- */
78
-
79
- /**
80
- * Get x position of mouse or touch event
81
- * @param {Event} e
82
- * @return {Point} x and y location
83
- */
84
- static _Pos(e) {
110
+ static _Pos(e): Point {
85
111
  if (e.targetTouches && e.targetTouches.length >= 1) {
86
112
  return { x: e.targetTouches[0].clientX, y: e.targetTouches[0].clientY };
87
113
  }
@@ -89,27 +115,18 @@
89
115
  return { x: e.clientX, y: e.clientY };
90
116
  }
91
117
 
92
- /**
93
- * Get Instance
94
- */
95
118
  static getInstance(el) {
96
- let domElem = !!el.jquery ? el[0] : el;
119
+ const domElem = !!el.jquery ? el[0] : el;
97
120
  return domElem.M_Timepicker;
98
121
  }
99
122
 
100
- /**
101
- * Teardown component
102
- */
103
123
  destroy() {
104
124
  this._removeEventHandlers();
105
125
  this.modal.destroy();
106
- $(this.modalEl).remove();
107
- this.el.M_Timepicker = undefined;
126
+ this.modalEl.remove();
127
+ (this.el as any).M_Timepicker = undefined;
108
128
  }
109
129
 
110
- /**
111
- * Setup Event Handlers
112
- */
113
130
  _setupEventHandlers() {
114
131
  this._handleInputKeydownBound = this._handleInputKeydown.bind(this);
115
132
  this._handleInputClickBound = this._handleInputClick.bind(this);
@@ -117,15 +134,13 @@
117
134
  this._handleDocumentClickMoveBound = this._handleDocumentClickMove.bind(this);
118
135
  this._handleDocumentClickEndBound = this._handleDocumentClickEnd.bind(this);
119
136
  this._inputFromTextFieldBound = this._handleTimeInputEnterKey.bind(this);
120
-
121
137
  this.el.addEventListener('click', this._handleInputClickBound);
122
138
  this.el.addEventListener('keydown', this._handleInputKeydownBound);
123
139
  this.plate.addEventListener('mousedown', this._handleClockClickStartBound);
124
140
  this.plate.addEventListener('touchstart', this._handleClockClickStartBound);
125
141
  this.digitalClock.addEventListener('keyup', this._inputFromTextFieldBound);
126
-
127
- $(this.inputHours).on('click', this.showView.bind(this, 'hours'));
128
- $(this.inputMinutes).on('click', this.showView.bind(this, 'minutes'));
142
+ this.inputHours.addEventListener('click', this.showView.bind(this, 'hours'));
143
+ this.inputMinutes.addEventListener('click', this.showView.bind(this, 'minutes'));
129
144
  }
130
145
 
131
146
  _removeEventHandlers() {
@@ -165,11 +180,9 @@
165
180
 
166
181
  // Set clock hands
167
182
  this.setHand(this.dx, this.dy, false);
168
-
169
183
  // Mousemove on document
170
184
  document.addEventListener('mousemove', this._handleDocumentClickMoveBound);
171
185
  document.addEventListener('touchmove', this._handleDocumentClickMoveBound);
172
-
173
186
  // Mouseup on document
174
187
  document.addEventListener('mouseup', this._handleDocumentClickEndBound);
175
188
  document.addEventListener('touchend', this._handleDocumentClickEndBound);
@@ -181,7 +194,7 @@
181
194
  let x = clickPos.x - this.x0;
182
195
  let y = clickPos.y - this.y0;
183
196
  this.moved = true;
184
- this.setHand(x, y, false, true);
197
+ this.setHand(x, y, false);
185
198
  }
186
199
 
187
200
  _handleDocumentClickEnd(e) {
@@ -194,37 +207,38 @@
194
207
  if (this.moved && x === this.dx && y === this.dy) {
195
208
  this.setHand(x, y);
196
209
  }
197
-
198
210
  if (this.currentView === 'hours') {
199
211
  this.showView('minutes', this.options.duration / 2);
200
- } else if (this.options.autoClose) {
201
- $(this.minutesView).addClass('timepicker-dial-out');
212
+ }
213
+ else if (this.options.autoClose) {
214
+ this.minutesView.classList.add('timepicker-dial-out');
202
215
  setTimeout(() => {
203
216
  this.done();
204
217
  }, this.options.duration / 2);
205
218
  }
206
-
207
219
  if (typeof this.options.onSelect === 'function') {
208
220
  this.options.onSelect.call(this, this.hours, this.minutes);
209
221
  }
210
-
211
222
  // Unbind mousemove event
212
223
  document.removeEventListener('mousemove', this._handleDocumentClickMoveBound);
213
224
  document.removeEventListener('touchmove', this._handleDocumentClickMoveBound);
214
225
  }
215
226
 
216
227
  _insertHTMLIntoDOM() {
217
- this.$modalEl = $(Timepicker._template);
218
- this.modalEl = this.$modalEl[0];
228
+ const template = document.createElement('template');
229
+ template.innerHTML = Timepicker._template.trim();
230
+ this.modalEl = <HTMLElement>template.content.firstChild;
219
231
  this.modalEl.id = 'modal-' + this.id;
220
232
 
221
233
  // Append popover to input by default
222
234
  const optEl = this.options.container;
223
- let containerEl = optEl instanceof HTMLElement ? optEl : document.querySelector(optEl);
235
+ const containerEl = optEl instanceof HTMLElement ? optEl : document.querySelector(optEl);
236
+
224
237
  if (this.options.container && !!containerEl) {
225
- this.$modalEl.appendTo(containerEl);
226
- } else {
227
- this.$modalEl.insertBefore(this.el);
238
+ containerEl.append(this.modalEl);
239
+ }
240
+ else {
241
+ this.el.parentElement.appendChild(this.modalEl);
228
242
  }
229
243
  }
230
244
 
@@ -246,14 +260,12 @@
246
260
  this.currentView = 'hours';
247
261
  this.vibrate = navigator.vibrate
248
262
  ? 'vibrate'
249
- : navigator.webkitVibrate
263
+ : (navigator as any).webkitVibrate
250
264
  ? 'webkitVibrate'
251
265
  : null;
252
-
253
266
  this._canvas = this.modalEl.querySelector('.timepicker-canvas');
254
267
  this.plate = this.modalEl.querySelector('.timepicker-plate');
255
268
  this.digitalClock = this.modalEl.querySelector('.timepicker-display-column');
256
-
257
269
  this.hoursView = this.modalEl.querySelector('.timepicker-hours');
258
270
  this.minutesView = this.modalEl.querySelector('.timepicker-minutes');
259
271
  this.inputHours = this.modalEl.querySelector('.timepicker-input-hours');
@@ -263,48 +275,52 @@
263
275
  this.amOrPm = 'PM';
264
276
  }
265
277
 
278
+ private _createButton(text: string, visibility: string): HTMLButtonElement {
279
+ const button = document.createElement('button');
280
+ button.classList.add('btn-flat', 'waves-effect');
281
+ button.style.visibility = visibility;
282
+ button.type = 'button';
283
+ button.tabIndex = this.options.twelveHour ? 3 : 1;
284
+ button.innerText = text;
285
+ return button;
286
+ }
287
+
266
288
  _pickerSetup() {
267
- let $clearBtn = $(
268
- `<button class="btn-flat timepicker-clear waves-effect" style="visibility: hidden;" type="button" tabindex="${
269
- this.options.twelveHour ? '3' : '1'
270
- }">${this.options.i18n.clear}</button>`
271
- )
272
- .appendTo(this.footer)
273
- .on('click', this.clear.bind(this));
274
- if (this.options.showClearBtn) {
275
- $clearBtn.css({ visibility: '' });
276
- }
277
-
278
- let confirmationBtnsContainer = $('<div class="confirmation-btns"></div>');
279
- $(
280
- '<button class="btn-flat timepicker-close waves-effect" type="button" tabindex="' +
281
- (this.options.twelveHour ? '3' : '1') +
282
- '">' +
283
- this.options.i18n.cancel +
284
- '</button>'
285
- )
286
- .appendTo(confirmationBtnsContainer)
287
- .on('click', this.close.bind(this));
288
- $(
289
- '<button class="btn-flat timepicker-close waves-effect" type="button" tabindex="' +
290
- (this.options.twelveHour ? '3' : '1') +
291
- '">' +
292
- this.options.i18n.done +
293
- '</button>'
294
- )
295
- .appendTo(confirmationBtnsContainer)
296
- .on('click', this.done.bind(this));
297
- confirmationBtnsContainer.appendTo(this.footer);
289
+ const clearButton = this._createButton(this.options.i18n.clear, this.options.showClearBtn ? '' : 'hidden');
290
+ clearButton.classList.add('timepicker-clear');
291
+ clearButton.addEventListener('click', this.clear.bind(this));
292
+ this.footer.appendChild(clearButton);
293
+
294
+ const confirmationBtnsContainer = document.createElement('div');
295
+ confirmationBtnsContainer.classList.add('confirmation-btns');
296
+ this.footer.append(confirmationBtnsContainer);
297
+
298
+ const cancelButton = this._createButton(this.options.i18n.cancel, '');
299
+ cancelButton.classList.add('timepicker-close');
300
+ cancelButton.addEventListener('click', this.close.bind(this));
301
+ confirmationBtnsContainer.appendChild(cancelButton);
302
+
303
+ const doneButton = this._createButton(this.options.i18n.done, '');
304
+ doneButton.classList.add('timepicker-close');
305
+ doneButton.addEventListener('click', this.done.bind(this));
306
+ confirmationBtnsContainer.appendChild(doneButton);
298
307
  }
299
308
 
300
309
  _clockSetup() {
301
310
  if (this.options.twelveHour) {
302
- this.$amBtn = $('<div class="am-btn">AM</div>');
303
- this.$pmBtn = $('<div class="pm-btn">PM</div>');
304
- this.$amBtn.on('click', this._handleAmPmClick.bind(this)).appendTo(this.spanAmPm);
305
- this.$pmBtn.on('click', this._handleAmPmClick.bind(this)).appendTo(this.spanAmPm);
311
+ // AM Button
312
+ this._amBtn = document.createElement('div');
313
+ this._amBtn.classList.add('am-btn');
314
+ this._amBtn.innerText = 'AM';
315
+ this._amBtn.addEventListener('click', this._handleAmPmClick.bind(this));
316
+ this.spanAmPm.appendChild(this._amBtn);
317
+ // PM Button
318
+ this._pmBtn = document.createElement('div');
319
+ this._pmBtn.classList.add('pm-btn');
320
+ this._pmBtn.innerText = 'PM';
321
+ this._pmBtn.addEventListener('click', this._handleAmPmClick.bind(this));
322
+ this.spanAmPm.appendChild(this._pmBtn);
306
323
  }
307
-
308
324
  this._buildHoursView();
309
325
  this._buildMinutesView();
310
326
  this._buildSVGClock();
@@ -315,21 +331,20 @@
315
331
  let dialRadius = this.options.dialRadius;
316
332
  let tickRadius = this.options.tickRadius;
317
333
  let diameter = dialRadius * 2;
318
-
319
334
  let svg = Timepicker._createSVGEl('svg');
320
335
  svg.setAttribute('class', 'timepicker-svg');
321
- svg.setAttribute('width', diameter);
322
- svg.setAttribute('height', diameter);
336
+ svg.setAttribute('width', diameter.toString());
337
+ svg.setAttribute('height', diameter.toString());
323
338
  let g = Timepicker._createSVGEl('g');
324
339
  g.setAttribute('transform', 'translate(' + dialRadius + ',' + dialRadius + ')');
325
340
  let bearing = Timepicker._createSVGEl('circle');
326
341
  bearing.setAttribute('class', 'timepicker-canvas-bearing');
327
- bearing.setAttribute('cx', 0);
328
- bearing.setAttribute('cy', 0);
329
- bearing.setAttribute('r', 4);
342
+ bearing.setAttribute('cx', '0');
343
+ bearing.setAttribute('cy', '0');
344
+ bearing.setAttribute('r', '4');
330
345
  let hand = Timepicker._createSVGEl('line');
331
- hand.setAttribute('x1', 0);
332
- hand.setAttribute('y1', 0);
346
+ hand.setAttribute('x1', '0');
347
+ hand.setAttribute('y1', '0');
333
348
  let bg = Timepicker._createSVGEl('circle');
334
349
  bg.setAttribute('class', 'timepicker-canvas-bg');
335
350
  bg.setAttribute('r', tickRadius);
@@ -338,7 +353,6 @@
338
353
  g.appendChild(bearing);
339
354
  svg.appendChild(g);
340
355
  this._canvas.appendChild(svg);
341
-
342
356
  this.hand = hand;
343
357
  this.bg = bg;
344
358
  this.bearing = bearing;
@@ -346,75 +360,74 @@
346
360
  }
347
361
 
348
362
  _buildHoursView() {
349
- let $tick = $('<div class="timepicker-tick"></div>');
363
+ const $tick = document.createElement('div');
364
+ $tick.classList.add('timepicker-tick');
350
365
  // Hours view
351
366
  if (this.options.twelveHour) {
352
367
  for (let i = 1; i < 13; i += 1) {
353
- let tick = $tick.clone();
354
- let radian = (i / 6) * Math.PI;
355
- let radius = this.options.outerRadius;
356
- tick.css({
357
- left:
358
- this.options.dialRadius + Math.sin(radian) * radius - this.options.tickRadius + 'px',
359
- top:
360
- this.options.dialRadius - Math.cos(radian) * radius - this.options.tickRadius + 'px'
361
- });
362
- tick.html(i === 0 ? '00' : i);
363
- this.hoursView.appendChild(tick[0]);
368
+ const tick = <HTMLElement>$tick.cloneNode(true);
369
+ const radian = (i / 6) * Math.PI;
370
+ const radius = this.options.outerRadius;
371
+ tick.style.left = this.options.dialRadius + Math.sin(radian) * radius - this.options.tickRadius + 'px';
372
+ tick.style.top = this.options.dialRadius - Math.cos(radian) * radius - this.options.tickRadius + 'px';
373
+ tick.innerHTML = i === 0 ? '00' : i.toString();
374
+ this.hoursView.appendChild(tick);
364
375
  // tick.on(mousedownEvent, mousedown);
365
376
  }
366
- } else {
377
+ }
378
+ else {
367
379
  for (let i = 0; i < 24; i += 1) {
368
- let tick = $tick.clone();
369
- let radian = (i / 6) * Math.PI;
370
- let inner = i > 0 && i < 13;
371
- let radius = inner ? this.options.innerRadius : this.options.outerRadius;
372
- tick.css({
373
- left:
374
- this.options.dialRadius + Math.sin(radian) * radius - this.options.tickRadius + 'px',
375
- top:
376
- this.options.dialRadius - Math.cos(radian) * radius - this.options.tickRadius + 'px'
377
- });
378
- tick.html(i === 0 ? '00' : i);
379
- this.hoursView.appendChild(tick[0]);
380
+ const tick = <HTMLElement>$tick.cloneNode(true);
381
+ const radian = (i / 6) * Math.PI;
382
+ const inner = i > 0 && i < 13;
383
+ const radius = inner ? this.options.innerRadius : this.options.outerRadius;
384
+ tick.style.left = this.options.dialRadius + Math.sin(radian) * radius - this.options.tickRadius + 'px';
385
+ tick.style.top = this.options.dialRadius - Math.cos(radian) * radius - this.options.tickRadius + 'px';
386
+ tick.innerHTML = i === 0 ? '00' : i.toString();
387
+ this.hoursView.appendChild(tick);
380
388
  // tick.on(mousedownEvent, mousedown);
381
389
  }
382
390
  }
383
391
  }
384
392
 
385
393
  _buildMinutesView() {
386
- let $tick = $('<div class="timepicker-tick"></div>');
394
+ const _tick = document.createElement('div');
395
+ _tick.classList.add('timepicker-tick');
387
396
  // Minutes view
388
397
  for (let i = 0; i < 60; i += 5) {
389
- let tick = $tick.clone();
390
- let radian = (i / 30) * Math.PI;
391
- tick.css({
392
- left:
393
- this.options.dialRadius +
394
- Math.sin(radian) * this.options.outerRadius -
395
- this.options.tickRadius +
396
- 'px',
397
- top:
398
+ const tick = <HTMLElement>_tick.cloneNode(true);
399
+ const radian = (i / 30) * Math.PI;
400
+ tick.style.left =
401
+ this.options.dialRadius +
402
+ Math.sin(radian) * this.options.outerRadius -
403
+ this.options.tickRadius +
404
+ 'px';
405
+ tick.style.top =
398
406
  this.options.dialRadius -
399
407
  Math.cos(radian) * this.options.outerRadius -
400
408
  this.options.tickRadius +
401
- 'px'
402
- });
403
- tick.html(Timepicker._addLeadingZero(i));
404
- this.minutesView.appendChild(tick[0]);
409
+ 'px';
410
+ tick.innerHTML = Timepicker._addLeadingZero(i);
411
+ this.minutesView.appendChild(tick);
405
412
  }
406
413
  }
407
414
 
408
415
  _handleAmPmClick(e) {
409
- let $btnClicked = $(e.target);
410
- this.amOrPm = $btnClicked.hasClass('am-btn') ? 'AM' : 'PM';
416
+ const btnClicked = <HTMLElement>e.target;
417
+ this.amOrPm = btnClicked.classList.contains('am-btn') ? 'AM' : 'PM';
411
418
  this._updateAmPmView();
412
419
  }
413
420
 
414
421
  _updateAmPmView() {
415
422
  if (this.options.twelveHour) {
416
- this.$amBtn.toggleClass('text-primary', this.amOrPm === 'AM');
417
- this.$pmBtn.toggleClass('text-primary', this.amOrPm === 'PM');
423
+ if (this.amOrPm === 'PM') {
424
+ this._amBtn.classList.remove('text-primary');
425
+ this._pmBtn.classList.add('text-primary');
426
+ }
427
+ else if (this.amOrPm === 'AM') {
428
+ this._amBtn.classList.add('text-primary');
429
+ this._pmBtn.classList.remove('text-primary');
430
+ }
418
431
  }
419
432
  }
420
433
 
@@ -431,9 +444,9 @@
431
444
  }
432
445
  if (value[0] === 'now') {
433
446
  let now = new Date(+new Date() + this.options.fromNow);
434
- value = [now.getHours(), now.getMinutes()];
447
+ value = [now.getHours().toString(), now.getMinutes().toString()];
435
448
  if (this.options.twelveHour) {
436
- this.amOrPm = value[0] >= 12 && value[0] < 24 ? 'PM' : 'AM';
449
+ this.amOrPm = parseInt(value[0]) >= 12 && parseInt(value[0]) < 24 ? 'PM' : 'AM';
437
450
  }
438
451
  }
439
452
  this.hours = +value[0] || 0;
@@ -444,8 +457,8 @@
444
457
  this._updateAmPmView();
445
458
  }
446
459
 
447
- showView(view, delay) {
448
- if (view === 'minutes' && $(this.hoursView).css('visibility') === 'visible') {
460
+ showView(view, delay: number = null) {
461
+ if (view === 'minutes' && getComputedStyle(this.hoursView).visibility === 'visible') {
449
462
  // raiseCallback(this.options.beforeHourSelect);
450
463
  }
451
464
  let isHours = view === 'hours',
@@ -453,22 +466,27 @@
453
466
  hideView = isHours ? this.minutesView : this.hoursView;
454
467
  this.currentView = view;
455
468
 
456
- $(this.inputHours).toggleClass('text-primary', isHours);
457
- $(this.inputMinutes).toggleClass('text-primary', !isHours);
469
+ if (isHours) {
470
+ this.inputHours.classList.add('text-primary');
471
+ this.inputMinutes.classList.remove('text-primary');
472
+ }
473
+ else {
474
+ this.inputHours.classList.remove('text-primary');
475
+ this.inputMinutes.classList.add('text-primary');
476
+ }
458
477
 
459
478
  // Transition view
460
479
  hideView.classList.add('timepicker-dial-out');
461
- $(nextView)
462
- .css('visibility', 'visible')
463
- .removeClass('timepicker-dial-out');
480
+
481
+ nextView.style.visibility = 'visible';
482
+ nextView.classList.remove('timepicker-dial-out');
464
483
 
465
484
  // Reset clock hand
466
485
  this.resetClock(delay);
467
-
468
486
  // After transitions ended
469
487
  clearTimeout(this.toggleViewTimer);
470
488
  this.toggleViewTimer = setTimeout(() => {
471
- $(hideView).css('visibility', 'hidden');
489
+ hideView.style.visibility = 'hidden';
472
490
  }, this.options.duration);
473
491
  }
474
492
 
@@ -485,46 +503,43 @@
485
503
  self = this;
486
504
 
487
505
  if (delay) {
488
- $(this.canvas).addClass('timepicker-canvas-out');
506
+ this.canvas?.classList.add('timepicker-canvas-out');
489
507
  setTimeout(() => {
490
- $(self.canvas).removeClass('timepicker-canvas-out');
508
+ self.canvas?.classList.remove('timepicker-canvas-out');
491
509
  self.setHand(x, y);
492
510
  }, delay);
493
- } else {
511
+ }
512
+ else {
494
513
  this.setHand(x, y);
495
514
  }
496
515
  }
497
516
 
498
517
  _inputFromTextField() {
499
518
  const isHours = this.currentView === 'hours';
500
-
501
519
  if (isHours) {
502
- const value = this['inputHours'].value;
503
-
520
+ const value = parseInt(this.inputHours.value);
504
521
  if (value > 0 && value < 13) {
505
522
  this.drawClockFromTimeInput(value, isHours);
506
-
507
523
  this.showView('minutes', this.options.duration / 2);
508
-
509
524
  this.hours = value;
510
525
  this.inputMinutes.focus();
511
- } else {
526
+ }
527
+ else {
512
528
  const hour = new Date().getHours();
513
- this['inputHours'].value = hour % 12;
529
+ this.inputHours.value = (hour % 12).toString();
514
530
  }
515
- } else {
516
- const value = this['inputMinutes'].value;
517
-
531
+ }
532
+ else {
533
+ const value = parseInt(this.inputMinutes.value);
518
534
  if (value >= 0 && value < 60) {
519
- this['inputMinutes'].value = Timepicker._addLeadingZero(value);
520
-
535
+ this.inputMinutes.value = Timepicker._addLeadingZero(value);
521
536
  this.drawClockFromTimeInput(value, isHours);
522
-
523
537
  this.minutes = value;
524
- this.modalEl.querySelector('.confirmation-btns :nth-child(2)').focus();
525
- } else {
538
+ (<HTMLElement>this.modalEl.querySelector('.confirmation-btns :nth-child(2)')).focus();
539
+ }
540
+ else {
526
541
  const minutes = new Date().getMinutes();
527
- this['inputMinutes'].value = Timepicker._addLeadingZero(minutes);
542
+ this.inputMinutes.value = Timepicker._addLeadingZero(minutes);
528
543
  }
529
544
  }
530
545
  }
@@ -533,23 +548,20 @@
533
548
  const unit = Math.PI / (isHours ? 6 : 30);
534
549
  const radian = value * unit;
535
550
  let radius;
536
-
537
551
  if (this.options.twelveHour) {
538
552
  radius = this.options.outerRadius;
539
553
  }
540
-
541
554
  let cx1 = Math.sin(radian) * (radius - this.options.tickRadius),
542
555
  cy1 = -Math.cos(radian) * (radius - this.options.tickRadius),
543
556
  cx2 = Math.sin(radian) * radius,
544
557
  cy2 = -Math.cos(radian) * radius;
545
-
546
- this.hand.setAttribute('x2', cx1);
547
- this.hand.setAttribute('y2', cy1);
548
- this.bg.setAttribute('cx', cx2);
549
- this.bg.setAttribute('cy', cy2);
558
+ this.hand.setAttribute('x2', cx1.toString());
559
+ this.hand.setAttribute('y2', cy1.toString());
560
+ this.bg.setAttribute('cx', cx2.toString());
561
+ this.bg.setAttribute('cy', cy2.toString());
550
562
  }
551
563
 
552
- setHand(x, y, roundBy5) {
564
+ setHand(x, y, roundBy5: boolean = false) {
553
565
  let radian = Math.atan2(x, -y),
554
566
  isHours = this.currentView === 'hours',
555
567
  unit = Math.PI / (isHours || roundBy5 ? 6 : 30),
@@ -611,9 +623,10 @@
611
623
 
612
624
  this[this.currentView] = value;
613
625
  if (isHours) {
614
- this['inputHours'].value = value;
615
- } else {
616
- this['inputMinutes'].value = Timepicker._addLeadingZero(value);
626
+ this.inputHours.value = value.toString();
627
+ }
628
+ else {
629
+ this.inputMinutes.value = Timepicker._addLeadingZero(value);
617
630
  }
618
631
 
619
632
  // Set clock hand and others' position
@@ -621,37 +634,27 @@
621
634
  cy1 = -Math.cos(radian) * (radius - this.options.tickRadius),
622
635
  cx2 = Math.sin(radian) * radius,
623
636
  cy2 = -Math.cos(radian) * radius;
624
- this.hand.setAttribute('x2', cx1);
625
- this.hand.setAttribute('y2', cy1);
626
- this.bg.setAttribute('cx', cx2);
627
- this.bg.setAttribute('cy', cy2);
637
+ this.hand.setAttribute('x2', cx1.toString());
638
+ this.hand.setAttribute('y2', cy1.toString());
639
+ this.bg.setAttribute('cx', cx2.toString());
640
+ this.bg.setAttribute('cy', cy2.toString());
628
641
  }
629
642
 
630
643
  open() {
631
- if (this.isOpen) {
632
- return;
633
- }
634
-
644
+ if (this.isOpen) return;
635
645
  this.isOpen = true;
636
646
  this._updateTimeFromInput();
637
647
  this.showView('hours');
638
-
639
- this.modal.open();
648
+ this.modal.open(undefined);
640
649
  }
641
650
 
642
651
  close() {
643
- if (!this.isOpen) {
644
- return;
645
- }
646
-
652
+ if (!this.isOpen) return;
647
653
  this.isOpen = false;
648
654
  this.modal.close();
649
655
  }
650
656
 
651
- /**
652
- * Finish timepicker selection.
653
- */
654
- done(e, clearValue) {
657
+ done(e = null, clearValue = null) {
655
658
  // Set input value
656
659
  let last = this.el.value;
657
660
  let value = clearValue
@@ -662,12 +665,10 @@
662
665
  value = `${value} ${this.amOrPm}`;
663
666
  }
664
667
  this.el.value = value;
665
-
666
668
  // Trigger change event
667
669
  if (value !== last) {
668
- this.$el.trigger('change');
670
+ this.el.dispatchEvent(new Event('change'));
669
671
  }
670
-
671
672
  this.close();
672
673
  this.el.focus();
673
674
  }
@@ -675,38 +676,33 @@
675
676
  clear() {
676
677
  this.done(null, true);
677
678
  }
678
- }
679
679
 
680
- Timepicker._template = [
681
- '<div class= "modal timepicker-modal">',
682
- '<div class="modal-content timepicker-container">',
683
- '<div class="timepicker-digital-display">',
684
- '<div class="timepicker-text-container">',
685
- '<div class="timepicker-display-column">',
686
- '<input type="text" maxlength="2" autofocus class="timepicker-input-hours text-primary" />',
687
- ':',
688
- '<input type="text" maxlength="2" class="timepicker-input-minutes" />',
689
- '</div>',
690
- '<div class="timepicker-display-column timepicker-display-am-pm">',
691
- '<div class="timepicker-span-am-pm"></div>',
692
- '</div>',
693
- '</div>',
694
- '</div>',
695
- '<div class="timepicker-analog-display">',
696
- '<div class="timepicker-plate">',
697
- '<div class="timepicker-canvas"></div>',
698
- '<div class="timepicker-dial timepicker-hours"></div>',
699
- '<div class="timepicker-dial timepicker-minutes timepicker-dial-out"></div>',
700
- '</div>',
701
- '<div class="timepicker-footer"></div>',
702
- '</div>',
703
- '</div>',
704
- '</div>'
705
- ].join('');
706
-
707
- M.Timepicker = Timepicker;
708
-
709
- if (M.jQueryLoaded) {
710
- M.initializeJqueryWrapper(Timepicker, 'timepicker', 'M_Timepicker');
680
+ static {
681
+ Timepicker._template = `
682
+ <div class="modal timepicker-modal">
683
+ <div class="modal-content timepicker-container">
684
+ <div class="timepicker-digital-display">
685
+ <div class="timepicker-text-container">
686
+ <div class="timepicker-display-column">
687
+ <input type="text" maxlength="2" autofocus class="timepicker-input-hours text-primary" />
688
+ :
689
+ <input type="text" maxlength="2" class="timepicker-input-minutes" />
690
+ </div>
691
+ <div class="timepicker-display-column timepicker-display-am-pm">
692
+ <div class="timepicker-span-am-pm"></div>
693
+ </div>
694
+ </div>
695
+ </div>
696
+ <div class="timepicker-analog-display">
697
+ <div class="timepicker-plate">
698
+ <div class="timepicker-canvas"></div>
699
+ <div class="timepicker-dial timepicker-hours"></div>
700
+ <div class="timepicker-dial timepicker-minutes timepicker-dial-out"></div>
701
+ </div>
702
+ <div class="timepicker-footer"></div>
703
+ </div>
704
+ </div>
705
+ </div`;
706
+ }
711
707
  }
712
- })(cash);
708
+