materialize-sass 1.0.0.alpha1 → 1.0.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/assets/javascripts/materialize-sprockets.js +1 -1
  3. data/assets/javascripts/materialize.js +1162 -1218
  4. data/assets/javascripts/materialize/anime.min.js +417 -0
  5. data/assets/javascripts/materialize/buttons.js +49 -26
  6. data/assets/javascripts/materialize/cards.js +14 -8
  7. data/assets/javascripts/materialize/cash.js +3 -5
  8. data/assets/javascripts/materialize/chips.js +22 -19
  9. data/assets/javascripts/materialize/collapsible.js +53 -17
  10. data/assets/javascripts/materialize/datepicker.js +94 -78
  11. data/assets/javascripts/materialize/dropdown.js +33 -26
  12. data/assets/javascripts/materialize/extras/nouislider.js +1 -1
  13. data/assets/javascripts/materialize/extras/nouislider.min.js +1 -1
  14. data/assets/javascripts/materialize/forms.js +17 -6
  15. data/assets/javascripts/materialize/global.js +17 -15
  16. data/assets/javascripts/materialize/materialbox.js +62 -35
  17. data/assets/javascripts/materialize/modal.js +50 -19
  18. data/assets/javascripts/materialize/range.js +40 -16
  19. data/assets/javascripts/materialize/scrollspy.js +9 -3
  20. data/assets/javascripts/materialize/select.js +62 -38
  21. data/assets/javascripts/materialize/sidenav.js +52 -18
  22. data/assets/javascripts/materialize/slider.js +56 -16
  23. data/assets/javascripts/materialize/tabs.js +35 -23
  24. data/assets/javascripts/materialize/timepicker.js +581 -579
  25. data/assets/javascripts/materialize/toasts.js +11 -7
  26. data/assets/javascripts/materialize/tooltip.js +16 -18
  27. data/assets/stylesheets/materialize.scss +3 -3
  28. data/assets/stylesheets/materialize/components/_buttons.scss +2 -2
  29. data/assets/stylesheets/materialize/components/_color-classes.scss +32 -0
  30. data/assets/stylesheets/materialize/components/{_color.scss → _color-variables.scss} +0 -42
  31. data/assets/stylesheets/materialize/components/_datepicker.scss +10 -4
  32. data/assets/stylesheets/materialize/components/_dropdown.scss +5 -0
  33. data/assets/stylesheets/materialize/components/_navbar.scss +3 -3
  34. data/assets/stylesheets/materialize/components/_pulse.scss +1 -1
  35. data/assets/stylesheets/materialize/components/_timepicker.scss +1 -0
  36. data/assets/stylesheets/materialize/components/_variables.scss +0 -1
  37. data/assets/stylesheets/materialize/components/forms/_input-fields.scss +6 -4
  38. data/assets/stylesheets/materialize/components/forms/_range.scss +3 -3
  39. data/assets/stylesheets/materialize/components/forms/_select.scss +7 -7
  40. data/assets/stylesheets/materialize/extras/nouislider.css +1 -1
  41. data/lib/materialize-sass/engine.rb +2 -0
  42. data/lib/materialize-sass/helpers.rb +38 -0
  43. data/lib/materialize-sass/version.rb +1 -1
  44. metadata +6 -5
  45. data/assets/javascripts/materialize/velocity.min.js +0 -782
  46. 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 ($, Vel) {
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
- Vel(this.$slides.first()[0], { opacity: 1 }, { duration: this.options.duration, queue: false, easing: 'easeOutQuad' });
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
- Vel(_this.$active.find('.caption')[0], { opacity: 1, translateX: 0, translateY: 0 }, { duration: _this.options.duration, queue: false, easing: 'easeOutQuad' });
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 velocityOptions = {
189
- opacity: 0
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
- velocityOptions.translateY = -100;
208
+ animOptions.translateY = -100;
194
209
  } else if ($(caption).hasClass('right-align')) {
195
- velocityOptions.translateX = 100;
210
+ animOptions.translateX = 100;
196
211
  } else if ($(caption).hasClass('left-align')) {
197
- velocityOptions.translateX = -100;
212
+ animOptions.translateX = -100;
198
213
  }
199
214
 
200
- Vel(caption, velocityOptions, { duration: duration, queue: false });
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
- Vel(this.$active[0], { opacity: 0 }, { duration: this.options.duration, queue: false, easing: 'easeOutQuad',
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
- Vel(el, { opacity: 0, translateX: 0, translateY: 0 }, { duration: 0, queue: false });
293
+ anim({
294
+ targets: el,
295
+ opacity: 0,
296
+ translateX: 0,
297
+ translateY: 0,
298
+ duration: 0,
299
+ easing: 'easeOutQuad'
300
+ });
275
301
  });
276
- }.bind(this)
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
- Vel(this.$slides.eq(index)[0], { opacity: 1 }, { duration: this.options.duration, queue: false, easing: 'easeOutQuad' });
288
- Vel(this.$slides.eq(index).find('.caption')[0], { opacity: 1, translateX: 0, translateY: 0 }, { duration: this.options.duration, delay: this.options.duration, queue: false, easing: 'easeOutQuad' });
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.Vel);
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 ($, Vel) {
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 carousel
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 !== undefined) {
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 !== undefined && !$oldContent.is(this.$content)) {
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 {jQuery} el
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 {jQuery} el
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 velOptions = {
392
- duration: this.options.duration,
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
- velOptionsLeft = $.extend({}, velOptions, { delay: 90 });
401
- velOptionsRight = velOptions;
400
+ leftDelay = 90;
402
401
  } else {
403
- velOptionsLeft = velOptions;
404
- velOptionsRight = $.extend({}, velOptions, { delay: 90 });
402
+ rightDelay = 90;
405
403
  }
406
404
 
407
- // Animate with velocity
408
- Vel(this._indicator, { left: this._calcLeftPos(this.$activeTabLink) }, velOptionsLeft);
409
- Vel(this._indicator, { right: this._calcRightPos(this.$activeTabLink) }, velOptionsRight);
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.Vel);
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 ($, Vel) {
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
- /**
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
- var Timepicker = function () {
31
- function Timepicker(el, options) {
32
- _classCallCheck(this, Timepicker);
30
+ var Timepicker = function () {
31
+ function Timepicker(el, options) {
32
+ _classCallCheck(this, Timepicker);
33
33
 
34
- // If exists, destroy and reinitialize
35
- if (!!el.M_Timepicker) {
36
- el.M_Timepicker.destroy();
37
- }
34
+ // If exists, destroy and reinitialize
35
+ if (!!el.M_Timepicker) {
36
+ el.M_Timepicker.destroy();
37
+ }
38
38
 
39
- this.el = el;
40
- this.$el = $(el);
41
- this.el.M_Timepicker = this;
39
+ this.el = el;
40
+ this.$el = $(el);
41
+ this.el.M_Timepicker = this;
42
42
 
43
- this.options = $.extend({}, Timepicker.defaults, options);
43
+ this.options = $.extend({}, Timepicker.defaults, options);
44
44
 
45
- this.id = M.guid();
46
- this._insertHTMLIntoDOM();
47
- this._setupModal();
48
- this._setupVariables();
49
- this._setupEventHandlers();
45
+ this.id = M.guid();
46
+ this._insertHTMLIntoDOM();
47
+ this._setupModal();
48
+ this._setupVariables();
49
+ this._setupEventHandlers();
50
50
 
51
- this._clockSetup();
52
- this._pickerSetup();
53
- }
51
+ this._clockSetup();
52
+ this._pickerSetup();
53
+ }
54
54
 
55
- _createClass(Timepicker, [{
56
- key: 'destroy',
55
+ _createClass(Timepicker, [{
56
+ key: 'destroy',
57
57
 
58
58
 
59
- /**
59
+ /**
60
60
  * Teardown component
61
61
  */
62
- value: function destroy() {
63
- this._removeEventHandlers();
64
- this.modal.destroy();
65
- $(this.modalEl).remove();
66
- this.el.M_Timepicker = undefined;
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
- 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
- this.$amBtn.toggleClass('text-primary', this.amOrPm === 'AM');
334
- this.$pmBtn.toggleClass('text-primary', this.amOrPm === 'PM');
335
- }
336
- }, {
337
- key: '_updateTimeFromInput',
338
- value: function _updateTimeFromInput() {
339
- // Get the time
340
- var value = ((this.el.value || this.options.defaultTime || '') + '').split(':');
341
- if (this.options.twelveHour && !(typeof value[1] === 'undefined')) {
342
- if (value[1].indexOf("AM") > 0) {
343
- this.amOrPm = 'AM';
344
- } else {
345
- this.amOrPm = 'PM';
346
- }
347
- value[1] = value[1].replace("AM", "").replace("PM", "");
348
- }
349
- if (value[0] === 'now') {
350
- var now = new Date(+new Date() + this.options.fromnow);
351
- value = [now.getHours(), now.getMinutes()];
352
- if (this.options.twelveHour) {
353
- this.amOrPm = value[0] >= 12 && value[0] < 24 ? 'PM' : 'AM';
354
- }
355
- }
356
- this.hours = +value[0] || 0;
357
- this.minutes = +value[1] || 0;
358
- this.spanHours.innerHTML = this.hours;
359
- this.spanMinutes.innerHTML = Timepicker._addLeadingZero(this.minutes);
360
-
361
- this._updateAmPmView();
362
- }
363
- }, {
364
- key: 'showView',
365
- value: function showView(view, delay) {
366
- if (view === 'minutes' && $(this.hoursView).css("visibility") === "visible") {
367
- // raiseCallback(this.options.beforeHourSelect);
368
- }
369
- var isHours = view === 'hours',
370
- nextView = isHours ? this.hoursView : this.minutesView,
371
- hideView = isHours ? this.minutesView : this.hoursView;
372
- this.currentView = view;
373
-
374
- $(this.spanHours).toggleClass('text-primary', isHours);
375
- $(this.spanMinutes).toggleClass('text-primary', !isHours);
376
-
377
- // Transition view
378
- hideView.classList.add('timepicker-dial-out');
379
- $(nextView).css('visibility', 'visible').removeClass('timepicker-dial-out');
380
-
381
- // Reset clock hand
382
- this.resetClock(delay);
383
-
384
- // After transitions ended
385
- clearTimeout(this.toggleViewTimer);
386
- this.toggleViewTimer = setTimeout(function () {
387
- $(hideView).css('visibility', 'hidden');
388
- }, this.options.duration);
389
- }
390
- }, {
391
- key: 'resetClock',
392
- value: function resetClock(delay) {
393
- var view = this.currentView,
394
- value = this[view],
395
- isHours = view === 'hours',
396
- unit = Math.PI / (isHours ? 6 : 30),
397
- radian = value * unit,
398
- radius = isHours && value > 0 && value < 13 ? this.options.innerRadius : this.options.outerRadius,
399
- x = Math.sin(radian) * radius,
400
- y = -Math.cos(radian) * radius,
401
- self = this;
402
-
403
- if (delay) {
404
- $(this.canvas).addClass('timepicker-canvas-out');
405
- setTimeout(function () {
406
- $(self.canvas).removeClass('timepicker-canvas-out');
407
- self.setHand(x, y);
408
- }, delay);
409
- } else {
410
- this.setHand(x, y);
411
- }
412
- }
413
- }, {
414
- key: 'setHand',
415
- value: function setHand(x, y, roundBy5) {
416
- var _this2 = this;
417
-
418
- var radian = Math.atan2(x, -y),
419
- isHours = this.currentView === 'hours',
420
- unit = Math.PI / (isHours || roundBy5 ? 6 : 30),
421
- z = Math.sqrt(x * x + y * y),
422
- inner = isHours && z < (this.options.outerRadius + this.options.innerRadius) / 2,
423
- radius = inner ? this.options.innerRadius : this.options.outerRadius;
424
-
425
- if (this.options.twelveHour) {
426
- radius = this.options.outerRadius;
427
- }
428
-
429
- // Radian should in range [0, 2PI]
430
- if (radian < 0) {
431
- radian = Math.PI * 2 + radian;
432
- }
433
-
434
- // Get the round value
435
- var value = Math.round(radian / unit);
436
-
437
- // Get the round radian
438
- radian = value * unit;
439
-
440
- // Correct the hours or minutes
441
- if (this.options.twelveHour) {
442
- if (isHours) {
443
- if (value === 0) value = 12;
444
- } else {
445
- if (roundBy5) value *= 5;
446
- if (value === 60) value = 0;
447
- }
448
- } else {
449
- if (isHours) {
450
- if (value === 12) {
451
- value = 0;
452
- }
453
- value = inner ? value === 0 ? 12 : value : value === 0 ? 0 : value + 12;
454
- } else {
455
- if (roundBy5) {
456
- value *= 5;
457
- }
458
- if (value === 60) {
459
- value = 0;
460
- }
461
- }
462
- }
463
-
464
- // Once hours or minutes changed, vibrate the device
465
- if (this[this.currentView] !== value) {
466
- if (this.vibrate && this.options.vibrate) {
467
- // Do not vibrate too frequently
468
- if (!this.vibrateTimer) {
469
- navigator[this.vibrate](10);
470
- this.vibrateTimer = setTimeout(function () {
471
- _this2.vibrateTimer = null;
472
- }, 100);
473
- }
474
- }
475
- }
476
-
477
- this[this.currentView] = value;
478
- if (isHours) {
479
- this['spanHours'].innerHTML = value;
480
- } else {
481
- this['spanMinutes'].innerHTML = Timepicker._addLeadingZero(value);
482
- }
483
-
484
- // Set clock hand and others' position
485
- var cx1 = Math.sin(radian) * (radius - this.options.tickRadius),
486
- cy1 = -Math.cos(radian) * (radius - this.options.tickRadius),
487
- cx2 = Math.sin(radian) * radius,
488
- cy2 = -Math.cos(radian) * radius;
489
- this.hand.setAttribute('x2', cx1);
490
- this.hand.setAttribute('y2', cy1);
491
- this.bg.setAttribute('cx', cx2);
492
- this.bg.setAttribute('cy', cy2);
493
- }
494
- }, {
495
- key: 'open',
496
- value: function open() {
497
- if (this.isOpen) {
498
- return;
499
- }
500
-
501
- this.isOpen = true;
502
- this._updateTimeFromInput();
503
- this.showView('hours');
504
- this.modal.open();
505
- }
506
- }, {
507
- key: 'close',
508
- value: function close() {
509
- if (!this.isOpen) {
510
- return;
511
- }
512
-
513
- this.isOpen = false;
514
- this.modal.close();
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
- key: 'done',
523
- value: function done(e, clearValue) {
524
- // Set input value
525
- var last = this.el.value;
526
- var value = clearValue ? '' : Timepicker._addLeadingZero(this.hours) + ':' + Timepicker._addLeadingZero(this.minutes);
527
- this.time = value;
528
- if (!clearValue && this.options.twelveHour) {
529
- value = value + ' ' + this.amOrPm;
530
- }
531
- this.el.value = value;
532
-
533
- // Trigger change event
534
- if (value !== last) {
535
- this.$el.trigger('change');
536
- }
537
-
538
- this.close();
539
- this.el.focus();
540
- }
541
- }, {
542
- key: 'clear',
543
- value: function clear() {
544
- this.done(null, true);
545
- }
546
- }], [{
547
- key: 'init',
548
- value: function init($els, options) {
549
- var arr = [];
550
- $els.each(function () {
551
- arr.push(new Timepicker(this, options));
552
- });
553
- return arr;
554
- }
555
- }, {
556
- key: '_addLeadingZero',
557
- value: function _addLeadingZero(num) {
558
- return (num < 10 ? '0' : '') + num;
559
- }
560
- }, {
561
- key: '_createSVGEl',
562
- value: function _createSVGEl(name) {
563
- var svgNS = 'http://www.w3.org/2000/svg';
564
- return document.createElementNS(svgNS, name);
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
- key: '_Pos',
581
- value: function _Pos(e) {
582
- if (e.targetTouches && e.targetTouches.length >= 1) {
583
- return { x: e.targetTouches[0].clientX, y: e.targetTouches[0].clientY };
584
- }
585
- // mouse event
586
- return { x: e.clientX, y: e.clientY };
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
- key: 'getInstance',
595
- value: function getInstance(el) {
596
- var domElem = !!el.jquery ? el[0] : el;
597
- return domElem.M_Timepicker;
598
- }
599
- }, {
600
- key: 'defaults',
601
- get: function () {
602
- return _defaults;
603
- }
604
- }]);
605
-
606
- return Timepicker;
607
- }();
608
-
609
- 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('');
610
-
611
- M.Timepicker = Timepicker;
612
-
613
- if (M.jQueryLoaded) {
614
- M.initializeJqueryWrapper(Timepicker, 'timepicker', 'M_Timepicker');
615
- }
616
- })(cash, M.Vel);
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);