md-date-time-picker-rails 2.0.3a → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -1
  3. data/lib/md-date-time-picker-rails/version.rb +1 -1
  4. data/vendor/assets/javascripts/mdDateTimePickerLocale.js +1253 -0
  5. data/vendor/assets/javascripts/moment_locales.js +12051 -0
  6. data/vendor/assets/stylesheets/themes/dark/amber/md-date-time-picker.css.erb +6 -5
  7. data/vendor/assets/stylesheets/themes/dark/blue-grey/md-date-time-picker.css.erb +12 -9
  8. data/vendor/assets/stylesheets/themes/dark/blue/md-date-time-picker.css.erb +12 -10
  9. data/vendor/assets/stylesheets/themes/dark/brown/md-date-time-picker.css.erb +1539 -0
  10. data/vendor/assets/stylesheets/themes/dark/cyan/md-date-time-picker.css.erb +1539 -0
  11. data/vendor/assets/stylesheets/themes/dark/deep-orange/md-date-time-picker.css.erb +1536 -0
  12. data/vendor/assets/stylesheets/themes/dark/deep-purple/md-date-time-picker.css.erb +1536 -0
  13. data/vendor/assets/stylesheets/themes/dark/green/md-date-time-picker.css.erb +1536 -0
  14. data/vendor/assets/stylesheets/themes/dark/grey/md-date-time-picker.css.erb +1536 -0
  15. data/vendor/assets/stylesheets/themes/dark/indigo/md-date-time-picker.css.erb +1536 -0
  16. data/vendor/assets/stylesheets/themes/dark/light-blue/md-date-time-picker.css.erb +1536 -0
  17. data/vendor/assets/stylesheets/themes/dark/light-green/md-date-time-picker.css.erb +1536 -0
  18. data/vendor/assets/stylesheets/themes/dark/lime/md-date-time-picker.css.erb +1536 -0
  19. data/vendor/assets/stylesheets/themes/dark/orange/md-date-time-picker.css.erb +1536 -0
  20. data/vendor/assets/stylesheets/themes/dark/pink/md-date-time-picker.css.erb +1536 -0
  21. data/vendor/assets/stylesheets/themes/dark/purple/md-date-time-picker.css.erb +1536 -0
  22. data/vendor/assets/stylesheets/themes/dark/red/md-date-time-picker.css.erb +1536 -0
  23. data/vendor/assets/stylesheets/themes/dark/teal/md-date-time-picker.css.erb +1536 -0
  24. data/vendor/assets/stylesheets/themes/dark/yellow/md-date-time-picker.css.erb +1536 -0
  25. data/vendor/assets/stylesheets/themes/dark_img.css.erb +16 -0
  26. data/vendor/assets/stylesheets/themes/light/amber/md-date-time-picker.css.erb +1536 -0
  27. data/vendor/assets/stylesheets/themes/light/blue-grey/md-date-time-picker.css.erb +1536 -0
  28. data/vendor/assets/stylesheets/themes/light/blue/md-date-time-picker.css.erb +1536 -0
  29. data/vendor/assets/stylesheets/themes/light/brown/md-date-time-picker.css.erb +1536 -0
  30. data/vendor/assets/stylesheets/themes/light/cyan/md-date-time-picker.css.erb +1536 -0
  31. data/vendor/assets/stylesheets/themes/light/deep-orange/md-date-time-picker.css.erb +1536 -0
  32. data/vendor/assets/stylesheets/themes/light/deep-purple/md-date-time-picker.css.erb +1536 -0
  33. data/vendor/assets/stylesheets/themes/light/green/md-date-time-picker.css.erb +1536 -0
  34. data/vendor/assets/stylesheets/themes/light/grey/md-date-time-picker.css.erb +1536 -0
  35. data/vendor/assets/stylesheets/themes/light/indigo/md-date-time-picker.css.erb +1536 -0
  36. data/vendor/assets/stylesheets/themes/light/light-blue/md-date-time-picker.css.erb +1536 -0
  37. data/vendor/assets/stylesheets/themes/light/light-green/md-date-time-picker.css.erb +1536 -0
  38. data/vendor/assets/stylesheets/themes/light/lime/md-date-time-picker.css.erb +1536 -0
  39. data/vendor/assets/stylesheets/themes/light/orange/md-date-time-picker.css.erb +1536 -0
  40. data/vendor/assets/stylesheets/themes/light/pink/md-date-time-picker.css.erb +1536 -0
  41. data/vendor/assets/stylesheets/themes/light/purple/md-date-time-picker.css.erb +1536 -0
  42. data/vendor/assets/stylesheets/themes/light/red/md-date-time-picker.css.erb +1536 -0
  43. data/vendor/assets/stylesheets/themes/light/teal/md-date-time-picker.css.erb +1536 -0
  44. data/vendor/assets/stylesheets/themes/light/yellow/md-date-time-picker.css.erb +1536 -0
  45. data/vendor/assets/stylesheets/themes/light_img.css.erb +15 -0
  46. metadata +40 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2504d6abf78a11ae0629c5ee61e307c8f661f67f
4
- data.tar.gz: d9081779d28a6654852387f4963af0ca64d9e1e0
3
+ metadata.gz: 5bf880e849b6709cf1e0d3bd772edf02de687e18
4
+ data.tar.gz: ca44b8b38d8150bd1e5c192e9d86f86b1c85de7f
5
5
  SHA512:
6
- metadata.gz: a6d750ce371eb73c76bbcb8265eaf34b6ae715cb714510d3d26e37eccc6f13e09dbf135f0b51be2722164995258e5a12efbe24fef22a727c067305962e2ec8db
7
- data.tar.gz: 96de1a3910d8ae6f64890889724c3d19319c7d9e72617a98b15b77363d8826919c20763488c05abef23729e695759387ed764a914d0ded8d919fa6fd82c02eea
6
+ metadata.gz: ea44d39cc375e750f3a5267468ddb71c92ff13a801304265d645a82e8a4fe0b41602bd69c36a24de961637d4ecbdc4586e4b276926f625c4f137f3c12b6c1e5b
7
+ data.tar.gz: 8acf9b8268f3995cddb65fc57c8561b3bc5e081b20bc6ef662f3550c07a8254f8be7da212951e1eb25a99594c05ebf5d83a17eaeda6ca3ab91217124a468938a
data/README.md CHANGED
@@ -69,7 +69,8 @@ and change the following line:
69
69
 
70
70
  Currently, Support Theme List
71
71
 
72
- - `themes/dark/amber`, `themes/dark/blue`, `themes/dark/blue-grey`
72
+ - `themes/dark/amber`, `themes/dark/blue`, `themes/dark/blue-grey`, `themes/dark/cyan`, `themes/dark/deep-orange`, `themes/dark/deep-purple`, `themes/dark/green`, `themes/dark/grey`,`themes/dark/indigo`, `themes/dark/light-blue`, `themes/dark/light-green`, `themes/dark/lime`, `themes/dark/orange`, `themes/dark/pink`, `themes/dark/purple`, `themes/dark/red`, `themes/dark/teal`, `themes/dark/yellow`
73
+ - `themes/light/amber`, `themes/light/blue`, `themes/light/blue-grey`, `themes/light/cyan`, `themes/light/deep-orange`, `themes/light/deep-purple`, `themes/light/green`, `themes/light/grey`,`themes/light/indigo`, `themes/light/light-blue`, `themes/light/light-green`, `themes/light/lime`, `themes/light/orange`, `themes/light/pink`, `themes/light/purple`, `themes/light/red`, `themes/light/teal`, `themes/light/yellow`
73
74
 
