materialize-sass 0.98.2 → 0.99.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +10 -1
  4. data/Rakefile +21 -3
  5. data/app/assets/fonts/roboto/Roboto-Bold.woff +0 -0
  6. data/app/assets/fonts/roboto/Roboto-Bold.woff2 +0 -0
  7. data/app/assets/fonts/roboto/Roboto-Light.woff +0 -0
  8. data/app/assets/fonts/roboto/Roboto-Light.woff2 +0 -0
  9. data/app/assets/fonts/roboto/Roboto-Medium.woff +0 -0
  10. data/app/assets/fonts/roboto/Roboto-Medium.woff2 +0 -0
  11. data/app/assets/fonts/roboto/Roboto-Regular.woff +0 -0
  12. data/app/assets/fonts/roboto/Roboto-Regular.woff2 +0 -0
  13. data/app/assets/fonts/roboto/Roboto-Thin.woff +0 -0
  14. data/app/assets/fonts/roboto/Roboto-Thin.woff2 +0 -0
  15. data/app/assets/javascripts/materialize-sprockets.js +2 -1
  16. data/app/assets/javascripts/materialize.js +9045 -5
  17. data/app/assets/javascripts/materialize/buttons.js +1 -1
  18. data/app/assets/javascripts/materialize/cards.js +13 -3
  19. data/app/assets/javascripts/materialize/carousel.js +33 -12
  20. data/app/assets/javascripts/materialize/character_counter.js +1 -1
  21. data/app/assets/javascripts/materialize/chips.js +8 -5
  22. data/app/assets/javascripts/materialize/collapsible.js +1 -1
  23. data/app/assets/javascripts/materialize/date_picker/picker.date.js +137 -136
  24. data/app/assets/javascripts/materialize/date_picker/picker.js +0 -1
  25. data/app/assets/javascripts/materialize/date_picker/picker.time.js +686 -0
  26. data/app/assets/javascripts/materialize/dropdown.js +17 -10
  27. data/app/assets/javascripts/materialize/extras/nouislider.js +1 -1
  28. data/app/assets/javascripts/materialize/extras/nouislider.min.js +1 -1
  29. data/app/assets/javascripts/materialize/forms.js +18 -12
  30. data/app/assets/javascripts/materialize/init.js +1 -0
  31. data/app/assets/javascripts/materialize/jquery.easing.1.4.js +166 -0
  32. data/app/assets/javascripts/materialize/materialbox.js +26 -17
  33. data/app/assets/javascripts/materialize/modal.js +2 -1
  34. data/app/assets/javascripts/materialize/scrollspy.js +11 -6
  35. data/app/assets/javascripts/materialize/sideNav.js +43 -13
  36. data/app/assets/javascripts/materialize/slider.js +3 -3
  37. data/app/assets/javascripts/materialize/tabs.js +10 -3
  38. data/app/assets/javascripts/materialize/tooltip.js +1 -1
  39. data/app/assets/javascripts/materialize/transitions.js +3 -3
  40. data/app/assets/javascripts/materialize/waves.js +1 -1
  41. data/app/assets/stylesheets/materialize.scss +0 -1
  42. data/app/assets/stylesheets/materialize/components/_buttons.scss +3 -8
  43. data/app/assets/stylesheets/materialize/components/_collapsible.scss +1 -0
  44. data/app/assets/stylesheets/materialize/components/_color.scss +1 -1
  45. data/app/assets/stylesheets/materialize/components/_global.scss +20 -20
  46. data/app/assets/stylesheets/materialize/components/_modal.scss +2 -2
  47. data/app/assets/stylesheets/materialize/components/_sideNav.scss +2 -0
  48. data/app/assets/stylesheets/materialize/components/_variables.scss +13 -4
  49. data/app/assets/stylesheets/materialize/components/date_picker/_default.date.scss +48 -27
  50. data/app/assets/stylesheets/materialize/components/date_picker/_default.scss +10 -0
  51. data/app/assets/stylesheets/materialize/components/date_picker/_default.time.scss +155 -13
  52. data/app/assets/stylesheets/materialize/components/forms/_input-fields.scss +12 -11
  53. data/app/assets/stylesheets/materialize/components/forms/_switches.scss +30 -17
  54. data/app/assets/stylesheets/materialize/extras/nouislider.css +1 -1
  55. data/lib/materialize-sass/version.rb +1 -1
  56. metadata +4 -14
  57. data/app/assets/fonts/roboto/Roboto-Bold.eot +0 -0
  58. data/app/assets/fonts/roboto/Roboto-Bold.ttf +0 -0
  59. data/app/assets/fonts/roboto/Roboto-Light.eot +0 -0
  60. data/app/assets/fonts/roboto/Roboto-Light.ttf +0 -0
  61. data/app/assets/fonts/roboto/Roboto-Medium.eot +0 -0
  62. data/app/assets/fonts/roboto/Roboto-Medium.ttf +0 -0
  63. data/app/assets/fonts/roboto/Roboto-Regular.eot +0 -0
  64. data/app/assets/fonts/roboto/Roboto-Regular.ttf +0 -0
  65. data/app/assets/fonts/roboto/Roboto-Thin.eot +0 -0
  66. data/app/assets/fonts/roboto/Roboto-Thin.ttf +0 -0
  67. data/app/assets/javascripts/materialize/jquery.easing.1.3.js +0 -205
  68. data/app/assets/stylesheets/materialize/components/_prefixer.scss +0 -384
