materialize-sass 1.0.0.alpha1 → 1.0.0.alpha2
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.
- checksums.yaml +4 -4
- data/assets/javascripts/materialize-sprockets.js +1 -1
- data/assets/javascripts/materialize.js +1162 -1218
- data/assets/javascripts/materialize/anime.min.js +417 -0
- data/assets/javascripts/materialize/buttons.js +49 -26
- data/assets/javascripts/materialize/cards.js +14 -8
- data/assets/javascripts/materialize/cash.js +3 -5
- data/assets/javascripts/materialize/chips.js +22 -19
- data/assets/javascripts/materialize/collapsible.js +53 -17
- data/assets/javascripts/materialize/datepicker.js +94 -78
- data/assets/javascripts/materialize/dropdown.js +33 -26
- data/assets/javascripts/materialize/extras/nouislider.js +1 -1
- data/assets/javascripts/materialize/extras/nouislider.min.js +1 -1
- data/assets/javascripts/materialize/forms.js +17 -6
- data/assets/javascripts/materialize/global.js +17 -15
- data/assets/javascripts/materialize/materialbox.js +62 -35
- data/assets/javascripts/materialize/modal.js +50 -19
- data/assets/javascripts/materialize/range.js +40 -16
- data/assets/javascripts/materialize/scrollspy.js +9 -3
- data/assets/javascripts/materialize/select.js +62 -38
- data/assets/javascripts/materialize/sidenav.js +52 -18
- data/assets/javascripts/materialize/slider.js +56 -16
- data/assets/javascripts/materialize/tabs.js +35 -23
- data/assets/javascripts/materialize/timepicker.js +581 -579
- data/assets/javascripts/materialize/toasts.js +11 -7
- data/assets/javascripts/materialize/tooltip.js +16 -18
- data/assets/stylesheets/materialize.scss +3 -3
- data/assets/stylesheets/materialize/components/_buttons.scss +2 -2
- data/assets/stylesheets/materialize/components/_color-classes.scss +32 -0
- data/assets/stylesheets/materialize/components/{_color.scss → _color-variables.scss} +0 -42
- data/assets/stylesheets/materialize/components/_datepicker.scss +10 -4
- data/assets/stylesheets/materialize/components/_dropdown.scss +5 -0
- data/assets/stylesheets/materialize/components/_navbar.scss +3 -3
- data/assets/stylesheets/materialize/components/_pulse.scss +1 -1
- data/assets/stylesheets/materialize/components/_timepicker.scss +1 -0
- data/assets/stylesheets/materialize/components/_variables.scss +0 -1
- data/assets/stylesheets/materialize/components/forms/_input-fields.scss +6 -4
- data/assets/stylesheets/materialize/components/forms/_range.scss +3 -3
- data/assets/stylesheets/materialize/components/forms/_select.scss +7 -7
- data/assets/stylesheets/materialize/extras/nouislider.css +1 -1
- data/lib/materialize-sass/engine.rb +2 -0
- data/lib/materialize-sass/helpers.rb +38 -0
- data/lib/materialize-sass/version.rb +1 -1
- metadata +6 -5
- data/assets/javascripts/materialize/velocity.min.js +0 -782
- data/assets/stylesheets/materialize/components/_mixins.scss +0 -5
@@ -2,7 +2,7 @@ var _createClass = function () { function defineProperties(target, props) { for
|
|
2
2
|
|
3
3
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
4
4
|
|
5
|
-
(function ($,
|
5
|
+
(function ($, anim) {
|
6
6
|
'use strict';
|
7
7
|
|
8
8
|
var _defaults = {
|
@@ -79,7 +79,12 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
79
79
|
this.$active.css('display', 'block');
|
80
80
|
} else {
|
81
81
|
this.$slides.first().addClass('active');
|
82
|
-
|
82
|
+
anim({
|
83
|
+
targets: this.$slides.first()[0],
|
84
|
+
opacity: 1,
|
85
|
+
duration: this.options.duration,
|
86
|
+
easing: 'easeOutQuad'
|
87
|
+
});
|
83
88
|
|
84
89
|
this.activeIndex = 0;
|
85
90
|
this.$active = this.$slides.eq(this.activeIndex);
|
@@ -92,7 +97,14 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
92
97
|
|
93
98
|
// Adjust height to current slide
|
94
99
|
this.$active.find('img').each(function (el) {
|
95
|
-
|
100
|
+
anim({
|
101
|
+
targets: _this.$active.find('.caption')[0],
|
102
|
+
opacity: 1,
|
103
|
+
translateX: 0,
|
104
|
+
translateY: 0,
|
105
|
+
duration: _this.options.duration,
|
106
|
+
easing: 'easeOutQuad'
|
107
|
+
});
|
96
108
|
});
|
97
109
|
|
98
110
|
this._setupEventHandlers();
|
@@ -185,19 +197,22 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
185
197
|
}, {
|
186
198
|
key: '_animateCaptionIn',
|
187
199
|
value: function _animateCaptionIn(caption, duration) {
|
188
|
-
var
|
189
|
-
|
200
|
+
var animOptions = {
|
201
|
+
targets: caption,
|
202
|
+
opacity: 0,
|
203
|
+
duration: duration,
|
204
|
+
easing: 'easeOutQuad'
|
190
205
|
};
|
191
206
|
|
192
207
|
if ($(caption).hasClass('center-align')) {
|
193
|
-
|
208
|
+
animOptions.translateY = -100;
|
194
209
|
} else if ($(caption).hasClass('right-align')) {
|
195
|
-
|
210
|
+
animOptions.translateX = 100;
|
196
211
|
} else if ($(caption).hasClass('left-align')) {
|
197
|
-
|
212
|
+
animOptions.translateX = -100;
|
198
213
|
}
|
199
214
|
|
200
|
-
|
215
|
+
anim(animOptions);
|
201
216
|
}
|
202
217
|
|
203
218
|
/**
|
@@ -266,14 +281,25 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
266
281
|
if (this.activeIndex != index) {
|
267
282
|
this.$active = this.$slides.eq(this.activeIndex);
|
268
283
|
var $caption = this.$active.find('.caption');
|
269
|
-
|
270
284
|
this.$active.removeClass('active');
|
271
|
-
|
285
|
+
|
286
|
+
anim({
|
287
|
+
targets: this.$active[0],
|
288
|
+
opacity: 0,
|
289
|
+
duration: this.options.duration,
|
290
|
+
easing: 'easeOutQuad',
|
272
291
|
complete: function () {
|
273
292
|
_this5.$slides.not('.active').each(function (el) {
|
274
|
-
|
293
|
+
anim({
|
294
|
+
targets: el,
|
295
|
+
opacity: 0,
|
296
|
+
translateX: 0,
|
297
|
+
translateY: 0,
|
298
|
+
duration: 0,
|
299
|
+
easing: 'easeOutQuad'
|
300
|
+
});
|
275
301
|
});
|
276
|
-
}
|
302
|
+
}
|
277
303
|
});
|
278
304
|
|
279
305
|
this._animateCaptionIn($caption[0], this.options.duration);
|
@@ -284,8 +310,22 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
284
310
|
this.$indicators.eq(index).addClass('active');
|
285
311
|
}
|
286
312
|
|
287
|
-
|
288
|
-
|
313
|
+
anim({
|
314
|
+
targets: this.$slides.eq(index)[0],
|
315
|
+
opacity: 1,
|
316
|
+
duration: this.options.duration,
|
317
|
+
easing: 'easeOutQuad'
|
318
|
+
});
|
319
|
+
|
320
|
+
anim({
|
321
|
+
targets: this.$slides.eq(index).find('.caption')[0],
|
322
|
+
opacity: 1,
|
323
|
+
translateX: 0,
|
324
|
+
translateY: 0,
|
325
|
+
duration: this.options.duration,
|
326
|
+
delay: this.options.duration,
|
327
|
+
easing: 'easeOutQuad'
|
328
|
+
});
|
289
329
|
|
290
330
|
this.$slides.eq(index).addClass('active');
|
291
331
|
this.activeIndex = index;
|
@@ -380,4 +420,4 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
380
420
|
if (M.jQueryLoaded) {
|
381
421
|
M.initializeJqueryWrapper(Slider, 'slider', 'M_Slider');
|
382
422
|
}
|
383
|
-
})(cash, M.
|
423
|
+
})(cash, M.anime);
|
@@ -2,7 +2,7 @@ var _createClass = function () { function defineProperties(target, props) { for
|
|
2
2
|
|
3
3
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
4
4
|
|
5
|
-
(function ($,
|
5
|
+
(function ($, anim) {
|
6
6
|
'use strict';
|
7
7
|
|
8
8
|
var _defaults = {
|
@@ -41,7 +41,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
41
41
|
this.el = el;
|
42
42
|
|
43
43
|
/**
|
44
|
-
* Options for the
|
44
|
+
* Options for the Tabs
|
45
45
|
* @member Tabs#options
|
46
46
|
* @prop {Number} duration
|
47
47
|
* @prop {Function} onShow
|
@@ -182,14 +182,14 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
182
182
|
});
|
183
183
|
}
|
184
184
|
} else {
|
185
|
-
if (this.$content
|
185
|
+
if (this.$content.length) {
|
186
186
|
this.$content[0].style.display = 'block';
|
187
187
|
this.$content.addClass('active');
|
188
188
|
if (typeof this.options.onShow === 'function') {
|
189
189
|
this.options.onShow.call(this, this.$content[0]);
|
190
190
|
}
|
191
191
|
|
192
|
-
if ($oldContent
|
192
|
+
if ($oldContent.length && !$oldContent.is(this.$content)) {
|
193
193
|
$oldContent[0].style.display = 'none';
|
194
194
|
$oldContent.removeClass('active');
|
195
195
|
}
|
@@ -263,7 +263,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
263
263
|
var _this3 = this;
|
264
264
|
|
265
265
|
// Change swipeable according to responsive threshold
|
266
|
-
if (window.innerWidth > options.responsiveThreshold) {
|
266
|
+
if (window.innerWidth > this.options.responsiveThreshold) {
|
267
267
|
this.options.swipeable = false;
|
268
268
|
}
|
269
269
|
|
@@ -290,7 +290,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
290
290
|
_this3.$activeTabLink.addClass('active');
|
291
291
|
_this3._animateIndicator(prevIndex);
|
292
292
|
if (typeof _this3.options.onShow === "function") {
|
293
|
-
_this3.options.onShow.call(_this3, _this3.$content);
|
293
|
+
_this3.options.onShow.call(_this3, _this3.$content[0]);
|
294
294
|
}
|
295
295
|
}
|
296
296
|
});
|
@@ -360,7 +360,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
360
360
|
|
361
361
|
/**
|
362
362
|
* Finds right attribute for indicator based on active tab.
|
363
|
-
* @param {
|
363
|
+
* @param {cash} el
|
364
364
|
*/
|
365
365
|
|
366
366
|
}, {
|
@@ -371,7 +371,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
371
371
|
|
372
372
|
/**
|
373
373
|
* Finds left attribute for indicator based on active tab.
|
374
|
-
* @param {
|
374
|
+
* @param {cash} el
|
375
375
|
*/
|
376
376
|
|
377
377
|
}, {
|
@@ -379,6 +379,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
379
379
|
value: function _calcLeftPos(el) {
|
380
380
|
return Math.floor(el.position().left);
|
381
381
|
}
|
382
|
+
}, {
|
383
|
+
key: 'updateTabIndicator',
|
384
|
+
value: function updateTabIndicator() {
|
385
|
+
this._animateIndicator(this.index);
|
386
|
+
}
|
382
387
|
|
383
388
|
/**
|
384
389
|
* Animates Indicator to active tab.
|
@@ -388,25 +393,31 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
388
393
|
}, {
|
389
394
|
key: '_animateIndicator',
|
390
395
|
value: function _animateIndicator(prevIndex) {
|
391
|
-
var
|
392
|
-
|
393
|
-
queue: false,
|
394
|
-
easing: 'easeOutQuad'
|
395
|
-
};
|
396
|
-
var velOptionsLeft = void 0,
|
397
|
-
velOptionsRight = void 0;
|
396
|
+
var leftDelay = 0,
|
397
|
+
rightDelay = 0;
|
398
398
|
|
399
399
|
if (this.index - prevIndex >= 0) {
|
400
|
-
|
401
|
-
velOptionsRight = velOptions;
|
400
|
+
leftDelay = 90;
|
402
401
|
} else {
|
403
|
-
|
404
|
-
velOptionsRight = $.extend({}, velOptions, { delay: 90 });
|
402
|
+
rightDelay = 90;
|
405
403
|
}
|
406
404
|
|
407
|
-
// Animate
|
408
|
-
|
409
|
-
|
405
|
+
// Animate
|
406
|
+
var animOptions = {
|
407
|
+
targets: this._indicator,
|
408
|
+
left: {
|
409
|
+
value: this._calcLeftPos(this.$activeTabLink),
|
410
|
+
delay: leftDelay
|
411
|
+
},
|
412
|
+
right: {
|
413
|
+
value: this._calcRightPos(this.$activeTabLink),
|
414
|
+
delay: rightDelay
|
415
|
+
},
|
416
|
+
duration: this.options.duration,
|
417
|
+
easing: 'easeOutQuad'
|
418
|
+
};
|
419
|
+
anim.remove(this._indicator);
|
420
|
+
anim(animOptions);
|
410
421
|
}
|
411
422
|
|
412
423
|
/**
|
@@ -419,6 +430,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
419
430
|
value: function select(tabId) {
|
420
431
|
var tab = this.$tabLinks.filter('[href="#' + tabId + '"]');
|
421
432
|
if (tab.length) {
|
433
|
+
4;
|
422
434
|
tab.trigger('click');
|
423
435
|
}
|
424
436
|
}
|
@@ -457,4 +469,4 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
457
469
|
if (M.jQueryLoaded) {
|
458
470
|
M.initializeJqueryWrapper(Tabs, 'tabs', 'M_Tabs');
|
459
471
|
}
|
460
|
-
})(cash, M.
|
472
|
+
})(cash, M.anime);
|
@@ -2,615 +2,617 @@ var _createClass = function () { function defineProperties(target, props) { for
|
|
2
2
|
|
3
3
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
4
4
|
|
5
|
-
(function (
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
5
|
+
(function ($) {
|
6
|
+
'use strict';
|
7
|
+
|
8
|
+
var _defaults = {
|
9
|
+
dialRadius: 135,
|
10
|
+
outerRadius: 105,
|
11
|
+
innerRadius: 70,
|
12
|
+
tickRadius: 20,
|
13
|
+
duration: 350,
|
14
|
+
container: null,
|
15
|
+
defaultTime: 'now', // default time, 'now' or '13:14' e.g.
|
16
|
+
fromnow: 0, // Millisecond offset from the defaultTime
|
17
|
+
doneText: 'Ok', // done button text
|
18
|
+
clearText: 'Clear',
|
19
|
+
cancelText: 'Cancel',
|
20
|
+
autoClose: false, // auto close when minute is selected
|
21
|
+
twelveHour: true, // change to 12 hour AM/PM clock from 24 hour
|
22
|
+
vibrate: true // vibrate the device when dragging clock hand
|
23
|
+
};
|
24
|
+
|
25
|
+
/**
|
26
26
|
* @class
|
27
27
|
*
|
28
28
|
*/
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
var Timepicker = function () {
|
31
|
+
function Timepicker(el, options) {
|
32
|
+
_classCallCheck(this, Timepicker);
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
// If exists, destroy and reinitialize
|
35
|
+
if (!!el.M_Timepicker) {
|
36
|
+
el.M_Timepicker.destroy();
|
37
|
+
}
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
this.el = el;
|
40
|
+
this.$el = $(el);
|
41
|
+
this.el.M_Timepicker = this;
|
42
42
|
|
43
|
-
|
43
|
+
this.options = $.extend({}, Timepicker.defaults, options);
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
this.id = M.guid();
|
46
|
+
this._insertHTMLIntoDOM();
|
47
|
+
this._setupModal();
|
48
|
+
this._setupVariables();
|
49
|
+
this._setupEventHandlers();
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
this._clockSetup();
|
52
|
+
this._pickerSetup();
|
53
|
+
}
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
_createClass(Timepicker, [{
|
56
|
+
key: 'destroy',
|
57
57
|
|
58
58
|
|
59
|
-
|
59
|
+
/**
|
60
60
|
* Teardown component
|
61
61
|
*/
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
62
|
+
value: function destroy() {
|
63
|
+
this._removeEventHandlers();
|
64
|
+
this.modal.destroy();
|
65
|
+
$(this.modalEl).remove();
|
66
|
+
this.el.M_Timepicker = undefined;
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
70
|
* Setup Event Handlers
|
71
71
|
*/
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
73
|
+
}, {
|
74
|
+
key: '_setupEventHandlers',
|
75
|
+
value: function _setupEventHandlers() {
|
76
|
+
this._handleInputKeydownBound = this._handleInputKeydown.bind(this);
|
77
|
+
this._handleInputClickBound = this._handleInputClick.bind(this);
|
78
|
+
this._handleClockClickStartBound = this._handleClockClickStart.bind(this);
|
79
|
+
this._handleDocumentClickMoveBound = this._handleDocumentClickMove.bind(this);
|
80
|
+
this._handleDocumentClickEndBound = this._handleDocumentClickEnd.bind(this);
|
81
|
+
|
82
|
+
this.el.addEventListener('click', this._handleInputClickBound);
|
83
|
+
this.el.addEventListener('keydown', this._handleInputKeydownBound);
|
84
|
+
this.plate.addEventListener('mousedown', this._handleClockClickStartBound);
|
85
|
+
this.plate.addEventListener('touchstart', this._handleClockClickStartBound);
|
86
|
+
|
87
|
+
$(this.spanHours).on('click', this.showView.bind(this, 'hours'));
|
88
|
+
$(this.spanMinutes).on('click', this.showView.bind(this, 'minutes'));
|
89
|
+
}
|
90
|
+
}, {
|
91
|
+
key: '_removeEventHandlers',
|
92
|
+
value: function _removeEventHandlers() {
|
93
|
+
this.el.removeEventListener('click', this._handleInputClickBound);
|
94
|
+
this.el.removeEventListener('keydown', this._handleInputKeydownBound);
|
95
|
+
}
|
96
|
+
}, {
|
97
|
+
key: '_handleInputClick',
|
98
|
+
value: function _handleInputClick() {
|
99
|
+
this.open();
|
100
|
+
}
|
101
|
+
}, {
|
102
|
+
key: '_handleInputKeydown',
|
103
|
+
value: function _handleInputKeydown(e) {
|
104
|
+
if (e.which === M.keys.ENTER) {
|
105
|
+
e.preventDefault();
|
106
|
+
this.open();
|
107
|
+
}
|
108
|
+
}
|
109
|
+
}, {
|
110
|
+
key: '_handleClockClickStart',
|
111
|
+
value: function _handleClockClickStart(e) {
|
112
|
+
e.preventDefault();
|
113
|
+
var clockPlateBR = this.plate.getBoundingClientRect();
|
114
|
+
var offset = { x: clockPlateBR.left, y: clockPlateBR.top };
|
115
|
+
|
116
|
+
this.x0 = offset.x + this.options.dialRadius;
|
117
|
+
this.y0 = offset.y + this.options.dialRadius;
|
118
|
+
this.moved = false;
|
119
|
+
var clickPos = Timepicker._Pos(e);
|
120
|
+
this.dx = clickPos.x - this.x0;
|
121
|
+
this.dy = clickPos.y - this.y0;
|
122
|
+
|
123
|
+
// Set clock hands
|
124
|
+
this.setHand(this.dx, this.dy, false);
|
125
|
+
|
126
|
+
// Mousemove on document
|
127
|
+
document.addEventListener('mousemove', this._handleDocumentClickMoveBound);
|
128
|
+
document.addEventListener('touchmove', this._handleDocumentClickMoveBound);
|
129
|
+
|
130
|
+
// Mouseup on document
|
131
|
+
document.addEventListener('mouseup', this._handleDocumentClickEndBound);
|
132
|
+
document.addEventListener('touchend', this._handleDocumentClickEndBound);
|
133
|
+
}
|
134
|
+
}, {
|
135
|
+
key: '_handleDocumentClickMove',
|
136
|
+
value: function _handleDocumentClickMove(e) {
|
137
|
+
e.preventDefault();
|
138
|
+
var clickPos = Timepicker._Pos(e);
|
139
|
+
var x = clickPos.x - this.x0;
|
140
|
+
var y = clickPos.y - this.y0;
|
141
|
+
this.moved = true;
|
142
|
+
this.setHand(x, y, false, true);
|
143
|
+
}
|
144
|
+
}, {
|
145
|
+
key: '_handleDocumentClickEnd',
|
146
|
+
value: function _handleDocumentClickEnd(e) {
|
147
|
+
e.preventDefault();
|
148
|
+
document.removeEventListener('mouseup', this._handleDocumentClickEndBound);
|
149
|
+
document.removeEventListener('touchend', this._handleDocumentClickEndBound);
|
150
|
+
var clickPos = Timepicker._Pos(e);
|
151
|
+
var x = clickPos.x - this.x0;
|
152
|
+
var y = clickPos.y - this.y0;
|
153
|
+
if (this.moved && x === this.dx && y === this.dy) {
|
154
|
+
this.setHand(x, y);
|
155
|
+
}
|
156
|
+
|
157
|
+
if (this.currentView === 'hours') {
|
158
|
+
this.showView('minutes', this.options.duration / 2);
|
159
|
+
} else if (this.options.autoClose) {
|
160
|
+
this.minutesView.addClass('timepicker-dial-out');
|
161
|
+
setTimeout(function () {
|
162
|
+
this.done();
|
163
|
+
}, this.options.duration / 2);
|
164
|
+
}
|
165
|
+
|
166
|
+
// Unbind mousemove event
|
167
|
+
document.removeEventListener('mousemove', this._handleDocumentClickMoveBound);
|
168
|
+
document.removeEventListener('touchmove', this._handleDocumentClickMoveBound);
|
169
|
+
}
|
170
|
+
}, {
|
171
|
+
key: '_insertHTMLIntoDOM',
|
172
|
+
value: function _insertHTMLIntoDOM() {
|
173
|
+
this.$modalEl = $(Timepicker._template);
|
174
|
+
this.modalEl = this.$modalEl[0];
|
175
|
+
this.modalEl.id = 'modal-' + this.id;
|
176
|
+
|
177
|
+
// Append popover to input by default
|
178
|
+
var containerEl = document.querySelector(this.options.container);
|
179
|
+
if (this.options.container && !!containerEl) {
|
180
|
+
this.$modalEl.appendTo(containerEl);
|
181
|
+
} else {
|
182
|
+
this.$modalEl.insertBefore(this.el);
|
183
|
+
}
|
184
|
+
}
|
185
|
+
}, {
|
186
|
+
key: '_setupModal',
|
187
|
+
value: function _setupModal() {
|
188
|
+
var _this = this;
|
189
|
+
|
190
|
+
this.modal = new M.Modal(this.modalEl, {
|
191
|
+
complete: function () {
|
192
|
+
_this.isOpen = false;
|
193
|
+
}
|
194
|
+
});
|
195
|
+
}
|
196
|
+
}, {
|
197
|
+
key: '_setupVariables',
|
198
|
+
value: function _setupVariables() {
|
199
|
+
this.currentView = 'hours';
|
200
|
+
this.vibrate = navigator.vibrate ? 'vibrate' : navigator.webkitVibrate ? 'webkitVibrate' : null;
|
201
|
+
|
202
|
+
this._canvas = this.modalEl.querySelector('.timepicker-canvas');
|
203
|
+
this.plate = this.modalEl.querySelector('.timepicker-plate');
|
204
|
+
|
205
|
+
this.hoursView = this.modalEl.querySelector('.timepicker-hours');
|
206
|
+
this.minutesView = this.modalEl.querySelector('.timepicker-minutes');
|
207
|
+
this.spanHours = this.modalEl.querySelector('.timepicker-span-hours');
|
208
|
+
this.spanMinutes = this.modalEl.querySelector('.timepicker-span-minutes');
|
209
|
+
this.spanAmPm = this.modalEl.querySelector('.timepicker-span-am-pm');
|
210
|
+
this.footer = this.modalEl.querySelector('.timepicker-footer');
|
211
|
+
this.amOrPm = 'PM';
|
212
|
+
}
|
213
|
+
}, {
|
214
|
+
key: '_pickerSetup',
|
215
|
+
value: function _pickerSetup() {
|
216
|
+
$('<button class="btn-flat timepicker-clear waves-effect" type="button" tabindex="' + (this.options.twelveHour ? '3' : '1') + '">' + this.options.clearText + '</button>').appendTo(this.footer).on('click', this.clear.bind(this));
|
217
|
+
|
218
|
+
var confirmationBtnsContainer = $('<div class="confirmation-btns"></div>');
|
219
|
+
$('<button class="btn-flat timepicker-close waves-effect" type="button" tabindex="' + (this.options.twelveHour ? '3' : '1') + '">' + this.options.cancelText + '</button>').appendTo(confirmationBtnsContainer).on('click', this.close.bind(this));
|
220
|
+
$('<button class="btn-flat timepicker-close waves-effect" type="button" tabindex="' + (this.options.twelveHour ? '3' : '1') + '">' + this.options.doneText + '</button>').appendTo(confirmationBtnsContainer).on('click', this.done.bind(this));
|
221
|
+
confirmationBtnsContainer.appendTo(this.footer);
|
222
|
+
}
|
223
|
+
}, {
|
224
|
+
key: '_clockSetup',
|
225
|
+
value: function _clockSetup() {
|
226
|
+
if (this.options.twelveHour) {
|
227
|
+
this.$amBtn = $('<div class="am-btn">AM</div>');
|
228
|
+
this.$pmBtn = $('<div class="pm-btn">PM</div>');
|
229
|
+
this.$amBtn.on('click', this._handleAmPmClick.bind(this)).appendTo(this.spanAmPm);
|
230
|
+
this.$pmBtn.on('click', this._handleAmPmClick.bind(this)).appendTo(this.spanAmPm);
|
231
|
+
}
|
232
|
+
|
233
|
+
this._buildHoursView();
|
234
|
+
this._buildMinutesView();
|
235
|
+
this._buildSVGClock();
|
236
|
+
}
|
237
|
+
}, {
|
238
|
+
key: '_buildSVGClock',
|
239
|
+
value: function _buildSVGClock() {
|
240
|
+
// Draw clock hands and others
|
241
|
+
var dialRadius = this.options.dialRadius;
|
242
|
+
var tickRadius = this.options.tickRadius;
|
243
|
+
var diameter = dialRadius * 2;
|
244
|
+
|
245
|
+
var svg = Timepicker._createSVGEl('svg');
|
246
|
+
svg.setAttribute('class', 'timepicker-svg');
|
247
|
+
svg.setAttribute('width', diameter);
|
248
|
+
svg.setAttribute('height', diameter);
|
249
|
+
var g = Timepicker._createSVGEl('g');
|
250
|
+
g.setAttribute('transform', 'translate(' + dialRadius + ',' + dialRadius + ')');
|
251
|
+
var bearing = Timepicker._createSVGEl('circle');
|
252
|
+
bearing.setAttribute('class', 'timepicker-canvas-bearing');
|
253
|
+
bearing.setAttribute('cx', 0);
|
254
|
+
bearing.setAttribute('cy', 0);
|
255
|
+
bearing.setAttribute('r', 4);
|
256
|
+
var hand = Timepicker._createSVGEl('line');
|
257
|
+
hand.setAttribute('x1', 0);
|
258
|
+
hand.setAttribute('y1', 0);
|
259
|
+
var bg = Timepicker._createSVGEl('circle');
|
260
|
+
bg.setAttribute('class', 'timepicker-canvas-bg');
|
261
|
+
bg.setAttribute('r', tickRadius);
|
262
|
+
g.appendChild(hand);
|
263
|
+
g.appendChild(bg);
|
264
|
+
g.appendChild(bearing);
|
265
|
+
svg.appendChild(g);
|
266
|
+
this._canvas.appendChild(svg);
|
267
|
+
|
268
|
+
this.hand = hand;
|
269
|
+
this.bg = bg;
|
270
|
+
this.bearing = bearing;
|
271
|
+
this.g = g;
|
272
|
+
}
|
273
|
+
}, {
|
274
|
+
key: '_buildHoursView',
|
275
|
+
value: function _buildHoursView() {
|
276
|
+
var $tick = $('<div class="timepicker-tick"></div>');
|
277
|
+
// Hours view
|
278
|
+
if (this.options.twelveHour) {
|
279
|
+
for (var i = 1; i < 13; i += 1) {
|
280
|
+
var tick = $tick.clone();
|
281
|
+
var radian = i / 6 * Math.PI;
|
282
|
+
var radius = this.options.outerRadius;
|
283
|
+
tick.css({
|
284
|
+
left: this.options.dialRadius + Math.sin(radian) * radius - this.options.tickRadius + 'px',
|
285
|
+
top: this.options.dialRadius - Math.cos(radian) * radius - this.options.tickRadius + 'px'
|
286
|
+
});
|
287
|
+
tick.html(i === 0 ? '00' : i);
|
288
|
+
this.hoursView.appendChild(tick[0]);
|
289
|
+
// tick.on(mousedownEvent, mousedown);
|
290
|
+
}
|
291
|
+
} else {
|
292
|
+
for (var _i = 0; _i < 24; _i += 1) {
|
293
|
+
var _tick = $tick.clone();
|
294
|
+
var _radian = _i / 6 * Math.PI;
|
295
|
+
var inner = _i > 0 && _i < 13;
|
296
|
+
var _radius = inner ? this.options.innerRadius : this.options.outerRadius;
|
297
|
+
_tick.css({
|
298
|
+
left: this.options.dialRadius + Math.sin(_radian) * _radius - this.options.tickRadius + 'px',
|
299
|
+
top: this.options.dialRadius - Math.cos(_radian) * _radius - this.options.tickRadius + 'px'
|
300
|
+
});
|
301
|
+
_tick.html(_i === 0 ? '00' : _i);
|
302
|
+
this.hoursView.appendChild(_tick[0]);
|
303
|
+
// tick.on(mousedownEvent, mousedown);
|
304
|
+
}
|
305
|
+
}
|
306
|
+
}
|
307
|
+
}, {
|
308
|
+
key: '_buildMinutesView',
|
309
|
+
value: function _buildMinutesView() {
|
310
|
+
var $tick = $('<div class="timepicker-tick"></div>');
|
311
|
+
// Minutes view
|
312
|
+
for (var i = 0; i < 60; i += 5) {
|
313
|
+
var tick = $tick.clone();
|
314
|
+
var radian = i / 30 * Math.PI;
|
315
|
+
tick.css({
|
316
|
+
left: this.options.dialRadius + Math.sin(radian) * this.options.outerRadius - this.options.tickRadius + 'px',
|
317
|
+
top: this.options.dialRadius - Math.cos(radian) * this.options.outerRadius - this.options.tickRadius + 'px'
|
318
|
+
});
|
319
|
+
tick.html(Timepicker._addLeadingZero(i));
|
320
|
+
this.minutesView.appendChild(tick[0]);
|
321
|
+
}
|
322
|
+
}
|
323
|
+
}, {
|
324
|
+
key: '_handleAmPmClick',
|
325
|
+
value: function _handleAmPmClick(e) {
|
326
|
+
var $btnClicked = $(e.target);
|
327
|
+
this.amOrPm = $btnClicked.hasClass('am-btn') ? 'AM' : 'PM';
|
328
|
+
this._updateAmPmView();
|
329
|
+
}
|
330
|
+
}, {
|
331
|
+
key: '_updateAmPmView',
|
332
|
+
value: function _updateAmPmView() {
|
333
|
+
if (this.options.twelveHour) {
|
334
|
+
this.$amBtn.toggleClass('text-primary', this.amOrPm === 'AM');
|
335
|
+
this.$pmBtn.toggleClass('text-primary', this.amOrPm === 'PM');
|
336
|
+
}
|
337
|
+
}
|
338
|
+
}, {
|
339
|
+
key: '_updateTimeFromInput',
|
340
|
+
value: function _updateTimeFromInput() {
|
341
|
+
// Get the time
|
342
|
+
var value = ((this.el.value || this.options.defaultTime || '') + '').split(':');
|
343
|
+
if (this.options.twelveHour && !(typeof value[1] === 'undefined')) {
|
344
|
+
if (value[1].indexOf("AM") > 0) {
|
345
|
+
this.amOrPm = 'AM';
|
346
|
+
} else {
|
347
|
+
this.amOrPm = 'PM';
|
348
|
+
}
|
349
|
+
value[1] = value[1].replace("AM", "").replace("PM", "");
|
350
|
+
}
|
351
|
+
if (value[0] === 'now') {
|
352
|
+
var now = new Date(+new Date() + this.options.fromnow);
|
353
|
+
value = [now.getHours(), now.getMinutes()];
|
354
|
+
if (this.options.twelveHour) {
|
355
|
+
this.amOrPm = value[0] >= 12 && value[0] < 24 ? 'PM' : 'AM';
|
356
|
+
}
|
357
|
+
}
|
358
|
+
this.hours = +value[0] || 0;
|
359
|
+
this.minutes = +value[1] || 0;
|
360
|
+
this.spanHours.innerHTML = this.hours;
|
361
|
+
this.spanMinutes.innerHTML = Timepicker._addLeadingZero(this.minutes);
|
362
|
+
|
363
|
+
this._updateAmPmView();
|
364
|
+
}
|
365
|
+
}, {
|
366
|
+
key: 'showView',
|
367
|
+
value: function showView(view, delay) {
|
368
|
+
if (view === 'minutes' && $(this.hoursView).css("visibility") === "visible") {
|
369
|
+
// raiseCallback(this.options.beforeHourSelect);
|
370
|
+
}
|
371
|
+
var isHours = view === 'hours',
|
372
|
+
nextView = isHours ? this.hoursView : this.minutesView,
|
373
|
+
hideView = isHours ? this.minutesView : this.hoursView;
|
374
|
+
this.currentView = view;
|
375
|
+
|
376
|
+
$(this.spanHours).toggleClass('text-primary', isHours);
|
377
|
+
$(this.spanMinutes).toggleClass('text-primary', !isHours);
|
378
|
+
|
379
|
+
// Transition view
|
380
|
+
hideView.classList.add('timepicker-dial-out');
|
381
|
+
$(nextView).css('visibility', 'visible').removeClass('timepicker-dial-out');
|
382
|
+
|
383
|
+
// Reset clock hand
|
384
|
+
this.resetClock(delay);
|
385
|
+
|
386
|
+
// After transitions ended
|
387
|
+
clearTimeout(this.toggleViewTimer);
|
388
|
+
this.toggleViewTimer = setTimeout(function () {
|
389
|
+
$(hideView).css('visibility', 'hidden');
|
390
|
+
}, this.options.duration);
|
391
|
+
}
|
392
|
+
}, {
|
393
|
+
key: 'resetClock',
|
394
|
+
value: function resetClock(delay) {
|
395
|
+
var view = this.currentView,
|
396
|
+
value = this[view],
|
397
|
+
isHours = view === 'hours',
|
398
|
+
unit = Math.PI / (isHours ? 6 : 30),
|
399
|
+
radian = value * unit,
|
400
|
+
radius = isHours && value > 0 && value < 13 ? this.options.innerRadius : this.options.outerRadius,
|
401
|
+
x = Math.sin(radian) * radius,
|
402
|
+
y = -Math.cos(radian) * radius,
|
403
|
+
self = this;
|
404
|
+
|
405
|
+
if (delay) {
|
406
|
+
$(this.canvas).addClass('timepicker-canvas-out');
|
407
|
+
setTimeout(function () {
|
408
|
+
$(self.canvas).removeClass('timepicker-canvas-out');
|
409
|
+
self.setHand(x, y);
|
410
|
+
}, delay);
|
411
|
+
} else {
|
412
|
+
this.setHand(x, y);
|
413
|
+
}
|
414
|
+
}
|
415
|
+
}, {
|
416
|
+
key: 'setHand',
|
417
|
+
value: function setHand(x, y, roundBy5) {
|
418
|
+
var _this2 = this;
|
419
|
+
|
420
|
+
var radian = Math.atan2(x, -y),
|
421
|
+
isHours = this.currentView === 'hours',
|
422
|
+
unit = Math.PI / (isHours || roundBy5 ? 6 : 30),
|
423
|
+
z = Math.sqrt(x * x + y * y),
|
424
|
+
inner = isHours && z < (this.options.outerRadius + this.options.innerRadius) / 2,
|
425
|
+
radius = inner ? this.options.innerRadius : this.options.outerRadius;
|
426
|
+
|
427
|
+
if (this.options.twelveHour) {
|
428
|
+
radius = this.options.outerRadius;
|
429
|
+
}
|
430
|
+
|
431
|
+
// Radian should in range [0, 2PI]
|
432
|
+
if (radian < 0) {
|
433
|
+
radian = Math.PI * 2 + radian;
|
434
|
+
}
|
435
|
+
|
436
|
+
// Get the round value
|
437
|
+
var value = Math.round(radian / unit);
|
438
|
+
|
439
|
+
// Get the round radian
|
440
|
+
radian = value * unit;
|
441
|
+
|
442
|
+
// Correct the hours or minutes
|
443
|
+
if (this.options.twelveHour) {
|
444
|
+
if (isHours) {
|
445
|
+
if (value === 0) value = 12;
|
446
|
+
} else {
|
447
|
+
if (roundBy5) value *= 5;
|
448
|
+
if (value === 60) value = 0;
|
449
|
+
}
|
450
|
+
} else {
|
451
|
+
if (isHours) {
|
452
|
+
if (value === 12) {
|
453
|
+
value = 0;
|
454
|
+
}
|
455
|
+
value = inner ? value === 0 ? 12 : value : value === 0 ? 0 : value + 12;
|
456
|
+
} else {
|
457
|
+
if (roundBy5) {
|
458
|
+
value *= 5;
|
459
|
+
}
|
460
|
+
if (value === 60) {
|
461
|
+
value = 0;
|
462
|
+
}
|
463
|
+
}
|
464
|
+
}
|
465
|
+
|
466
|
+
// Once hours or minutes changed, vibrate the device
|
467
|
+
if (this[this.currentView] !== value) {
|
468
|
+
if (this.vibrate && this.options.vibrate) {
|
469
|
+
// Do not vibrate too frequently
|
470
|
+
if (!this.vibrateTimer) {
|
471
|
+
navigator[this.vibrate](10);
|
472
|
+
this.vibrateTimer = setTimeout(function () {
|
473
|
+
_this2.vibrateTimer = null;
|
474
|
+
}, 100);
|
475
|
+
}
|
476
|
+
}
|
477
|
+
}
|
478
|
+
|
479
|
+
this[this.currentView] = value;
|
480
|
+
if (isHours) {
|
481
|
+
this['spanHours'].innerHTML = value;
|
482
|
+
} else {
|
483
|
+
this['spanMinutes'].innerHTML = Timepicker._addLeadingZero(value);
|
484
|
+
}
|
485
|
+
|
486
|
+
// Set clock hand and others' position
|
487
|
+
var cx1 = Math.sin(radian) * (radius - this.options.tickRadius),
|
488
|
+
cy1 = -Math.cos(radian) * (radius - this.options.tickRadius),
|
489
|
+
cx2 = Math.sin(radian) * radius,
|
490
|
+
cy2 = -Math.cos(radian) * radius;
|
491
|
+
this.hand.setAttribute('x2', cx1);
|
492
|
+
this.hand.setAttribute('y2', cy1);
|
493
|
+
this.bg.setAttribute('cx', cx2);
|
494
|
+
this.bg.setAttribute('cy', cy2);
|
495
|
+
}
|
496
|
+
}, {
|
497
|
+
key: 'open',
|
498
|
+
value: function open() {
|
499
|
+
if (this.isOpen) {
|
500
|
+
return;
|
501
|
+
}
|
502
|
+
|
503
|
+
this.isOpen = true;
|
504
|
+
this._updateTimeFromInput();
|
505
|
+
this.showView('hours');
|
506
|
+
this.modal.open();
|
507
|
+
}
|
508
|
+
}, {
|
509
|
+
key: 'close',
|
510
|
+
value: function close() {
|
511
|
+
if (!this.isOpen) {
|
512
|
+
return;
|
513
|
+
}
|
514
|
+
|
515
|
+
this.isOpen = false;
|
516
|
+
this.modal.close();
|
517
|
+
}
|
518
|
+
|
519
|
+
/**
|
518
520
|
* Finish timepicker selection.
|
519
521
|
*/
|
520
522
|
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
523
|
+
}, {
|
524
|
+
key: 'done',
|
525
|
+
value: function done(e, clearValue) {
|
526
|
+
// Set input value
|
527
|
+
var last = this.el.value;
|
528
|
+
var value = clearValue ? '' : Timepicker._addLeadingZero(this.hours) + ':' + Timepicker._addLeadingZero(this.minutes);
|
529
|
+
this.time = value;
|
530
|
+
if (!clearValue && this.options.twelveHour) {
|
531
|
+
value = value + ' ' + this.amOrPm;
|
532
|
+
}
|
533
|
+
this.el.value = value;
|
534
|
+
|
535
|
+
// Trigger change event
|
536
|
+
if (value !== last) {
|
537
|
+
this.$el.trigger('change');
|
538
|
+
}
|
539
|
+
|
540
|
+
this.close();
|
541
|
+
this.el.focus();
|
542
|
+
}
|
543
|
+
}, {
|
544
|
+
key: 'clear',
|
545
|
+
value: function clear() {
|
546
|
+
this.done(null, true);
|
547
|
+
}
|
548
|
+
}], [{
|
549
|
+
key: 'init',
|
550
|
+
value: function init($els, options) {
|
551
|
+
var arr = [];
|
552
|
+
$els.each(function () {
|
553
|
+
arr.push(new Timepicker(this, options));
|
554
|
+
});
|
555
|
+
return arr;
|
556
|
+
}
|
557
|
+
}, {
|
558
|
+
key: '_addLeadingZero',
|
559
|
+
value: function _addLeadingZero(num) {
|
560
|
+
return (num < 10 ? '0' : '') + num;
|
561
|
+
}
|
562
|
+
}, {
|
563
|
+
key: '_createSVGEl',
|
564
|
+
value: function _createSVGEl(name) {
|
565
|
+
var svgNS = 'http://www.w3.org/2000/svg';
|
566
|
+
return document.createElementNS(svgNS, name);
|
567
|
+
}
|
568
|
+
|
569
|
+
/**
|
568
570
|
* @typedef {Object} Point
|
569
571
|
* @property {number} x The X Coordinate
|
570
572
|
* @property {number} y The Y Coordinate
|
571
573
|
*/
|
572
574
|
|
573
|
-
|
575
|
+
/**
|
574
576
|
* Get x position of mouse or touch event
|
575
577
|
* @param {Event} e
|
576
578
|
* @return {Point} x and y location
|
577
579
|
*/
|
578
580
|
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
581
|
+
}, {
|
582
|
+
key: '_Pos',
|
583
|
+
value: function _Pos(e) {
|
584
|
+
if (e.targetTouches && e.targetTouches.length >= 1) {
|
585
|
+
return { x: e.targetTouches[0].clientX, y: e.targetTouches[0].clientY };
|
586
|
+
}
|
587
|
+
// mouse event
|
588
|
+
return { x: e.clientX, y: e.clientY };
|
589
|
+
}
|
590
|
+
|
591
|
+
/**
|
590
592
|
* Get Instance
|
591
593
|
*/
|
592
594
|
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
})(cash
|
595
|
+
}, {
|
596
|
+
key: 'getInstance',
|
597
|
+
value: function getInstance(el) {
|
598
|
+
var domElem = !!el.jquery ? el[0] : el;
|
599
|
+
return domElem.M_Timepicker;
|
600
|
+
}
|
601
|
+
}, {
|
602
|
+
key: 'defaults',
|
603
|
+
get: function () {
|
604
|
+
return _defaults;
|
605
|
+
}
|
606
|
+
}]);
|
607
|
+
|
608
|
+
return Timepicker;
|
609
|
+
}();
|
610
|
+
|
611
|
+
Timepicker._template = ['<div class= "modal timepicker-modal">', '<div class="modal-content timepicker-container">', '<div class="timepicker-digital-display">', '<div class="timepicker-text-container">', '<div class="timepicker-display-column">', '<span class="timepicker-span-hours text-primary"></span>', ':', '<span class="timepicker-span-minutes"></span>', '</div>', '<div class="timepicker-display-column timepicker-display-am-pm">', '<div class="timepicker-span-am-pm"></div>', '</div>', '</div>', '</div>', '<div class="timepicker-analog-display">', '<div class="timepicker-plate">', '<div class="timepicker-canvas"></div>', '<div class="timepicker-dial timepicker-hours"></div>', '<div class="timepicker-dial timepicker-minutes timepicker-dial-out"></div>', '</div>', '<div class="timepicker-footer"></div>', '</div>', '</div>', '</div>'].join('');
|
612
|
+
|
613
|
+
M.Timepicker = Timepicker;
|
614
|
+
|
615
|
+
if (M.jQueryLoaded) {
|
616
|
+
M.initializeJqueryWrapper(Timepicker, 'timepicker', 'M_Timepicker');
|
617
|
+
}
|
618
|
+
})(cash);
|