74
75
 
75
76
 
@@ -1,5 +1,5 @@
1
1
  module MdDateTimePicker
2
2
  module Rails
3
- VERSION = "2.0.3a"
3
+ VERSION = "2.0.4"
4
4
  end
5
5
  end
@@ -0,0 +1,1253 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(['exports'], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports);
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports);
11
+ global.mdDateTimePicker = mod.exports;
12
+ }
13
+ })(this, function (exports) {
14
+ 'use strict';
15
+
16
+ Object.defineProperty(exports, "__esModule", {
17
+ value: true
18
+ });
19
+
20
+ function _classCallCheck(instance, Constructor) {
21
+ if (!(instance instanceof Constructor)) {
22
+ throw new TypeError("Cannot call a class as a function");
23
+ }
24
+ }
25
+
26
+ var _createClass = function () {
27
+ function defineProperties(target, props) {
28
+ for (var i = 0; i < props.length; i++) {
29
+ var descriptor = props[i];
30
+ descriptor.enumerable = descriptor.enumerable || !1;
31
+ descriptor.configurable = !0;
32
+ if ("value" in descriptor) descriptor.writable = !0;
33
+ Object.defineProperty(target, descriptor.key, descriptor);
34
+ }
35
+ }
36
+
37
+ return function (Constructor, protoProps, staticProps) {
38
+ if (protoProps) defineProperties(Constructor.prototype, protoProps);
39
+ if (staticProps) defineProperties(Constructor, staticProps);
40
+ return Constructor;
41
+ };
42
+ }(),
43
+ _dialog = {
44
+ view: !0,
45
+ state: !1
46
+ },
47
+ mdDateTimePicker = function () {
48
+ /**
49
+ * [constructor of the mdDateTimePicker]
50
+ *
51
+ * @method constructor
52
+ *
53
+ * @param {[string]} type = 'date' or 'time [type of dialog]
54
+ * @param {[moment]} init [initial value for the dialog date or time, defaults to today] [@default = today]
55
+ * @param {[moment]} past [the past moment till which the calendar shall render] [@default = exactly 21 Years ago from init]
56
+ * @param {[moment]} future [the future moment till which the calendar shall render] [@default = init]
57
+ * @param {[moment]} locale [the future moment locale render] [@default = en]
58
+ * @param {[Boolean]} mode [this value tells whether the time dialog will have the 24 hour mode (true) or 12 hour mode (false)] [@default = false]
59
+ * @param {[string]} orientation = 'LANDSCAPE' or 'PORTRAIT' [force the orientation of the picker @default = 'LANDSCAPE']
60
+ * @param {[element]} trigger [element on which all the events will be dispatched e.g var foo = document.getElementById('bar'), here element = foo]
61
+ *
62
+ * @return {[Object]} [mdDateTimePicker]
63
+ */
64
+
65
+ function mdDateTimePicker(_ref) {
66
+ var type = _ref.type,
67
+ _ref$init = _ref.init,
68
+ init = _ref$init === undefined ? moment() : _ref$init,
69
+ _ref$past = _ref.past,
70
+ past = _ref$past === undefined ? moment().subtract(21, 'years') : _ref$past,
71
+ _ref$future = _ref.future,
72
+ future = _ref$future === undefined ? init : _ref$future,
73
+ _ref$mode = _ref.mode,
74
+ mode = _ref$mode === undefined ? !1 : _ref$mode,
75
+ _ref$orientation = _ref.orientation,
76
+ orientation = _ref$orientation === undefined ? 'LANDSCAPE' : _ref$orientation,
77
+ _ref$trigger = _ref.trigger,
78
+ trigger = _ref$trigger === undefined ? '' : _ref$trigger;
79
+
80
+
81
+ _classCallCheck(this, mdDateTimePicker);
82
+
83
+ this._type = type;
84
+ this._init = init;
85
+ this._past = past;
86
+ this._future = future;
87
+ this._mode = mode;
88
+ this._orientation = orientation;
89
+ this._trigger = trigger;
90
+
91
+
92
+ /**
93
+ * [dialog selected classes have the same structure as dialog but one level down]
94
+ * @type {Object}
95
+ * e.g
96
+ * sDialog = {
97
+ * picker: 'some-picker-selected'
98
+ * }
99
+ */
100
+ this._sDialog = {};
101
+ // attach the dialog if not present
102
+ if (!document.getElementById('mddtp-picker__' + this._type)) {
103
+ this._buildDialog();
104
+ }
105
+ }
106
+
107
+ /**
108
+ * [time to get or set the current picker's moment]
109
+ *
110
+ * @method time
111
+ *
112
+ * @param {[moment]} m
113
+ *
114
+ */
115
+
116
+
117
+ _createClass(mdDateTimePicker, [{
118
+ key: 'toggle',
119
+ value: function toggle() {
120
+ this._selectDialog();
121
+ // work according to the current state of the dialog
122
+ if (mdDateTimePicker.dialog.state) {
123
+ this._hideDialog();
124
+ } else {
125
+ if (this._type === 'date') {
126
+ this._initDateDialog(this._init);
127
+ } else if (this._type === 'time') {
128
+ this._initTimeDialog(this._init);
129
+ }
130
+ this._showDialog();
131
+ }
132
+ }
133
+ }, {
134
+ key: '_selectDialog',
135
+ value: function _selectDialog() {
136
+ // now do what you normally would do
137
+ this._sDialog.picker = document.getElementById('mddtp-picker__' + [this._type]);
138
+ /**
139
+ * [sDialogEls stores all inner components of the selected dialog or sDialog to be later getElementById]
140
+ *
141
+ * @type {Array}
142
+ */
143
+ var sDialogEls = ['viewHolder', 'years', 'header', 'cancel', 'ok', 'left', 'right', 'previous', 'current', 'next', 'subtitle', 'title', 'titleDay', 'titleMonth', 'AM', 'PM', 'needle', 'hourView', 'minuteView', 'hour', 'minute', 'fakeNeedle', 'circularHolder', 'circle', 'dotSpan'],
144
+ i = sDialogEls.length;
145
+
146
+ while (i--) {
147
+ this._sDialog[sDialogEls[i]] = document.getElementById('mddtp-' + this._type + '__' + sDialogEls[i]);
148
+ }
149
+
150
+ this._sDialog.tDate = this._init.clone();
151
+ this._sDialog.sDate = this._init.clone();
152
+ }
153
+ }, {
154
+ key: '_showDialog',
155
+ value: function _showDialog() {
156
+ var me = this,
157
+ zoomIn = 'zoomIn';
158
+
159
+ mdDateTimePicker.dialog.state = !0;
160
+ this._sDialog.picker.classList.remove('mddtp-picker--inactive');
161
+ this._sDialog.picker.classList.add(zoomIn);
162
+ // if the dialog is forced into portrait mode
163
+ if (this._orientation === 'PORTRAIT') {
164
+ this._sDialog.picker.classList.add('mddtp-picker--portrait');
165
+ }
166
+ setTimeout(function () {
167
+ me._sDialog.picker.classList.remove(zoomIn);
168
+ }, 300);
169
+ }
170
+ }, {
171
+ key: '_hideDialog',
172
+ value: function _hideDialog() {
173
+ var me = this,
174
+ years = this._sDialog.years,
175
+ title = me._sDialog.title,
176
+ subtitle = me._sDialog.subtitle,
177
+ viewHolder = this._sDialog.viewHolder,
178
+ AM = this._sDialog.AM,
179
+ PM = this._sDialog.PM,
180
+ minute = this._sDialog.minute,
181
+ hour = this._sDialog.hour,
182
+ minuteView = this._sDialog.minuteView,
183
+ hourView = this._sDialog.hourView,
184
+ picker = this._sDialog.picker,
185
+ needle = this._sDialog.needle,
186
+ dotSpan = this._sDialog.dotSpan,
187
+ active = 'mddtp-picker__color--active',
188
+ inactive = 'mddtp-picker--inactive',
189
+ invisible = 'mddtp-picker__years--invisible',
190
+ zoomIn = 'zoomIn',
191
+ zoomOut = 'zoomOut',
192
+ hidden = 'mddtp-picker__circularView--hidden',
193
+ selection = 'mddtp-picker__selection';
194
+
195
+ mdDateTimePicker.dialog.state = !1;
196
+ mdDateTimePicker.dialog.view = !0;
197
+ this._sDialog.picker.classList.add(zoomOut);
198
+ // reset classes
199
+ if (this._type === 'date') {
200
+ years.classList.remove(zoomIn, zoomOut);
201
+ years.classList.add(invisible);
202
+ title.classList.remove(active);
203
+ subtitle.classList.add(active);
204
+ viewHolder.classList.remove(zoomOut);
205
+ } else {
206
+ AM.classList.remove(active);
207
+ PM.classList.remove(active);
208
+ minute.classList.remove(active);
209
+ hour.classList.add(active);
210
+ minuteView.classList.add(hidden);
211
+ hourView.classList.remove(hidden);
212
+ subtitle.setAttribute('style', 'display: none');
213
+ dotSpan.setAttribute('style', 'display: none');
214
+ needle.className = selection;
215
+ }
216
+ setTimeout(function () {
217
+ // remove portrait mode
218
+ me._sDialog.picker.classList.remove('mddtp-picker--portrait');
219
+ me._sDialog.picker.classList.remove(zoomOut);
220
+ me._sDialog.picker.classList.add(inactive);
221
+ // clone elements and add them again to clear events attached to them
222
+ var pickerClone = picker.cloneNode(!0);
223
+ picker.parentNode.replaceChild(pickerClone, picker);
224
+ }, 300);
225
+ }
226
+ }, {
227
+ key: '_buildDialog',
228
+ value: function _buildDialog() {
229
+ var type = this._type,
230
+ docfrag = document.createDocumentFragment(),
231
+ container = document.createElement('div'),
232
+ header = document.createElement('div'),
233
+ body = document.createElement('div'),
234
+ action = document.createElement('div'),
235
+ cancel = document.createElement('button'),
236
+ ok = document.createElement('button');
237
+ // outer most container of the picker
238
+
239
+ // header container of the picker
240
+
241
+ // body container of the picker
242
+
243
+ // action elements container
244
+
245
+ // ... add properties to them
246
+ container.id = 'mddtp-picker__' + type;
247
+ container.classList.add('mddtp-picker');
248
+ container.classList.add('mddtp-picker-' + type);
249
+ container.classList.add('mddtp-picker--inactive');
250
+ container.classList.add('animated');
251
+ this._addId(header, 'header');
252
+ this._addClass(header, 'header');
253
+ // add header to container
254
+ container.appendChild(header);
255
+ this._addClass(body, 'body');
256
+ body.appendChild(action);
257
+ // add body to container
258
+ container.appendChild(body);
259
+ // add stuff to header and body according to dialog type
260
+ if (this._type === 'date') {
261
+ var subtitle = document.createElement('div'),
262
+ title = document.createElement('div'),
263
+ titleDay = document.createElement('div'),
264
+ titleMonth = document.createElement('div'),
265
+ viewHolder = document.createElement('div'),
266
+ views = document.createElement('ul'),
267
+ previous = document.createElement('li'),
268
+ current = document.createElement('li'),
269
+ next = document.createElement('li'),
270
+ left = document.createElement('button'),
271
+ right = document.createElement('button'),
272
+ years = document.createElement('ul');
273
+
274
+ // inside header
275
+ // adding properties to them
276
+ this._addId(subtitle, 'subtitle');
277
+ this._addClass(subtitle, 'subtitle');
278
+ this._addId(title, 'title');
279
+ this._addClass(title, 'title', ['mddtp-picker__color--active']);
280
+ this._addId(titleDay, 'titleDay');
281
+ this._addId(titleMonth, 'titleMonth');
282
+ // add title stuff to it
283
+ title.appendChild(titleDay);
284
+ title.appendChild(titleMonth);
285
+ // add them to header
286
+ header.appendChild(subtitle);
287
+ header.appendChild(title);
288
+ // inside body
289
+ // inside viewHolder
290
+ this._addId(viewHolder, 'viewHolder');
291
+ this._addClass(viewHolder, 'viewHolder', ['animated']);
292
+ this._addClass(views, 'views');
293
+ this._addId(previous, 'previous');
294
+ previous.classList.add('mddtp-picker__view');
295
+ this._addId(current, 'current');
296
+ current.classList.add('mddtp-picker__view');
297
+ this._addId(next, 'next');
298
+ next.classList.add('mddtp-picker__view');
299
+ // fill the views
300
+ this._addView(previous);
301
+ this._addView(current);
302
+ this._addView(next);
303
+ // add them
304
+ viewHolder.appendChild(views);
305
+ views.appendChild(previous);
306
+ views.appendChild(current);
307
+ views.appendChild(next);
308
+ // inside body again
309
+ this._addId(left, 'left');
310
+ left.classList.add('mddtp-button');
311
+ this._addClass(left, 'left');
312
+ left.setAttribute('type', 'button');
313
+ this._addId(right, 'right');
314
+ right.classList.add('mddtp-button');
315
+ this._addClass(right, 'right');
316
+ right.setAttribute('type', 'button');
317
+ this._addId(years, 'years');
318
+ this._addClass(years, 'years', ['mddtp-picker__years--invisible', 'animated']);
319
+ // add them to body
320
+ body.appendChild(viewHolder);
321
+ body.appendChild(left);
322
+ body.appendChild(right);
323
+ body.appendChild(years);
324
+ } else {
325
+ var _title = document.createElement('div'),
326
+ hour = document.createElement('span'),
327
+ span = document.createElement('span'),
328
+ minute = document.createElement('span'),
329
+ _subtitle = document.createElement('div'),
330
+ AM = document.createElement('div'),
331
+ PM = document.createElement('div'),
332
+ circularHolder = document.createElement('div'),
333
+ needle = document.createElement('div'),
334
+ dot = document.createElement('span'),
335
+ line = document.createElement('span'),
336
+ circle = document.createElement('span'),
337
+ minuteView = document.createElement('div'),
338
+ fakeNeedle = document.createElement('div'),
339
+ hourView = document.createElement('div');
340
+
341
+ // add properties to them
342
+ // inside header
343
+ this._addId(_title, 'title');
344
+ this._addClass(_title, 'title');
345
+ this._addId(hour, 'hour');
346
+ hour.classList.add('mddtp-picker__color--active');
347
+ span.textContent = ':';
348
+ this._addId(span, 'dotSpan');
349
+ span.setAttribute('style', 'display: none');
350
+ this._addId(minute, 'minute');
351
+ this._addId(_subtitle, 'subtitle');
352
+ this._addClass(_subtitle, 'subtitle');
353
+ _subtitle.setAttribute('style', 'display: none');
354
+ this._addId(AM, 'AM');
355
+ AM.textContent = 'AM';
356
+ this._addId(PM, 'PM');
357
+ PM.textContent = 'PM';
358
+ // add them to title and subtitle
359
+ _title.appendChild(hour);
360
+ _title.appendChild(span);
361
+ _title.appendChild(minute);
362
+ _subtitle.appendChild(AM);
363
+ _subtitle.appendChild(PM);
364
+ // add them to header
365
+ header.appendChild(_title);
366
+ header.appendChild(_subtitle);
367
+ // inside body
368
+ this._addId(circularHolder, 'circularHolder');
369
+ this._addClass(circularHolder, 'circularHolder');
370
+ this._addId(needle, 'needle');
371
+ needle.classList.add('mddtp-picker__selection');
372
+ this._addClass(dot, 'dot');
373
+ this._addClass(line, 'line');
374
+ this._addId(circle, 'circle');
375
+ this._addClass(circle, 'circle');
376
+ this._addId(minuteView, 'minuteView');
377
+ minuteView.classList.add('mddtp-picker__circularView');
378
+ minuteView.classList.add('mddtp-picker__circularView--hidden');
379
+ this._addId(fakeNeedle, 'fakeNeedle');
380
+ fakeNeedle.classList.add('mddtp-picker__circle--fake');
381
+ this._addId(hourView, 'hourView');
382
+ hourView.classList.add('mddtp-picker__circularView');
383
+ // add them to needle
384
+ needle.appendChild(dot);
385
+ needle.appendChild(line);
386
+ needle.appendChild(circle);
387
+ // add them to circularHolder
388
+ circularHolder.appendChild(needle);
389
+ circularHolder.appendChild(minuteView);
390
+ circularHolder.appendChild(fakeNeedle);
391
+ circularHolder.appendChild(hourView);
392
+ // add them to body
393
+ body.appendChild(circularHolder);
394
+ }
395
+ action.classList.add('mddtp-picker__action');
396
+ this._addId(cancel, 'cancel');
397
+ cancel.classList.add('mddtp-button');
398
+ cancel.setAttribute('type', 'button');
399
+ cancel.textContent = 'cancel';
400
+ this._addId(ok, 'ok');
401
+ ok.classList.add('mddtp-button');
402
+ ok.setAttribute('type', 'button');
403
+ ok.textContent = 'ok';
404
+ // add actions
405
+ action.appendChild(cancel);
406
+ action.appendChild(ok);
407
+ // add actions to body
408
+ body.appendChild(action);
409
+ docfrag.appendChild(container);
410
+ // add the container to the end of body
411
+ document.getElementsByTagName('body').item(0).appendChild(docfrag);
412
+ }
413
+ }, {
414
+ key: '_initTimeDialog',
415
+ value: function _initTimeDialog(m) {
416
+ var hour = this._sDialog.hour,
417
+ minute = this._sDialog.minute,
418
+ subtitle = this._sDialog.subtitle,
419
+ dotSpan = this._sDialog.dotSpan;
420
+
421
+ // switch according to 12 hour or 24 hour mode
422
+ if (this._mode) {
423
+ this._fillText(hour, m.format('H'));
424
+ } else {
425
+ this._fillText(hour, m.format('h'));
426
+ this._sDialog[m.format('A')].classList.add('mddtp-picker__color--active');
427
+ subtitle.removeAttribute('style');
428
+ dotSpan.removeAttribute('style');
429
+ }
430
+ this._fillText(minute, m.format('mm'));
431
+ this._initHour();
432
+ this._initMinute();
433
+ this._attachEventHandlers();
434
+ this._changeM();
435
+ this._dragDial();
436
+ this._switchToView(hour);
437
+ this._switchToView(minute);
438
+ this._addClockEvent();
439
+ }
440
+ }, {
441
+ key: '_initHour',
442
+ value: function _initHour() {
443
+ var hourView = this._sDialog.hourView,
444
+ needle = this._sDialog.needle,
445
+ hour = 'mddtp-hour__selected',
446
+ selected = 'mddtp-picker__cell--selected',
447
+ rotate = 'mddtp-picker__cell--rotate-',
448
+ cell = 'mddtp-picker__cell',
449
+ docfrag = document.createDocumentFragment(),
450
+ hourNow = void 0;
451
+
452
+ if (this._mode) {
453
+ hourNow = parseInt(this._sDialog.tDate.format('H'), 10);
454
+ for (var i = 1, j = 5; i <= 24; i++, j += 5) {
455
+ var div = document.createElement('div'),
456
+ span = document.createElement('span');
457
+
458
+ div.classList.add(cell);
459
+ span.textContent = i;
460
+ div.classList.add(rotate + j);
461
+ if (hourNow === i) {
462
+ div.id = hour;
463
+ div.classList.add(selected);
464
+ needle.classList.add(rotate + j);
465
+ }
466
+ div.appendChild(span);
467
+ docfrag.appendChild(div);
468
+ }
469
+ } else {
470
+ hourNow = parseInt(this._sDialog.tDate.format('h'), 10);
471
+ for (var _i = 1, _j = 10; _i <= 12; _i++, _j += 10) {
472
+ var _div = document.createElement('div'),
473
+ _span = document.createElement('span');
474
+
475
+ _div.classList.add(cell);
476
+ _span.textContent = _i;
477
+ _div.classList.add(rotate + _j);
478
+ if (hourNow === _i) {
479
+ _div.id = hour;
480
+ _div.classList.add(selected);
481
+ needle.classList.add(rotate + _j);
482
+ }
483
+ _div.appendChild(_span);
484
+ docfrag.appendChild(_div);
485
+ }
486
+ }
487
+ //empty the hours
488
+ while (hourView.lastChild) {
489
+ hourView.removeChild(hourView.lastChild);
490
+ }
491
+ // set inner html accordingly
492
+ hourView.appendChild(docfrag);
493
+ }
494
+ }, {
495
+ key: '_initMinute',
496
+ value: function _initMinute() {
497
+ var minuteView = this._sDialog.minuteView,
498
+ minuteNow = parseInt(this._sDialog.tDate.format('m'), 10),
499
+ sMinute = 'mddtp-minute__selected',
500
+ selected = 'mddtp-picker__cell--selected',
501
+ rotate = 'mddtp-picker__cell--rotate-',
502
+ cell = 'mddtp-picker__cell',
503
+ docfrag = document.createDocumentFragment();
504
+
505
+ for (var i = 5, j = 10; i <= 60; i += 5, j += 10) {
506
+ var div = document.createElement('div'),
507
+ span = document.createElement('span');
508
+
509
+ div.classList.add(cell);
510
+ if (i === 60) {
511
+ span.textContent = this._numWithZero(0);
512
+ } else {
513
+ span.textContent = this._numWithZero(i);
514
+ }
515
+ if (minuteNow === 0) {
516
+ minuteNow = 60;
517
+ }
518
+ div.classList.add(rotate + j);
519
+ // (minuteNow === 1 && i === 60) for corner case highlight 00 at 01
520
+ if (minuteNow === i || minuteNow - 1 === i || minuteNow + 1 === i || minuteNow === 1 && i === 60) {
521
+ div.id = sMinute;
522
+ div.classList.add(selected);
523
+ }
524
+ div.appendChild(span);
525
+ docfrag.appendChild(div);
526
+ }
527
+ //empty the hours
528
+ while (minuteView.lastChild) {
529
+ minuteView.removeChild(minuteView.lastChild);
530
+ }
531
+ // set inner html accordingly
532
+ minuteView.appendChild(docfrag);
533
+ }
534
+ }, {
535
+ key: '_initDateDialog',
536
+ value: function _initDateDialog(m) {
537
+ var subtitle = this._sDialog.subtitle,
538
+ title = this._sDialog.title,
539
+ titleDay = this._sDialog.titleDay,
540
+ titleMonth = this._sDialog.titleMonth;
541
+
542
+ this._fillText(subtitle, m.format('YYYY'));
543
+ this._fillText(titleDay, m.format('ddd, '));
544
+ this._fillText(titleMonth, m.format('MMM D'));
545
+ this._initYear();
546
+ this._initViewHolder();
547
+ this._attachEventHandlers();
548
+ this._changeMonth();
549
+ this._switchToView(subtitle);
550
+ this._switchToView(title);
551
+ }
552
+ }, {
553
+ key: '_initViewHolder',
554
+ value: function _initViewHolder() {
555
+ var m = this._sDialog.tDate,
556
+ picker = this._sDialog.picker,
557
+ current = this._sDialog.current,
558
+ previous = this._sDialog.previous,
559
+ next = this._sDialog.next,
560
+ past = this._past,
561
+ future = this._future;
562
+
563
+ if (m.isBefore(past, 'month')) {
564
+ m = past.clone();
565
+ }
566
+ if (m.isAfter(future, 'month')) {
567
+ m = future.clone();
568
+ }
569
+ this._sDialog.tDate = m;
570
+ this._initMonth(current, m);
571
+ this._initMonth(next, moment(this._getMonth(m, 1)));
572
+ this._initMonth(previous, moment(this._getMonth(m, -1)));
573
+ this._toMoveMonth();
574
+ }
575
+ }, {
576
+ key: '_initMonth',
577
+ value: function _initMonth(view, m) {
578
+ var displayMonth = m.format('MMMM YYYY'),
579
+ innerDivs = view.getElementsByTagName('div');
580
+ // get the .mddtp-picker__month element using innerDivs[0]
581
+
582
+ this._fillText(innerDivs[0], displayMonth);
583
+ var docfrag = document.createDocumentFragment(),
584
+ tr = innerDivs[3],
585
+ firstDayOfMonth = parseInt(moment(m).date(1).day(), 10),
586
+ today = -1,
587
+ selected = -1,
588
+ lastDayOfMonth = parseInt(moment(m).endOf('month').format('D'), 10) + firstDayOfMonth - 1,
589
+ past = firstDayOfMonth,
590
+ cellClass = 'mddtp-picker__cell',
591
+ future = lastDayOfMonth;
592
+ // get the .mddtp-picker__tr element using innerDivs[3]
593
+
594
+ if (moment().isSame(m, 'month')) {
595
+ today = parseInt(moment().format('D'), 10);
596
+ today += firstDayOfMonth - 1;
597
+ }
598
+ if (this._past.isSame(m, 'month')) {
599
+ past = parseInt(this._past.format('D'), 10);
600
+ past += firstDayOfMonth - 1;
601
+ }
602
+ if (this._future.isSame(m, 'month')) {
603
+ future = parseInt(this._future.format('D'), 10);
604
+ future += firstDayOfMonth - 1;
605
+ }
606
+ if (this._sDialog.sDate.isSame(m, 'month')) {
607
+ selected = parseInt(moment(m).format('D'), 10);
608
+ selected += firstDayOfMonth - 1;
609
+ }
610
+ for (var i = 0; i < 42; i++) {
611
+ // create cell
612
+ var cell = document.createElement('span'),
613
+ currentDay = i - firstDayOfMonth + 1;
614
+
615
+ if (i >= firstDayOfMonth && i <= lastDayOfMonth) {
616
+ if (i > future || i < past) {
617
+ cell.classList.add(cellClass + '--disabled');
618
+ } else {
619
+ cell.classList.add(cellClass);
620
+ }
621
+ this._fillText(cell, currentDay);
622
+ }
623
+ if (today === i) {
624
+ cell.classList.add(cellClass + '--today');
625
+ }
626
+ if (selected === i) {
627
+ cell.classList.add(cellClass + '--selected');
628
+ cell.id = 'mddtp-date__selected';
629
+ }
630
+ docfrag.appendChild(cell);
631
+ }
632
+ //empty the tr
633
+ while (tr.lastChild) {
634
+ tr.removeChild(tr.lastChild);
635
+ }
636
+ // set inner html accordingly
637
+ tr.appendChild(docfrag);
638
+ this._addCellClickEvent(tr);
639
+ }
640
+ }, {
641
+ key: '_initYear',
642
+ value: function _initYear() {
643
+ var years = this._sDialog.years,
644
+ currentYear = this._sDialog.tDate.year(),
645
+ docfrag = document.createDocumentFragment(),
646
+ past = this._past.year(),
647
+ future = this._future.year();
648
+
649
+ for (var year = past; year <= future; year++) {
650
+ var li = document.createElement('li');
651
+ li.textContent = year;
652
+ if (year === currentYear) {
653
+ li.id = 'mddtp-date__currentYear';
654
+ li.classList.add('mddtp-picker__li--current');
655
+ }
656
+ docfrag.appendChild(li);
657
+ }
658
+ //empty the years ul
659
+ while (years.lastChild) {
660
+ years.removeChild(years.lastChild);
661
+ }
662
+ // set inner html accordingly
663
+ years.appendChild(docfrag);
664
+ // attach event handler to the ul to get the benefit of event delegation
665
+ this._changeYear(years);
666
+ }
667
+ }, {
668
+ key: '_switchToView',
669
+ value: function _switchToView(el) {
670
+ var me = this;
671
+ // attach the view change button
672
+ if (this._type == 'date') {
673
+ el.onclick = function () {
674
+ me._switchToDateView(el, me);
675
+ };
676
+ } else {
677
+ el.onclick = function () {
678
+ me._switchToTimeView(me);
679
+ };
680
+ }
681
+ }
682
+ }, {
683
+ key: '_switchToTimeView',
684
+ value: function _switchToTimeView(me) {
685
+ var hourView = me._sDialog.hourView,
686
+ minuteView = me._sDialog.minuteView,
687
+ hour = me._sDialog.hour,
688
+ minute = me._sDialog.minute,
689
+ activeClass = 'mddtp-picker__color--active',
690
+ hidden = 'mddtp-picker__circularView--hidden',
691
+ selection = 'mddtp-picker__selection',
692
+ needle = me._sDialog.needle,
693
+ circularHolder = me._sDialog.circularHolder,
694
+ circle = me._sDialog.circle,
695
+ fakeNeedle = me._sDialog.fakeNeedle,
696
+ spoke = 60,
697
+ value = void 0;
698
+
699
+ // toggle view classes
700
+ hourView.classList.toggle(hidden);
701
+ minuteView.classList.toggle(hidden);
702
+ hour.classList.toggle(activeClass);
703
+ minute.classList.toggle(activeClass);
704
+ // move the needle to correct position
705
+ needle.className = '';
706
+ needle.classList.add(selection);
707
+ if (mdDateTimePicker.dialog.view) {
708
+ value = me._sDialog.sDate.format('m');
709
+ // move the fakeNeedle to correct position
710
+ setTimeout(function () {
711
+ var hOffset = circularHolder.getBoundingClientRect(),
712
+ cOffset = circle.getBoundingClientRect();
713
+
714
+ fakeNeedle.setAttribute('style', 'left:' + (cOffset.left - hOffset.left) + 'px;top:' + (cOffset.top - hOffset.top) + 'px');
715
+ }, 300);
716
+ } else {
717
+ if (me._mode) {
718
+ spoke = 24;
719
+ value = me._sDialog.sDate.format('H');
720
+ } else {
721
+ spoke = 12;
722
+ value = me._sDialog.sDate.format('h');
723
+ }
724
+ }
725
+ var rotationClass = me._calcRotation(spoke, parseInt(value, 10));
726
+ if (rotationClass) {
727
+ needle.classList.add(rotationClass);
728
+ }
729
+ // toggle the view type
730
+ mdDateTimePicker.dialog.view = !mdDateTimePicker.dialog.view;
731
+ }
732
+ }, {
733
+ key: '_switchToDateView',
734
+ value: function _switchToDateView(el, me) {
735
+ el.setAttribute('disabled', '');
736
+ var viewHolder = me._sDialog.viewHolder,
737
+ years = me._sDialog.years,
738
+ title = me._sDialog.title,
739
+ subtitle = me._sDialog.subtitle,
740
+ currentYear = document.getElementById('mddtp-date__currentYear');
741
+
742
+ if (mdDateTimePicker.dialog.view) {
743
+ viewHolder.classList.add('zoomOut');
744
+ years.classList.remove('mddtp-picker__years--invisible');
745
+ years.classList.add('zoomIn');
746
+ // scroll into the view
747
+ currentYear.scrollIntoViewIfNeeded();
748
+ } else {
749
+ years.classList.add('zoomOut');
750
+ viewHolder.classList.remove('zoomOut');
751
+ viewHolder.classList.add('zoomIn');
752
+ setTimeout(function () {
753
+ years.classList.remove('zoomIn', 'zoomOut');
754
+ years.classList.add('mddtp-picker__years--invisible');
755
+ viewHolder.classList.remove('zoomIn');
756
+ }, 300);
757
+ }
758
+ title.classList.toggle('mddtp-picker__color--active');
759
+ subtitle.classList.toggle('mddtp-picker__color--active');
760
+ mdDateTimePicker.dialog.view = !mdDateTimePicker.dialog.view;
761
+ setTimeout(function () {
762
+ el.removeAttribute('disabled');
763
+ }, 300);
764
+ }
765
+ }, {
766
+ key: '_addClockEvent',
767
+ value: function _addClockEvent() {
768
+ var me = this,
769
+ hourView = this._sDialog.hourView,
770
+ minuteView = this._sDialog.minuteView,
771
+ sClass = 'mddtp-picker__cell--selected';
772
+
773
+ hourView.onclick = function (e) {
774
+ var sHour = 'mddtp-hour__selected',
775
+ selectedHour = document.getElementById(sHour),
776
+ setHour = 0;
777
+
778
+ if (e.target && e.target.nodeName == 'SPAN') {
779
+ // clear the previously selected hour
780
+ selectedHour.id = '';
781
+ selectedHour.classList.remove(sClass);
782
+ // select the new hour
783
+ e.target.parentNode.classList.add(sClass);
784
+ e.target.parentNode.id = sHour;
785
+ // set the sDate according to 24 or 12 hour mode
786
+ if (me._mode) {
787
+ setHour = e.target.textContent;
788
+ } else {
789
+ if (me._sDialog.sDate.format('A') === 'AM') {
790
+ setHour = e.target.textContent;
791
+ } else {
792
+ setHour = parseInt(e.target.textContent, 10) + 12;
793
+ }
794
+ }
795
+ me._sDialog.sDate.hour(setHour);
796
+ // set the display hour
797
+ me._sDialog.hour.textContent = e.target.textContent;
798
+ // switch the view
799
+ me._switchToTimeView(me);
800
+ }
801
+ };
802
+ minuteView.onclick = function (e) {
803
+ var sMinute = 'mddtp-minute__selected',
804
+ selectedMinute = document.getElementById(sMinute),
805
+ setMinute = 0;
806
+
807
+ if (e.target && e.target.nodeName == 'SPAN') {
808
+ // clear the previously selected hour
809
+ if (selectedMinute) {
810
+ selectedMinute.id = '';
811
+ selectedMinute.classList.remove(sClass);
812
+ }
813
+ // select the new hour
814
+ e.target.parentNode.classList.add(sClass);
815
+ e.target.parentNode.id = sMinute;
816
+ // set the sDate minute
817
+ setMinute = e.target.textContent;
818
+ me._sDialog.sDate.minute(setMinute);
819
+ // set the display minute
820
+ me._sDialog.minute.textContent = setMinute;
821
+ // switch the view
822
+ me._switchToTimeView(me);
823
+ }
824
+ };
825
+ }
826
+ }, {
827
+ key: '_addCellClickEvent',
828
+ value: function _addCellClickEvent(el) {
829
+ var me = this;
830
+ el.onclick = function (e) {
831
+ if (e.target && e.target.nodeName == 'SPAN' && e.target.classList.contains('mddtp-picker__cell')) {
832
+ var picker = me._sDialog.picker,
833
+ day = e.target.textContent,
834
+ currentDate = me._sDialog.tDate.date(day),
835
+ sId = 'mddtp-date__selected',
836
+ sClass = 'mddtp-picker__cell--selected',
837
+ selected = document.getElementById(sId),
838
+ subtitle = me._sDialog.subtitle,
839
+ titleDay = me._sDialog.titleDay,
840
+ titleMonth = me._sDialog.titleMonth;
841
+
842
+ if (selected) {
843
+ selected.classList.remove(sClass);
844
+ selected.id = '';
845
+ }
846
+ e.target.classList.add(sClass);
847
+ e.target.id = sId;
848
+
849
+ // update temp date object with the date selected
850
+ me._sDialog.sDate = currentDate.clone();
851
+
852
+ me._fillText(subtitle, currentDate.year());
853
+ me._fillText(titleDay, currentDate.format('ddd, '));
854
+ me._fillText(titleMonth, currentDate.format('MMM D'));
855
+ }
856
+ };
857
+ }
858
+ }, {
859
+ key: '_toMoveMonth',
860
+ value: function _toMoveMonth() {
861
+ var m = this._sDialog.tDate,
862
+ left = this._sDialog.left,
863
+ right = this._sDialog.right,
864
+ past = this._past,
865
+ future = this._future;
866
+
867
+ left.removeAttribute('disabled');
868
+ right.removeAttribute('disabled');
869
+ left.classList.remove('mddtp-button--disabled');
870
+ right.classList.remove('mddtp-button--disabled');
871
+ if (m.isSame(past, 'month')) {
872
+ left.setAttribute('disabled', '');
873
+ left.classList.add('mddtp-button--disabled');
874
+ }
875
+ if (m.isSame(future, 'month')) {
876
+ right.setAttribute('disabled', '');
877
+ right.classList.add('mddtp-button--disabled');
878
+ }
879
+ }
880
+ }, {
881
+ key: '_changeMonth',
882
+ value: function _changeMonth() {
883
+ var me = this,
884
+ left = this._sDialog.left,
885
+ right = this._sDialog.right,
886
+ mLeftClass = 'mddtp-picker__view--left',
887
+ mRightClass = 'mddtp-picker__view--right',
888
+ pause = 'mddtp-picker__view--pause';
889
+
890
+ left.onclick = function () {
891
+ moveStep(mRightClass, me._sDialog.previous);
892
+ };
893
+
894
+ right.onclick = function () {
895
+ moveStep(mLeftClass, me._sDialog.next);
896
+ };
897
+
898
+ function moveStep(aClass, to) {
899
+ /**
900
+ * [stepBack to know if the to step is going back or not]
901
+ *
902
+ * @type {Boolean}
903
+ */
904
+ var stepBack = !1,
905
+ next = me._sDialog.next,
906
+ current = me._sDialog.current,
907
+ previous = me._sDialog.previous;
908
+
909
+ left.setAttribute('disabled', '');
910
+ right.setAttribute('disabled', '');
911
+ current.classList.add(aClass);
912
+ previous.classList.add(aClass);
913
+ next.classList.add(aClass);
914
+ var clone = to.cloneNode(!0),
915
+ del = void 0;
916
+
917
+ if (to === next) {
918
+ del = previous;
919
+ current.parentNode.appendChild(clone);
920
+ next.id = current.id;
921
+ current.id = previous.id;
922
+ previous = current;
923
+ current = next;
924
+ next = clone;
925
+ } else {
926
+ stepBack = !0;
927
+ del = next;
928
+ previous.id = current.id;
929
+ current.id = next.id;
930
+ next = current;
931
+ current = previous;
932
+ }
933
+ setTimeout(function () {
934
+ if (to === previous) {
935
+ current.parentNode.insertBefore(clone, current);
936
+ previous = clone;
937
+ }
938
+ // update real values to match these values
939
+ me._sDialog.next = next;
940
+ me._sDialog.current = current;
941
+ me._sDialog.previous = previous;
942
+ current.classList.add(pause);
943
+ next.classList.add(pause);
944
+ previous.classList.add(pause);
945
+ current.classList.remove(aClass);
946
+ next.classList.remove(aClass);
947
+ previous.classList.remove(aClass);
948
+ del.parentNode.removeChild(del);
949
+ }, 300);
950
+ // REVIEW replace below code with requestAnimationFrame
951
+ setTimeout(function () {
952
+ current.classList.remove(pause);
953
+ next.classList.remove(pause);
954
+ previous.classList.remove(pause);
955
+ if (stepBack) {
956
+ me._sDialog.tDate = me._getMonth(me._sDialog.tDate, -1);
957
+ } else {
958
+ me._sDialog.tDate = me._getMonth(me._sDialog.tDate, 1);
959
+ }
960
+ me._initViewHolder();
961
+ }, 350);
962
+ setTimeout(function () {
963
+ if (!left.classList.contains('mddtp-button--disabled')) {
964
+ left.removeAttribute('disabled');
965
+ }
966
+ if (!right.classList.contains('mddtp-button--disabled')) {
967
+ right.removeAttribute('disabled');
968
+ }
969
+ }, 400);
970
+ }
971
+ }
972
+ }, {
973
+ key: '_changeYear',
974
+ value: function _changeYear(el) {
975
+ var me = this;
976
+ el.onclick = function (e) {
977
+ if (e.target && e.target.nodeName == 'LI') {
978
+ var selected = document.getElementById('mddtp-date__currentYear');
979
+ // clear previous selected
980
+ selected.id = '';
981
+ selected.classList.remove('mddtp-picker__li--current');
982
+ // add the properties to the newer one
983
+ e.target.id = 'mddtp-date__currentYear';
984
+ e.target.classList.add('mddtp-picker__li--current');
985
+ // switch view
986
+ me._switchToDateView(el, me);
987
+ // set the tdate to it
988
+ me._sDialog.tDate.year(parseInt(e.target.textContent, 10));
989
+ // update the dialog
990
+ me._initViewHolder();
991
+ }
992
+ };
993
+ }
994
+ }, {
995
+ key: '_changeM',
996
+ value: function _changeM() {
997
+ var me = this,
998
+ AM = this._sDialog.AM,
999
+ PM = this._sDialog.PM;
1000
+
1001
+ AM.onclick = function (e) {
1002
+ var m = me._sDialog.sDate.format('A');
1003
+ if (m === 'PM') {
1004
+ me._sDialog.sDate.subtract(12, 'h');
1005
+ AM.classList.toggle('mddtp-picker__color--active');
1006
+ PM.classList.toggle('mddtp-picker__color--active');
1007
+ }
1008
+ };
1009
+ PM.onclick = function (e) {
1010
+ var m = me._sDialog.sDate.format('A');
1011
+ if (m === 'AM') {
1012
+ me._sDialog.sDate.add(12, 'h');
1013
+ AM.classList.toggle('mddtp-picker__color--active');
1014
+ PM.classList.toggle('mddtp-picker__color--active');
1015
+ }
1016
+ };
1017
+ }
1018
+ }, {
1019
+ key: '_dragDial',
1020
+ value: function _dragDial() {
1021
+ var me = this,
1022
+ needle = this._sDialog.needle,
1023
+ circle = this._sDialog.circle,
1024
+ fakeNeedle = this._sDialog.fakeNeedle,
1025
+ circularHolder = this._sDialog.circularHolder,
1026
+ minute = this._sDialog.minute,
1027
+ quick = 'mddtp-picker__selection--quick',
1028
+ selection = 'mddtp-picker__selection',
1029
+ selected = 'mddtp-picker__cell--selected',
1030
+ rotate = 'mddtp-picker__cell--rotate-',
1031
+ hOffset = circularHolder.getBoundingClientRect(),
1032
+ divides = void 0,
1033
+ fakeNeedleDraggabilly = new Draggabilly(fakeNeedle, {
1034
+ containment: !0
1035
+ });
1036
+
1037
+ fakeNeedleDraggabilly.on('pointerDown', function () {
1038
+ hOffset = circularHolder.getBoundingClientRect();
1039
+ });
1040
+ fakeNeedleDraggabilly.on('dragMove', function (e) {
1041
+ var xPos = e.clientX - hOffset.left - hOffset.width / 2,
1042
+ yPos = e.clientY - hOffset.top - hOffset.height / 2,
1043
+ slope = Math.atan2(-yPos, xPos);
1044
+
1045
+ needle.className = '';
1046
+ if (slope < 0) {
1047
+ slope += 2 * Math.PI;
1048
+ }
1049
+ slope *= 180 / Math.PI;
1050
+ slope = 360 - slope;
1051
+ if (slope > 270) {
1052
+ slope -= 360;
1053
+ }
1054
+ divides = parseInt(slope / 6);
1055
+ var same = Math.abs(6 * divides - slope),
1056
+ upper = Math.abs(6 * (divides + 1) - slope);
1057
+
1058
+ if (upper < same) {
1059
+ divides++;
1060
+ }
1061
+ divides += 15;
1062
+ needle.classList.add(selection);
1063
+ needle.classList.add(quick);
1064
+ needle.classList.add(rotate + divides * 2);
1065
+ });
1066
+ fakeNeedleDraggabilly.on('dragEnd', function () {
1067
+ var minuteViewChildren = me._sDialog.minuteView.getElementsByTagName('div'),
1068
+ sMinute = 'mddtp-minute__selected',
1069
+ selectedMinute = document.getElementById(sMinute),
1070
+ cOffset = circle.getBoundingClientRect();
1071
+
1072
+ fakeNeedle.setAttribute('style', 'left:' + (cOffset.left - hOffset.left) + 'px;top:' + (cOffset.top - hOffset.top) + 'px');
1073
+ needle.classList.remove(quick);
1074
+ var select = divides;
1075
+ if (select === 1) {
1076
+ select = 60;
1077
+ }
1078
+ select = me._nearestDivisor(select, 5);
1079
+ // normalize 60 => 0
1080
+ if (divides === 60) {
1081
+ divides = 0;
1082
+ }
1083
+ // remove previously selected value
1084
+ if (selectedMinute) {
1085
+ selectedMinute.id = '';
1086
+ selectedMinute.classList.remove(selected);
1087
+ }
1088
+ // add the new selected
1089
+ if (select > 0) {
1090
+ select /= 5;
1091
+ select--;
1092
+ minuteViewChildren[select].id = sMinute;
1093
+ minuteViewChildren[select].classList.add(selected);
1094
+ }
1095
+ minute.textContent = me._numWithZero(divides);
1096
+ me._sDialog.sDate.minutes(divides);
1097
+ });
1098
+ }
1099
+ }, {
1100
+ key: '_attachEventHandlers',
1101
+ value: function _attachEventHandlers() {
1102
+ var me = this,
1103
+ ok = this._sDialog.ok,
1104
+ cancel = this._sDialog.cancel,
1105
+ onCancel = new CustomEvent('onCancel'),
1106
+ onOk = new CustomEvent('onOk');
1107
+ // create cutom events to dispatch
1108
+
1109
+ cancel.onclick = function () {
1110
+ me.toggle();
1111
+ if (me._trigger) {
1112
+ me._trigger.dispatchEvent(onCancel);
1113
+ }
1114
+ };
1115
+ ok.onclick = function () {
1116
+ me._init = me._sDialog.sDate;
1117
+ me.toggle();
1118
+ if (me._trigger) {
1119
+ me._trigger.dispatchEvent(onOk);
1120
+ }
1121
+ };
1122
+ }
1123
+ }, {
1124
+ key: '_getMonth',
1125
+ value: function _getMonth(moment, count) {
1126
+ var m = void 0;
1127
+ m = moment.clone();
1128
+ if (count > 0) {
1129
+ return m.add(Math.abs(count), 'M');
1130
+ } else {
1131
+ return m.subtract(Math.abs(count), 'M');
1132
+ }
1133
+ }
1134
+ }, {
1135
+ key: '_nearestDivisor',
1136
+ value: function _nearestDivisor(number, divided) {
1137
+ if (number % divided === 0) {
1138
+ return number;
1139
+ } else if ((number - 1) % divided === 0) {
1140
+ return number - 1;
1141
+ } else if ((number + 1) % divided === 0) {
1142
+ return number + 1;
1143
+ }
1144
+ return -1;
1145
+ }
1146
+ }, {
1147
+ key: '_numWithZero',
1148
+ value: function _numWithZero(n) {
1149
+ return n > 9 ? '' + n : '0' + n;
1150
+ }
1151
+ }, {
1152
+ key: '_fillText',
1153
+ value: function _fillText(el, text) {
1154
+ if (el.firstChild) {
1155
+ el.firstChild.nodeValue = text;
1156
+ } else {
1157
+ el.appendChild(document.createTextNode(text));
1158
+ }
1159
+ }
1160
+ }, {
1161
+ key: '_addId',
1162
+ value: function _addId(el, id) {
1163
+ el.id = 'mddtp-' + this._type + '__' + id;
1164
+ }
1165
+ }, {
1166
+ key: '_addClass',
1167
+ value: function _addClass(el, aClass, more) {
1168
+ el.classList.add('mddtp-picker__' + aClass);
1169
+ var i = 0;
1170
+ if (more) {
1171
+ i = more.length;
1172
+ more.reverse();
1173
+ }
1174
+ while (i--) {
1175
+ el.classList.add(more[i]);
1176
+ }
1177
+ }
1178
+ }, {
1179
+ key: '_addView',
1180
+ value: function _addView(view) {
1181
+ var month = document.createElement('div'),
1182
+ grid = document.createElement('div'),
1183
+ th = document.createElement('div'),
1184
+ tr = document.createElement('div'),
1185
+ weekDays = ['S', 'F', 'T', 'W', 'T', 'M', 'S'],
1186
+ week = 7;
1187
+
1188
+ while (week--) {
1189
+ var span = document.createElement('span');
1190
+ span.textContent = weekDays[week];
1191
+ th.appendChild(span);
1192
+ }
1193
+ // add properties to them
1194
+ this._addClass(month, 'month');
1195
+ this._addClass(grid, 'grid');
1196
+ this._addClass(th, 'th');
1197
+ this._addClass(tr, 'tr');
1198
+ // add them to the view
1199
+ view.appendChild(month);
1200
+ view.appendChild(grid);
1201
+ grid.appendChild(th);
1202
+ grid.appendChild(tr);
1203
+ }
1204
+ }, {
1205
+ key: '_calcRotation',
1206
+ value: function _calcRotation(spoke, value) {
1207
+ var start = spoke / 12 * 3;
1208
+ // set clocks top and right side value
1209
+ if (spoke === 12) {
1210
+ value *= 10;
1211
+ } else if (spoke === 24) {
1212
+ value *= 5;
1213
+ } else {
1214
+ value *= 2;
1215
+ }
1216
+ // special case for 00 => 60
1217
+ if (spoke === 60 && value === 0) {
1218
+ value = 120;
1219
+ }
1220
+ return 'mddtp-picker__cell--rotate-' + value;
1221
+ }
1222
+ }, {
1223
+ key: 'time',
1224
+ get: function get() {
1225
+ return this._init;
1226
+ },
1227
+ set: function set(m) {
1228
+ if (m) {
1229
+ this._init = m;
1230
+ }
1231
+ }
1232
+ }, {
1233
+ key: 'trigger',
1234
+ get: function get() {
1235
+ return this._trigger;
1236
+ },
1237
+ set: function set(el) {
1238
+ if (el) {
1239
+ this._trigger = el;
1240
+ }
1241
+ }
1242
+ }], [{
1243
+ key: 'dialog',
1244
+ get: function get() {
1245
+ return _dialog;
1246
+ }
1247
+ }]);
1248
+
1249
+ return mdDateTimePicker;
1250
+ }();
1251
+
1252
+ exports.default = mdDateTimePicker;
1253
+ });