@@ -1120,4 +1120,3 @@ return PickerConstructor
1120
1120
 
1121
1121
  }));
1122
1122
 
1123
-
@@ -0,0 +1,686 @@
1
+ /*!
2
+ * ClockPicker v0.0.7 (http://weareoutman.github.io/clockpicker/)
3
+ * Copyright 2014 Wang Shenwei.
4
+ * Licensed under MIT (https://github.com/weareoutman/clockpicker/blob/gh-pages/LICENSE)
5
+ *
6
+ * Further modified
7
+ * Copyright 2015 Ching Yaw Hao.
8
+ */
9
+
10
+ ;(function(){
11
+ var $ = window.jQuery,
12
+ $win = $(window),
13
+ $doc = $(document);
14
+
15
+ // Can I use inline svg ?
16
+ var svgNS = 'http://www.w3.org/2000/svg',
17
+ svgSupported = 'SVGAngle' in window && (function() {
18
+ var supported,
19
+ el = document.createElement('div');
20
+ el.innerHTML = '<svg/>';
21
+ supported = (el.firstChild && el.firstChild.namespaceURI) == svgNS;
22
+ el.innerHTML = '';
23
+ return supported;
24
+ })();
25
+
26
+ // Can I use transition ?
27
+ var transitionSupported = (function() {
28
+ var style = document.createElement('div').style;
29
+ return 'transition' in style ||
30
+ 'WebkitTransition' in style ||
31
+ 'MozTransition' in style ||
32
+ 'msTransition' in style ||
33
+ 'OTransition' in style;
34
+ })();
35
+
36
+ // Listen touch events in touch screen device, instead of mouse events in desktop.
37
+ var touchSupported = 'ontouchstart' in window,
38
+ mousedownEvent = 'mousedown' + ( touchSupported ? ' touchstart' : ''),
39
+ mousemoveEvent = 'mousemove.clockpicker' + ( touchSupported ? ' touchmove.clockpicker' : ''),
40
+ mouseupEvent = 'mouseup.clockpicker' + ( touchSupported ? ' touchend.clockpicker' : '');
41
+
42
+ // Vibrate the device if supported
43
+ var vibrate = navigator.vibrate ? 'vibrate' : navigator.webkitVibrate ? 'webkitVibrate' : null;
44
+
45
+ function createSvgElement(name) {
46
+ return document.createElementNS(svgNS, name);
47
+ }
48
+
49
+ function leadingZero(num) {
50
+ return (num < 10 ? '0' : '') + num;
51
+ }
52
+
53
+ // Get a unique id
54
+ var idCounter = 0;
55
+ function uniqueId(prefix) {
56
+ var id = ++idCounter + '';
57
+ return prefix ? prefix + id : id;
58
+ }
59
+
60
+ // Clock size
61
+ var dialRadius = 135,
62
+ outerRadius = 105,
63
+ // innerRadius = 80 on 12 hour clock
64
+ innerRadius = 80,
65
+ tickRadius = 20,
66
+ diameter = dialRadius * 2,
67
+ duration = transitionSupported ? 350 : 1;
68
+
69
+ // Popover template
70
+ var tpl = [
71
+ '<div class="clockpicker picker">',
72
+ '<div class="picker__holder">',
73
+ '<div class="picker__frame">',
74
+ '<div class="picker__wrap">',
75
+ '<div class="picker__box">',
76
+ '<div class="picker__date-display">',
77
+ '<div class="clockpicker-display">',
78
+ '<div class="clockpicker-display-column">',
79
+ '<span class="clockpicker-span-hours text-primary"></span>',
80
+ ':',
81
+ '<span class="clockpicker-span-minutes"></span>',
82
+ '</div>',
83
+ '<div class="clockpicker-display-column clockpicker-display-am-pm">',
84
+ '<div class="clockpicker-span-am-pm"></div>',
85
+ '</div>',
86
+ '</div>',
87
+ '</div>',
88
+ '<div class="picker__container__wrapper">',
89
+ '<div class="picker__calendar-container">',
90
+ '<div class="clockpicker-plate">',
91
+ '<div class="clockpicker-canvas"></div>',
92
+ '<div class="clockpicker-dial clockpicker-hours"></div>',
93
+ '<div class="clockpicker-dial clockpicker-minutes clockpicker-dial-out"></div>',
94
+ '</div>',
95
+ '<div class="clockpicker-am-pm-block">',
96
+ '</div>',
97
+ '</div>',
98
+ '<div class="picker__footer">',
99
+ '</div>',
100
+ '</div>',
101
+ '</div>',
102
+ '</div>',
103
+ '</div>',
104
+ '</div>',
105
+ '</div>'
106
+ ].join('');
107
+
108
+ // ClockPicker
109
+ function ClockPicker(element, options) {
110
+ var popover = $(tpl),
111
+ plate = popover.find('.clockpicker-plate'),
112
+ holder = popover.find('.picker__holder'),
113
+ hoursView = popover.find('.clockpicker-hours'),
114
+ minutesView = popover.find('.clockpicker-minutes'),
115
+ amPmBlock = popover.find('.clockpicker-am-pm-block'),
116
+ isInput = element.prop('tagName') === 'INPUT',
117
+ input = isInput ? element : element.find('input'),
118
+ label = $("label[for=" + input.attr("id") + "]"),
119
+ self = this;
120
+
121
+ this.id = uniqueId('cp');
122
+ this.element = element;
123
+ this.holder = holder;
124
+ this.options = options;
125
+ this.isAppended = false;
126
+ this.isShown = false;
127
+ this.currentView = 'hours';
128
+ this.isInput = isInput;
129
+ this.input = input;
130
+ this.label = label;
131
+ this.popover = popover;
132
+ this.plate = plate;
133
+ this.hoursView = hoursView;
134
+ this.minutesView = minutesView;
135
+ this.amPmBlock = amPmBlock;
136
+ this.spanHours = popover.find('.clockpicker-span-hours');
137
+ this.spanMinutes = popover.find('.clockpicker-span-minutes');
138
+ this.spanAmPm = popover.find('.clockpicker-span-am-pm');
139
+ this.footer = popover.find('.picker__footer');
140
+ this.amOrPm = "PM";
141
+
142
+ // Setup for for 12 hour clock if option is selected
143
+ if (options.twelvehour) {
144
+ if (!options.ampmclickable) {
145
+ this.spanAmPm.empty();
146
+ $('<div id="click-am">AM</div>').appendTo(this.spanAmPm);
147
+ $('<div id="click-pm">PM</div>').appendTo(this.spanAmPm);
148
+ }
149
+ else {
150
+ this.spanAmPm.empty();
151
+ $('<div id="click-am">AM</div>').on("click", function() {
152
+ self.spanAmPm.children('#click-am').addClass("text-primary");
153
+ self.spanAmPm.children('#click-pm').removeClass("text-primary");
154
+ self.amOrPm = "AM";
155
+ }).appendTo(this.spanAmPm);
156
+ $('<div id="click-pm">PM</div>').on("click", function() {
157
+ self.spanAmPm.children('#click-pm').addClass("text-primary");
158
+ self.spanAmPm.children('#click-am').removeClass("text-primary");
159
+ self.amOrPm = 'PM';
160
+ }).appendTo(this.spanAmPm);
161
+ }
162
+ }
163
+
164
+ // Add buttons to footer
165
+ $('<button type="button" class="btn-flat picker__clear" tabindex="' + (options.twelvehour? '3' : '1') + '">' + options.cleartext + '</button>').click($.proxy(this.clear, this)).appendTo(this.footer);
166
+ $('<button type="button" class="btn-flat picker__close" tabindex="' + (options.twelvehour? '3' : '1') + '">' + options.canceltext + '</button>').click($.proxy(this.hide, this)).appendTo(this.footer);
167
+ $('<button type="button" class="btn-flat picker__close" tabindex="' + (options.twelvehour? '3' : '1') + '">' + options.donetext + '</button>').click($.proxy(this.done, this)).appendTo(this.footer);
168
+
169
+ this.spanHours.click($.proxy(this.toggleView, this, 'hours'));
170
+ this.spanMinutes.click($.proxy(this.toggleView, this, 'minutes'));
171
+
172
+ // Show or toggle
173
+ input.on('focus.clockpicker click.clockpicker', $.proxy(this.show, this));
174
+
175
+ // Build ticks
176
+ var tickTpl = $('<div class="clockpicker-tick"></div>'),
177
+ i, tick, radian, radius;
178
+
179
+ // Hours view
180
+ if (options.twelvehour) {
181
+ for (i = 1; i < 13; i += 1) {
182
+ tick = tickTpl.clone();
183
+ radian = i / 6 * Math.PI;
184
+ radius = outerRadius;
185
+ tick.css({
186
+ left: dialRadius + Math.sin(radian) * radius - tickRadius,
187
+ top: dialRadius - Math.cos(radian) * radius - tickRadius
188
+ });
189
+ tick.html(i === 0 ? '00' : i);
190
+ hoursView.append(tick);
191
+ tick.on(mousedownEvent, mousedown);
192
+ }
193
+ } else {
194
+ for (i = 0; i < 24; i += 1) {
195
+ tick = tickTpl.clone();
196
+ radian = i / 6 * Math.PI;
197
+ var inner = i > 0 && i < 13;
198
+ radius = inner ? innerRadius : outerRadius;
199
+ tick.css({
200
+ left: dialRadius + Math.sin(radian) * radius - tickRadius,
201
+ top: dialRadius - Math.cos(radian) * radius - tickRadius
202
+ });
203
+ tick.html(i === 0 ? '00' : i);
204
+ hoursView.append(tick);
205
+ tick.on(mousedownEvent, mousedown);
206
+ }
207
+ }
208
+
209
+ // Minutes view
210
+ for (i = 0; i < 60; i += 5) {
211
+ tick = tickTpl.clone();
212
+ radian = i / 30 * Math.PI;
213
+ tick.css({
214
+ left: dialRadius + Math.sin(radian) * outerRadius - tickRadius,
215
+ top: dialRadius - Math.cos(radian) * outerRadius - tickRadius
216
+ });
217
+ tick.html(leadingZero(i));
218
+ minutesView.append(tick);
219
+ tick.on(mousedownEvent, mousedown);
220
+ }
221
+
222
+ // Clicking on minutes view space
223
+ plate.on(mousedownEvent, function(e) {
224
+ if ($(e.target).closest('.clockpicker-tick').length === 0) {
225
+ mousedown(e, true);
226
+ }
227
+ });
228
+
229
+ // Mousedown or touchstart
230
+ function mousedown(e, space) {
231
+ var offset = plate.offset(),
232
+ isTouch = /^touch/.test(e.type),
233
+ x0 = offset.left + dialRadius,
234
+ y0 = offset.top + dialRadius,
235
+ dx = (isTouch ? e.originalEvent.touches[0] : e).pageX - x0,
236
+ dy = (isTouch ? e.originalEvent.touches[0] : e).pageY - y0,
237
+ z = Math.sqrt(dx * dx + dy * dy),
238
+ moved = false;
239
+
240
+ // When clicking on minutes view space, check the mouse position
241
+ if (space && (z < outerRadius - tickRadius || z > outerRadius + tickRadius)) {
242
+ return;
243
+ }
244
+ e.preventDefault();
245
+
246
+ // Set cursor style of body after 200ms
247
+ var movingTimer = setTimeout(function(){
248
+ self.popover.addClass('clockpicker-moving');
249
+ }, 200);
250
+
251
+ // Clock
252
+ self.setHand(dx, dy, !space, true);
253
+
254
+ // Mousemove on document
255
+ $doc.off(mousemoveEvent).on(mousemoveEvent, function(e){
256
+ e.preventDefault();
257
+ var isTouch = /^touch/.test(e.type),
258
+ x = (isTouch ? e.originalEvent.touches[0] : e).pageX - x0,
259
+ y = (isTouch ? e.originalEvent.touches[0] : e).pageY - y0;
260
+ if (! moved && x === dx && y === dy) {
261
+ // Clicking in chrome on windows will trigger a mousemove event
262
+ return;
263
+ }
264
+ moved = true;
265
+ self.setHand(x, y, false, true);
266
+ });
267
+
268
+ // Mouseup on document
269
+ $doc.off(mouseupEvent).on(mouseupEvent, function(e) {
270
+ $doc.off(mouseupEvent);
271
+ e.preventDefault();
272
+ var isTouch = /^touch/.test(e.type),
273
+ x = (isTouch ? e.originalEvent.changedTouches[0] : e).pageX - x0,
274
+ y = (isTouch ? e.originalEvent.changedTouches[0] : e).pageY - y0;
275
+ if ((space || moved) && x === dx && y === dy) {
276
+ self.setHand(x, y);
277
+ }
278
+
279
+ if (self.currentView === 'hours') {
280
+ self.toggleView('minutes', duration / 2);
281
+ } else if (options.autoclose) {
282
+ self.minutesView.addClass('clockpicker-dial-out');
283
+ setTimeout(function(){
284
+ self.done();
285
+ }, duration / 2);
286
+ }
287
+ plate.prepend(canvas);
288
+
289
+ // Reset cursor style of body
290
+ clearTimeout(movingTimer);
291
+ self.popover.removeClass('clockpicker-moving');
292
+
293
+ // Unbind mousemove event
294
+ $doc.off(mousemoveEvent);
295
+ });
296
+ }
297
+
298
+ if (svgSupported) {
299
+ // Draw clock hands and others
300
+ var canvas = popover.find('.clockpicker-canvas'),
301
+ svg = createSvgElement('svg');
302
+ svg.setAttribute('class', 'clockpicker-svg');
303
+ svg.setAttribute('width', diameter);
304
+ svg.setAttribute('height', diameter);
305
+ var g = createSvgElement('g');
306
+ g.setAttribute('transform', 'translate(' + dialRadius + ',' + dialRadius + ')');
307
+ var bearing = createSvgElement('circle');
308
+ bearing.setAttribute('class', 'clockpicker-canvas-bearing');
309
+ bearing.setAttribute('cx', 0);
310
+ bearing.setAttribute('cy', 0);
311
+ bearing.setAttribute('r', 4);
312
+ var hand = createSvgElement('line');
313
+ hand.setAttribute('x1', 0);
314
+ hand.setAttribute('y1', 0);
315
+ var bg = createSvgElement('circle');
316
+ bg.setAttribute('class', 'clockpicker-canvas-bg');
317
+ bg.setAttribute('r', tickRadius);
318
+ g.appendChild(hand);
319
+ g.appendChild(bg);
320
+ g.appendChild(bearing);
321
+ svg.appendChild(g);
322
+ canvas.append(svg);
323
+
324
+ this.hand = hand;
325
+ this.bg = bg;
326
+ this.bearing = bearing;
327
+ this.g = g;
328
+ this.canvas = canvas;
329
+ }
330
+
331
+ raiseCallback(this.options.init);
332
+ }
333
+
334
+ function raiseCallback(callbackFunction) {
335
+ if (callbackFunction && typeof callbackFunction === "function")
336
+ callbackFunction();
337
+ }
338
+
339
+ // Default options
340
+ ClockPicker.DEFAULTS = {
341
+ 'default': '', // default time, 'now' or '13:14' e.g.
342
+ fromnow: 0, // set default time to * milliseconds from now (using with default = 'now')
343
+ donetext: 'Ok', // done button text
344
+ cleartext: 'Clear',
345
+ canceltext: 'Cancel',
346
+ autoclose: false, // auto close when minute is selected
347
+ ampmclickable: true, // set am/pm button on itself
348
+ darktheme: false, // set to dark theme
349
+ twelvehour: true, // change to 12 hour AM/PM clock from 24 hour
350
+ vibrate: true // vibrate the device when dragging clock hand
351
+ };
352
+
353
+ // Show or hide popover
354
+ ClockPicker.prototype.toggle = function() {
355
+ this[this.isShown ? 'hide' : 'show']();
356
+ };
357
+
358
+ // Set popover position
359
+ ClockPicker.prototype.locate = function() {
360
+ var element = this.element,
361
+ popover = this.popover,
362
+ offset = element.offset(),
363
+ width = element.outerWidth(),
364
+ height = element.outerHeight(),
365
+ align = this.options.align,
366
+ self = this;
367
+
368
+ popover.show();
369
+ };
370
+
371
+ // Show popover
372
+ ClockPicker.prototype.show = function(e){
373
+ // Not show again
374
+ if (this.isShown) {
375
+ return;
376
+ }
377
+ raiseCallback(this.options.beforeShow);
378
+ $(':input').each(function() {
379
+ $(this).attr('tabindex', -1);
380
+ })
381
+ var self = this;
382
+ // Initialize
383
+ this.input.blur();
384
+ this.popover.addClass('picker--opened');
385
+ this.input.addClass('picker__input picker__input--active');
386
+ $(document.body).css('overflow', 'hidden');
387
+ // Get the time
388
+ var value = ((this.input.prop('value') || this.options['default'] || '') + '').split(':');
389
+ if (this.options.twelvehour && !(typeof value[1] === 'undefined')) {
390
+ if (value[1].indexOf("AM") > 0){
391
+ this.amOrPm = 'AM';
392
+ } else {
393
+ this.amOrPm = 'PM';
394
+ }
395
+ value[1] = value[1].replace("AM", "").replace("PM", "");
396
+ }
397
+ if (value[0] === 'now') {
398
+ var now = new Date(+ new Date() + this.options.fromnow);
399
+ value = [
400
+ now.getHours(),
401
+ now.getMinutes()
402
+ ];
403
+ }
404
+ this.hours = + value[0] || 0;
405
+ this.minutes = + value[1] || 0;
406
+ this.spanHours.html(this.hours);
407
+ this.spanMinutes.html(leadingZero(this.minutes));
408
+ if (!this.isAppended) {
409
+ // Append popover to body
410
+ this.popover.insertAfter(this.input);
411
+ if (this.options.twelvehour) {
412
+ if (this.amOrPm === 'PM'){
413
+ this.spanAmPm.children('#click-pm').addClass("text-primary");
414
+ this.spanAmPm.children('#click-am').removeClass("text-primary");
415
+ } else {
416
+ this.spanAmPm.children('#click-am').addClass("text-primary");
417
+ this.spanAmPm.children('#click-pm').removeClass("text-primary");
418
+ }
419
+ }
420
+ // Reset position when resize
421
+ $win.on('resize.clockpicker' + this.id, function() {
422
+ if (self.isShown) {
423
+ self.locate();
424
+ }
425
+ });
426
+ this.isAppended = true;
427
+ }
428
+ // Toggle to hours view
429
+ this.toggleView('hours');
430
+ // Set position
431
+ this.locate();
432
+ this.isShown = true;
433
+ // Hide when clicking or tabbing on any element except the clock and input
434
+ $doc.on('click.clockpicker.' + this.id + ' focusin.clockpicker.' + this.id, function(e) {
435
+ var target = $(e.target);
436
+ if (target.closest(self.popover.find('.picker__wrap')).length === 0 && target.closest(self.input).length === 0) {
437
+ self.hide();
438
+ }
439
+ });
440
+ // Hide when ESC is pressed
441
+ $doc.on('keyup.clockpicker.' + this.id, function(e){
442
+ if (e.keyCode === 27) {
443
+ self.hide();
444
+ }
445
+ });
446
+ raiseCallback(this.options.afterShow);
447
+ };
448
+ // Hide popover
449
+ ClockPicker.prototype.hide = function() {
450
+ raiseCallback(this.options.beforeHide);
451
+ this.input.removeClass('picker__input picker__input--active');
452
+ this.popover.removeClass('picker--opened');
453
+ $(document.body).css('overflow', 'visible');
454
+ this.isShown = false;
455
+ $(':input').each(function(index) {
456
+ $(this).attr('tabindex', index + 1);
457
+ });
458
+ // Unbinding events on document
459
+ $doc.off('click.clockpicker.' + this.id + ' focusin.clockpicker.' + this.id);
460
+ $doc.off('keyup.clockpicker.' + this.id);
461
+ this.popover.hide();
462
+ raiseCallback(this.options.afterHide);
463
+ };
464
+ // Toggle to hours or minutes view
465
+ ClockPicker.prototype.toggleView = function(view, delay) {
466
+ var raiseAfterHourSelect = false;
467
+ if (view === 'minutes' && $(this.hoursView).css("visibility") === "visible") {
468
+ raiseCallback(this.options.beforeHourSelect);
469
+ raiseAfterHourSelect = true;
470
+ }
471
+ var isHours = view === 'hours',
472
+ nextView = isHours ? this.hoursView : this.minutesView,
473
+ hideView = isHours ? this.minutesView : this.hoursView;
474
+ this.currentView = view;
475
+
476
+ this.spanHours.toggleClass('text-primary', isHours);
477
+ this.spanMinutes.toggleClass('text-primary', ! isHours);
478
+
479
+ // Let's make transitions
480
+ hideView.addClass('clockpicker-dial-out');
481
+ nextView.css('visibility', 'visible').removeClass('clockpicker-dial-out');
482
+
483
+ // Reset clock hand
484
+ this.resetClock(delay);
485
+
486
+ // After transitions ended
487
+ clearTimeout(this.toggleViewTimer);
488
+ this.toggleViewTimer = setTimeout(function() {
489
+ hideView.css('visibility', 'hidden');
490
+ }, duration);
491
+
492
+ if (raiseAfterHourSelect) {
493
+ raiseCallback(this.options.afterHourSelect);
494
+ }
495
+ };
496
+
497
+ // Reset clock hand
498
+ ClockPicker.prototype.resetClock = function(delay) {
499
+ var view = this.currentView,
500
+ value = this[view],
501
+ isHours = view === 'hours',
502
+ unit = Math.PI / (isHours ? 6 : 30),
503
+ radian = value * unit,
504
+ radius = isHours && value > 0 && value < 13 ? innerRadius : outerRadius,
505
+ x = Math.sin(radian) * radius,
506
+ y = - Math.cos(radian) * radius,
507
+ self = this;
508
+
509
+ if (svgSupported && delay) {
510
+ self.canvas.addClass('clockpicker-canvas-out');
511
+ setTimeout(function(){
512
+ self.canvas.removeClass('clockpicker-canvas-out');
513
+ self.setHand(x, y);
514
+ }, delay);
515
+ } else
516
+ this.setHand(x, y);
517
+ };
518
+
519
+ // Set clock hand to (x, y)
520
+ ClockPicker.prototype.setHand = function(x, y, roundBy5, dragging) {
521
+ var radian = Math.atan2(x, - y),
522
+ isHours = this.currentView === 'hours',
523
+ unit = Math.PI / (isHours || roundBy5? 6 : 30),
524
+ z = Math.sqrt(x * x + y * y),
525
+ options = this.options,
526
+ inner = isHours && z < (outerRadius + innerRadius) / 2,
527
+ radius = inner ? innerRadius : outerRadius,
528
+ value;
529
+
530
+ if (options.twelvehour) {
531
+ radius = outerRadius;
532
+ }
533
+
534
+ // Radian should in range [0, 2PI]
535
+ if (radian < 0) {
536
+ radian = Math.PI * 2 + radian;
537
+ }
538
+
539
+ // Get the round value
540
+ value = Math.round(radian / unit);
541
+
542
+ // Get the round radian
543
+ radian = value * unit;
544
+
545
+ // Correct the hours or minutes
546
+ if (options.twelvehour) {
547
+ if (isHours) {
548
+ if (value === 0)
549
+ value = 12;
550
+ } else {
551
+ if (roundBy5)
552
+ value *= 5;
553
+ if (value === 60)
554
+ value = 0;
555
+ }
556
+ } else {
557
+ if (isHours) {
558
+ if (value === 12)
559
+ value = 0;
560
+ value = inner ? (value === 0 ? 12 : value) : value === 0 ? 0 : value + 12;
561
+ } else {
562
+ if (roundBy5)
563
+ value *= 5;
564
+ if (value === 60)
565
+ value = 0;
566
+ }
567
+ }
568
+
569
+ // Once hours or minutes changed, vibrate the device
570
+ if (this[this.currentView] !== value) {
571
+ if (vibrate && this.options.vibrate) {
572
+ // Do not vibrate too frequently
573
+ if (!this.vibrateTimer) {
574
+ navigator[vibrate](10);
575
+ this.vibrateTimer = setTimeout($.proxy(function(){
576
+ this.vibrateTimer = null;
577
+ }, this), 100);
578
+ }
579
+ }
580
+ }
581
+
582
+ this[this.currentView] = value;
583
+ if (isHours) {
584
+ this['spanHours'].html(value);
585
+ } else {
586
+ this['spanMinutes'].html(leadingZero(value));
587
+ }
588
+
589
+ // If svg is not supported, just add an active class to the tick
590
+ if (!svgSupported) {
591
+ this[isHours ? 'hoursView' : 'minutesView'].find('.clockpicker-tick').each(function(){
592
+ var tick = $(this);
593
+ tick.toggleClass('active', value === + tick.html());
594
+ });
595
+ return;
596
+ }
597
+
598
+ // Set clock hand and others' position
599
+ var cx1 = Math.sin(radian) * (radius - tickRadius),
600
+ cy1 = - Math.cos(radian) * (radius - tickRadius),
601
+ cx2 = Math.sin(radian) * radius,
602
+ cy2 = - Math.cos(radian) * radius;
603
+ this.hand.setAttribute('x2', cx1);
604
+ this.hand.setAttribute('y2', cy1);
605
+ this.bg.setAttribute('cx', cx2);
606
+ this.bg.setAttribute('cy', cy2);
607
+ };
608
+
609
+ // Hours and minutes are selected
610
+ ClockPicker.prototype.done = function() {
611
+ raiseCallback(this.options.beforeDone);
612
+ this.hide();
613
+ this.label.addClass('active');
614
+
615
+ var last = this.input.prop('value'),
616
+ value = leadingZero(this.hours) + ':' + leadingZero(this.minutes);
617
+ if (this.options.twelvehour) {
618
+ value = value + this.amOrPm;
619
+ }
620
+
621
+ this.input.prop('value', value);
622
+ if (value !== last) {
623
+ this.input.triggerHandler('change');
624
+ if (!this.isInput) {
625
+ this.element.trigger('change');
626
+ }
627
+ }
628
+
629
+ if (this.options.autoclose)
630
+ this.input.trigger('blur');
631
+
632
+ raiseCallback(this.options.afterDone);
633
+ };
634
+
635
+ // Clear input field
636
+ ClockPicker.prototype.clear = function() {
637
+ this.hide();
638
+ this.label.removeClass('active');
639
+
640
+ var last = this.input.prop('value'),
641
+ value = '';
642
+
643
+ this.input.prop('value', value);
644
+ if (value !== last) {
645
+ this.input.triggerHandler('change');
646
+ if (! this.isInput) {
647
+ this.element.trigger('change');
648
+ }
649
+ }
650
+
651
+ if (this.options.autoclose) {
652
+ this.input.trigger('blur');
653
+ }
654
+ };
655
+
656
+ // Remove clockpicker from input
657
+ ClockPicker.prototype.remove = function() {
658
+ this.element.removeData('clockpicker');
659
+ this.input.off('focus.clockpicker click.clockpicker');
660
+ if (this.isShown) {
661
+ this.hide();
662
+ }
663
+ if (this.isAppended) {
664
+ $win.off('resize.clockpicker' + this.id);
665
+ this.popover.remove();
666
+ }
667
+ };
668
+
669
+ // Extends $.fn.clockpicker
670
+ $.fn.pickatime = function(option){
671
+ var args = Array.prototype.slice.call(arguments, 1);
672
+ return this.each(function(){
673
+ var $this = $(this),
674
+ data = $this.data('clockpicker');
675
+ if (!data) {
676
+ var options = $.extend({}, ClockPicker.DEFAULTS, $this.data(), typeof option == 'object' && option);
677
+ $this.data('clockpicker', new ClockPicker($this, options));
678
+ } else {
679
+ // Manual operatsions. show, hide, remove, e.g.
680
+ if (typeof data[option] === 'function') {
681
+ data[option].apply(data, args);
682
+ }
683
+ }
684
+ });
685
+ };
686
+ }());