materialize-sass 0.100.2.1 → 1.0.0.alpha1

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