materialize-sass 1.0.0.alpha4 → 1.0.0.beta

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