@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.
- package/Gruntfile.js +68 -313
- package/README.md +26 -14
- package/dist/css/materialize.css +1009 -1822
- package/dist/css/materialize.min.css +2 -8
- package/dist/js/materialize.js +8414 -12299
- package/dist/js/materialize.min.js +8968 -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/_theme_variables.scss +98 -0
- 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 +293 -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,54 +1,91 @@
|
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
}
|
|
201
|
-
|
|
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
|
-
|
|
218
|
-
|
|
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
|
-
|
|
235
|
+
const containerEl = optEl instanceof HTMLElement ? optEl : document.querySelector(optEl);
|
|
236
|
+
|
|
224
237
|
if (this.options.container && !!containerEl) {
|
|
225
|
-
this
|
|
226
|
-
}
|
|
227
|
-
|
|
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
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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
|
-
|
|
303
|
-
this
|
|
304
|
-
this
|
|
305
|
-
this
|
|
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
|
-
|
|
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
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
tick.
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
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
|
-
}
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
367
379
|
for (let i = 0; i < 24; i += 1) {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
tick.
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
-
|
|
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
|
-
|
|
390
|
-
|
|
391
|
-
tick.
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
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
|
-
|
|
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
|
-
|
|
410
|
-
this.amOrPm =
|
|
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
|
-
|
|
417
|
-
|
|
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' &&
|
|
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
|
-
|
|
457
|
-
|
|
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
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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
|
-
|
|
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
|
-
|
|
506
|
+
this.canvas?.classList.add('timepicker-canvas-out');
|
|
489
507
|
setTimeout(() => {
|
|
490
|
-
|
|
508
|
+
self.canvas?.classList.remove('timepicker-canvas-out');
|
|
491
509
|
self.setHand(x, y);
|
|
492
510
|
}, delay);
|
|
493
|
-
}
|
|
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
|
|
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
|
-
}
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
512
528
|
const hour = new Date().getHours();
|
|
513
|
-
this
|
|
529
|
+
this.inputHours.value = (hour % 12).toString();
|
|
514
530
|
}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
const value = parseInt(this.inputMinutes.value);
|
|
518
534
|
if (value >= 0 && value < 60) {
|
|
519
|
-
this
|
|
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
|
-
}
|
|
538
|
+
(<HTMLElement>this.modalEl.querySelector('.confirmation-btns :nth-child(2)')).focus();
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
526
541
|
const minutes = new Date().getMinutes();
|
|
527
|
-
this
|
|
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('
|
|
547
|
-
this.
|
|
548
|
-
this.bg.setAttribute('
|
|
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
|
|
615
|
-
}
|
|
616
|
-
|
|
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
|
|
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
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
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
|
-
|
|
708
|
+
|