dlegr250_material_design 0.5.67 → 0.5.68

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50d44d6a7663208d8d2352be34fa2be664e59f3a
4
- data.tar.gz: ccf5e38e6460d17a5c2dac2676f125fa8ed4173f
3
+ metadata.gz: 62fd685d4bae4450d96665a38c7bc4cbc226f5c9
4
+ data.tar.gz: 819034bac31f7102ac82e05b68cc3aeeeb817ed4
5
5
  SHA512:
6
- metadata.gz: 1a2ffdb0c946069b5392cf662f6049c60a87c8125d8f30c8796dac6458b328dd6f8207f8f0e0efb92d52659d7f3ca253eef429998d378eb4cdf756128eb6f4a2
7
- data.tar.gz: 172376e999f6339d67c73b486a273ba4a116bd6861401c727c2d00f226c710425892931e765daa7778b0929ff57c89c4e49e264120d601e683e93209ff079d9e
6
+ metadata.gz: 57100618fdf0e113d3f5c36e36fd386c79255540e7b7cad44c3a81b6799e83ba4f61b9f7386f94b5b84f3c1fa7c34084dfa1affadcec07aea5b2bd779b7c4e81
7
+ data.tar.gz: 3023bb1b29cc3ca1f0a50af5631b7e21028406a36b697726a7a83acf882a0ab96a8bf0e2812068e7bc1d92197853caf3576086cf022369488c1afced47db30fe
@@ -1,3 +1,3 @@
1
1
  module Dlegr250MaterialDesign
2
- VERSION = "0.5.67"
2
+ VERSION = "0.5.68"
3
3
  end
@@ -146,15 +146,19 @@ $default-rounded-corners-radius: 3px;
146
146
  // Flexbox
147
147
  //----------------------------------------------------------------------
148
148
 
149
+ @mixin flex-parent() {
150
+ display: flex;
151
+ display: -ms-flexbox;
152
+ display: -webkit-flex;
153
+ }
154
+
149
155
  // For a row of flex elements, such as the appbar.
150
156
  @mixin flex-parent-row() {
157
+ @include flex-parent();
151
158
  align-items: center;
152
159
  -ms-flex-align: center;
153
160
  -webkit-align-items: center;
154
161
  -webkit-box-align: center;
155
- display: flex;
156
- display: -ms-flexbox;
157
- display: -webkit-flex;
158
162
  flex-direction: row;
159
163
  flex-wrap: nowrap;
160
164
  justify-content: flex-start;
@@ -182,13 +186,11 @@ $default-rounded-corners-radius: 3px;
182
186
 
183
187
  // Center elements vertically and horizontally
184
188
  @mixin flex-center() {
189
+ @include flex-parent();
185
190
  align-items: center;
186
191
  -ms-flex-align: center;
187
192
  -webkit-align-items: center;
188
193
  -webkit-box-align: center;
189
- display: flex;
190
- display: -ms-flexbox;
191
- display: -webkit-flex;
192
194
  flex-direction: column;
193
195
  flex-wrap: nowrap;
194
196
  justify-content: center;
@@ -198,13 +200,11 @@ $default-rounded-corners-radius: 3px;
198
200
 
199
201
  // Grid list
200
202
  @mixin flex-grid-list() {
203
+ @include flex-parent();
201
204
  align-items: flex-start;
202
205
  -ms-flex-align: flex-start;
203
206
  -webkit-align-items: flex-start;
204
207
  -webkit-box-align: flex-start;
205
- display: flex;
206
- display: -ms-flexbox;
207
- display: -webkit-flex;
208
208
  flex-direction: row;
209
209
  flex-wrap: wrap;
210
210
  }
@@ -10,8 +10,11 @@ $application-container-min-width: 300px;
10
10
  // Dimensions - appbar
11
11
  //----------------------------------------------------------------------
12
12
 
13
- $appbar-height: 64px;
14
- $appbar-button-height: 48px;
13
+ $appbar-height-small: 56px !default; // Small devices
14
+ $appbar-height-medium: 64px !default; // Medium to large devices
15
+ $appbar-height: $appbar-height-medium !default;
16
+
17
+ $appbar-button-height: 48px !default;
15
18
 
16
19
  // Dimensions - sidebars
17
20
  //----------------------------------------------------------------------
@@ -80,8 +83,7 @@ $button-height-large: 56px;
80
83
 
81
84
  $button-icon-height: $button-height;
82
85
 
83
- $button-fab-mini-height: $button-icon-height;
84
- $button-fab-height: $button-height-large;
86
+ $button-fab-height: 56px;
85
87
 
86
88
  // Dimensions - inputs (text-fields, etc...)
87
89
  //----------------------------------------------------------------------
@@ -118,9 +120,22 @@ $spacing-normal: 16px;
118
120
  $spacing-large: 24px;
119
121
  $spacing-xlarge: 32px;
120
122
 
121
- // Depth (z-index)
123
+ // Elevation (z-index)
124
+ // See: https://material.io/guidelines/material-design/elevation-shadows.html#elevation-shadows-elevation-android
122
125
  //----------------------------------------------------------------------
123
126
 
127
+ $elevation-1: 1;
128
+ $elevation-2: 2;
129
+ $elevation-3: 3;
130
+ $elevation-4: 4;
131
+ $elevation-6: 6;
132
+ $elevation-8: 8;
133
+ $elevation-9: 9;
134
+ $elevation-12: 12;
135
+ $elevation-16: 16;
136
+ $elevation-24: 24;
137
+
138
+ // DEPRECATED: USE ELEVATION VARIABLES
124
139
  $layout-depth: 10;
125
140
  $menu-depth: 20;
126
141
  $overlay-depth: 30;
@@ -130,7 +145,13 @@ $dialog-depth: 50;
130
145
  // Device breakpoints
131
146
  //----------------------------------------------------------------------
132
147
 
133
- $width-small: 400px;
134
- $width-medium: 760px;
135
- $width-large: 1000px;
136
- $width-xlarge: 1200px;
148
+ $device-small: 400px;
149
+ $device-medium: 760px;
150
+ $device-large: 1000px;
151
+ $device-xlarge: 1200px;
152
+
153
+ // DEPRECATED: USE DEVICE VARIABLES
154
+ $width-small: $device-small;
155
+ $width-medium: $device-medium;
156
+ $width-large: $device-large;
157
+ $width-xlarge: $device-xlarge;
@@ -15,7 +15,8 @@
15
15
  color: color("white");
16
16
  content: attr(data-tooltip);
17
17
  font-family: "Roboto", sans-serif;
18
- font-size: $font-size-small;
18
+ font-size: $font-size-small !important;
19
+ font-weight: bold !important;
19
20
  left: 50%;
20
21
  line-height: normal;
21
22
  padding: $spacing-small;
@@ -26,6 +27,7 @@
26
27
  visibility: hidden;
27
28
  white-space: nowrap;
28
29
  z-index: 2;
30
+ @include font-smoothing();
29
31
  @include rounded-corners;
30
32
  @include transform(translateX(-50%) translateY(10%));
31
33
  @include transition(opacity 0.2s ease, transform 0.2s ease);
@@ -1,7 +1,11 @@
1
- // Base (load order is important)
1
+ //======================================================================
2
+ // Manifest file for stylesheets.
3
+ // Load order is IMPORTANT!
4
+ //======================================================================
5
+
6
+ // Base
2
7
  //----------------------------------------------------------------------
3
8
 
4
- @import "fonts/material_design_iconic_font";
5
9
  @import "fonts/google_material_design_icons";
6
10
 
7
11
  @import "base/normalize";
@@ -13,10 +17,7 @@
13
17
  // Layouts
14
18
  //----------------------------------------------------------------------
15
19
 
16
- @import "layouts/application/base";
17
- @import "layouts/application/appbar";
18
- @import "layouts/application/sidebars";
19
- @import "layouts/application/main";
20
+ // TODO: currently in Rails app
20
21
 
21
22
  // Components
22
23
  //----------------------------------------------------------------------
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dlegr250_material_design
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.67
4
+ version: 0.5.68
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel LeGrand
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-21 00:00:00.000000000 Z
11
+ date: 2017-04-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'WARNING: ALPHA CODE, NOT PRODUCTION READY. ACTIVELY UNDER DEVELOPMENT
14
14
  AS OF AUG 2016. Implement Google Material Design spec with modern browsers in mind
@@ -37,7 +37,6 @@ files:
37
37
  - lib/dlegr250_material_design.rb
38
38
  - lib/dlegr250_material_design/version.rb
39
39
  - vendor/assets/javascripts/base/init.js.coffee
40
- - vendor/assets/javascripts/components/clockpicker.coffee
41
40
  - vendor/assets/javascripts/components/combobox.coffee
42
41
  - vendor/assets/javascripts/components/datepicker.coffee
43
42
  - vendor/assets/javascripts/components/dialog.coffee
@@ -63,7 +62,6 @@ files:
63
62
  - vendor/assets/javascripts/third_party/autosize.min.3.0.20.js
64
63
  - vendor/assets/javascripts/third_party/handlebars.latest.js
65
64
  - vendor/assets/javascripts/third_party/jquery.autonumeric.1-9-44.js
66
- - vendor/assets/javascripts/third_party/jquery.clockpicker.js
67
65
  - vendor/assets/javascripts/third_party/jquery.inputmask.min.3.2.8-11.js
68
66
  - vendor/assets/javascripts/third_party/jquery.scroll_scope.min.0.1.0.js
69
67
  - vendor/assets/javascripts/third_party/moment.min.2.17.1.js
@@ -126,16 +124,6 @@ files:
126
124
  - vendor/assets/stylesheets/fonts/google_material_design_icons/MaterialIcons-Regular.ttf
127
125
  - vendor/assets/stylesheets/fonts/google_material_design_icons/MaterialIcons-Regular.woff
128
126
  - vendor/assets/stylesheets/fonts/google_material_design_icons/MaterialIcons-Regular.woff2
129
- - vendor/assets/stylesheets/fonts/material_design_iconic_font.scss
130
- - vendor/assets/stylesheets/fonts/material_design_iconic_font/Material-Design-Iconic-Font.eot
131
- - vendor/assets/stylesheets/fonts/material_design_iconic_font/Material-Design-Iconic-Font.svg
132
- - vendor/assets/stylesheets/fonts/material_design_iconic_font/Material-Design-Iconic-Font.ttf
133
- - vendor/assets/stylesheets/fonts/material_design_iconic_font/Material-Design-Iconic-Font.woff
134
- - vendor/assets/stylesheets/fonts/material_design_iconic_font/Material-Design-Iconic-Font.woff2
135
- - vendor/assets/stylesheets/layouts/application/appbar.scss
136
- - vendor/assets/stylesheets/layouts/application/base.scss
137
- - vendor/assets/stylesheets/layouts/application/main.scss
138
- - vendor/assets/stylesheets/layouts/application/sidebars.scss
139
127
  homepage: http://www.github.com/dlegr250/dlegr250_material_design
140
128
  licenses: []
141
129
  metadata: {}
@@ -1,31 +0,0 @@
1
- class App.MD.Clockpicker
2
- @init: () ->
3
- # TODO DEPRECATE
4
- $.map $("[role='clockpicker']"), (element, index) ->
5
- new App.MD.Clockpicker(element)
6
-
7
- $.map $("[data-behavior='clockpicker']"), (element, index) ->
8
- new App.MD.Clockpicker(element)
9
-
10
- constructor: (element, options = {}) ->
11
- @$element = $(element)
12
-
13
- # Do not re-run on elements that already have clockpickers
14
- if @$element.attr("data-has-clockpicker") == "true"
15
- return
16
- else
17
- @options = $.extend({}, @defaultOptions(), options)
18
- @init()
19
-
20
- init: () ->
21
- @$element.clockpicker(@options)
22
- @$element.attr("data-has-clockpicker", true)
23
-
24
- defaultOptions: () ->
25
- {
26
- donetext: "Select",
27
- twelvehour: true,
28
- autoclose: false,
29
- placement: "bottom",
30
- align: "left",
31
- }
@@ -1,737 +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
-
7
- ;(function(){
8
- var $ = window.jQuery,
9
- $win = $(window),
10
- $doc = $(document),
11
- $body;
12
-
13
- // Can I use inline svg ?
14
- var svgNS = 'http://www.w3.org/2000/svg',
15
- svgSupported = 'SVGAngle' in window && (function(){
16
- var supported,
17
- el = document.createElement('div');
18
- el.innerHTML = '<svg/>';
19
- supported = (el.firstChild && el.firstChild.namespaceURI) == svgNS;
20
- el.innerHTML = '';
21
- return supported;
22
- })();
23
-
24
- // Can I use transition ?
25
- var transitionSupported = (function(){
26
- var style = document.createElement('div').style;
27
- return 'transition' in style ||
28
- 'WebkitTransition' in style ||
29
- 'MozTransition' in style ||
30
- 'msTransition' in style ||
31
- 'OTransition' in style;
32
- })();
33
-
34
- // Listen touch events in touch screen device, instead of mouse events in desktop.
35
- var touchSupported = 'ontouchstart' in window,
36
- mousedownEvent = 'mousedown' + ( touchSupported ? ' touchstart' : ''),
37
- mousemoveEvent = 'mousemove.clockpicker' + ( touchSupported ? ' touchmove.clockpicker' : ''),
38
- mouseupEvent = 'mouseup.clockpicker' + ( touchSupported ? ' touchend.clockpicker' : '');
39
-
40
- // Vibrate the device if supported
41
- var vibrate = navigator.vibrate ? 'vibrate' : navigator.webkitVibrate ? 'webkitVibrate' : null;
42
-
43
- function createSvgElement(name) {
44
- return document.createElementNS(svgNS, name);
45
- }
46
-
47
- function leadingZero(num) {
48
- return (num < 10 ? '0' : '') + num;
49
- }
50
-
51
- // Get a unique id
52
- var idCounter = 0;
53
- function uniqueId(prefix) {
54
- var id = ++idCounter + '';
55
- return prefix ? prefix + id : id;
56
- }
57
-
58
- // Clock size
59
- var dialRadius = 100,
60
- outerRadius = 80,
61
- // innerRadius = 80 on 12 hour clock
62
- innerRadius = 54,
63
- tickRadius = 13,
64
- diameter = dialRadius * 2,
65
- duration = transitionSupported ? 350 : 1;
66
-
67
- // Popover template
68
- var tpl = [
69
- '<div class="popover clockpicker-popover">',
70
- // '<div class="arrow"></div>',
71
- '<div class="popover-title">',
72
- '<span class="clockpicker-span-hours text-primary"></span>',
73
- ' : ',
74
- '<span class="clockpicker-span-minutes"></span>',
75
- ' <span class="clockpicker-span-am-pm"></span>',
76
- '</div>',
77
- '<div class="popover-content">',
78
- '<div class="clockpicker-plate">',
79
- '<div class="clockpicker-canvas"></div>',
80
- '<div class="clockpicker-dial clockpicker-hours"></div>',
81
- '<div class="clockpicker-dial clockpicker-minutes clockpicker-dial-out"></div>',
82
- '</div>',
83
- '<span class="clockpicker-am-pm-block">',
84
- '</span>',
85
- '</div>',
86
- '</div>'
87
- ].join('');
88
-
89
- // ClockPicker
90
- function ClockPicker(element, options) {
91
- var popover = $(tpl),
92
- plate = popover.find('.clockpicker-plate'),
93
- hoursView = popover.find('.clockpicker-hours'),
94
- minutesView = popover.find('.clockpicker-minutes'),
95
- amPmBlock = popover.find('.clockpicker-am-pm-block'),
96
- isInput = element.prop('tagName') === 'INPUT',
97
- input = isInput ? element : element.find('input'),
98
- addon = element.find('.input-group-addon'),
99
- self = this,
100
- timer;
101
-
102
- this.id = uniqueId('cp');
103
- this.element = element;
104
- this.options = options;
105
- this.isAppended = false;
106
- this.isShown = false;
107
- this.currentView = 'hours';
108
- this.isInput = isInput;
109
- this.input = input;
110
- this.addon = addon;
111
- this.popover = popover;
112
- this.plate = plate;
113
- this.hoursView = hoursView;
114
- this.minutesView = minutesView;
115
- this.amPmBlock = amPmBlock;
116
- this.spanHours = popover.find('.clockpicker-span-hours');
117
- this.spanMinutes = popover.find('.clockpicker-span-minutes');
118
- this.spanAmPm = popover.find('.clockpicker-span-am-pm');
119
- this.amOrPm = "PM";
120
-
121
- // Setup for for 12 hour clock if option is selected
122
- if (options.twelvehour) {
123
-
124
- var amPmButtonsTemplate = ['<div class="clockpicker-am-pm-block">',
125
- '<button type="button" class="btn btn-sm btn-default clockpicker-button clockpicker-am-button">',
126
- 'AM</button>',
127
- '<button type="button" class="btn btn-sm btn-default clockpicker-button clockpicker-pm-button">',
128
- 'PM</button>',
129
- '</div>'].join('');
130
-
131
- var amPmButtons = $(amPmButtonsTemplate);
132
- //amPmButtons.appendTo(plate);
133
-
134
- ////Not working b/c they are not shown when this runs
135
- //$('clockpicker-am-button')
136
- // .on("click", function() {
137
- // self.amOrPm = "AM";
138
- // $('.clockpicker-span-am-pm').empty().append('AM');
139
- // });
140
- //
141
- //$('clockpicker-pm-button')
142
- // .on("click", function() {
143
- // self.amOrPm = "PM";
144
- // $('.clockpicker-span-am-pm').empty().append('PM');
145
- // });
146
-
147
- $('<button type="button" class="btn btn-sm btn-default clockpicker-button am-button">' + "AM" + '</button>')
148
- .on("click", function() {
149
- self.amOrPm = "AM";
150
- $('.clockpicker-span-am-pm').empty().append('AM');
151
- }).appendTo(this.amPmBlock);
152
-
153
-
154
- $('<button type="button" class="btn btn-sm btn-default clockpicker-button pm-button">' + "PM" + '</button>')
155
- .on("click", function() {
156
- self.amOrPm = 'PM';
157
- $('.clockpicker-span-am-pm').empty().append('PM');
158
- }).appendTo(this.amPmBlock);
159
-
160
- }
161
-
162
- if (! options.autoclose) {
163
- // If autoclose is not setted, append a button
164
- $('<button type="button" class="btn btn-sm btn-default btn-block clockpicker-button">' + options.donetext + '</button>')
165
- .click($.proxy(this.done, this))
166
- .appendTo(popover);
167
- }
168
-
169
- // Placement and arrow align - make sure they make sense.
170
- if ((options.placement === 'top' || options.placement === 'bottom') && (options.align === 'top' || options.align === 'bottom')) options.align = 'left';
171
- if ((options.placement === 'left' || options.placement === 'right') && (options.align === 'left' || options.align === 'right')) options.align = 'top';
172
-
173
- popover.addClass(options.placement);
174
- popover.addClass('clockpicker-align-' + options.align);
175
-
176
- this.spanHours.click($.proxy(this.toggleView, this, 'hours'));
177
- this.spanMinutes.click($.proxy(this.toggleView, this, 'minutes'));
178
-
179
- // Show or toggle
180
- input.on('focus.clockpicker click.clockpicker', $.proxy(this.show, this));
181
- addon.on('click.clockpicker', $.proxy(this.toggle, this));
182
-
183
- // Build ticks
184
- var tickTpl = $('<div class="clockpicker-tick"></div>'),
185
- i, tick, radian, radius;
186
-
187
- // Hours view
188
- if (options.twelvehour) {
189
- for (i = 1; i < 13; i += 1) {
190
- tick = tickTpl.clone();
191
- radian = i / 6 * Math.PI;
192
- radius = outerRadius;
193
- tick.css('font-size', '120%');
194
- tick.css({
195
- left: dialRadius + Math.sin(radian) * radius - tickRadius,
196
- top: dialRadius - Math.cos(radian) * radius - tickRadius
197
- });
198
- tick.html(i === 0 ? '00' : i);
199
- hoursView.append(tick);
200
- tick.on(mousedownEvent, mousedown);
201
- }
202
- } else {
203
- for (i = 0; i < 24; i += 1) {
204
- tick = tickTpl.clone();
205
- radian = i / 6 * Math.PI;
206
- var inner = i > 0 && i < 13;
207
- radius = inner ? innerRadius : outerRadius;
208
- tick.css({
209
- left: dialRadius + Math.sin(radian) * radius - tickRadius,
210
- top: dialRadius - Math.cos(radian) * radius - tickRadius
211
- });
212
- if (inner) {
213
- tick.css('font-size', '120%');
214
- }
215
- tick.html(i === 0 ? '00' : i);
216
- hoursView.append(tick);
217
- tick.on(mousedownEvent, mousedown);
218
- }
219
- }
220
-
221
- // Minutes view
222
- for (i = 0; i < 60; i += 5) {
223
- tick = tickTpl.clone();
224
- radian = i / 30 * Math.PI;
225
- tick.css({
226
- left: dialRadius + Math.sin(radian) * outerRadius - tickRadius,
227
- top: dialRadius - Math.cos(radian) * outerRadius - tickRadius
228
- });
229
- tick.css('font-size', '120%');
230
- tick.html(leadingZero(i));
231
- minutesView.append(tick);
232
- tick.on(mousedownEvent, mousedown);
233
- }
234
-
235
- // Clicking on minutes view space
236
- plate.on(mousedownEvent, function(e){
237
- if ($(e.target).closest('.clockpicker-tick').length === 0) {
238
- mousedown(e, true);
239
- }
240
- });
241
-
242
- // Mousedown or touchstart
243
- function mousedown(e, space) {
244
- var offset = plate.offset(),
245
- isTouch = /^touch/.test(e.type),
246
- x0 = offset.left + dialRadius,
247
- y0 = offset.top + dialRadius,
248
- dx = (isTouch ? e.originalEvent.touches[0] : e).pageX - x0,
249
- dy = (isTouch ? e.originalEvent.touches[0] : e).pageY - y0,
250
- z = Math.sqrt(dx * dx + dy * dy),
251
- moved = false;
252
-
253
- // When clicking on minutes view space, check the mouse position
254
- if (space && (z < outerRadius - tickRadius || z > outerRadius + tickRadius)) {
255
- return;
256
- }
257
- e.preventDefault();
258
-
259
- // Set cursor style of body after 200ms
260
- var movingTimer = setTimeout(function(){
261
- $body.addClass('clockpicker-moving');
262
- }, 200);
263
-
264
- // Place the canvas to top
265
- if (svgSupported) {
266
- plate.append(self.canvas);
267
- }
268
-
269
- // Clock
270
- self.setHand(dx, dy, ! space, true);
271
-
272
- // Mousemove on document
273
- $doc.off(mousemoveEvent).on(mousemoveEvent, function(e){
274
- e.preventDefault();
275
- var isTouch = /^touch/.test(e.type),
276
- x = (isTouch ? e.originalEvent.touches[0] : e).pageX - x0,
277
- y = (isTouch ? e.originalEvent.touches[0] : e).pageY - y0;
278
- if (! moved && x === dx && y === dy) {
279
- // Clicking in chrome on windows will trigger a mousemove event
280
- return;
281
- }
282
- moved = true;
283
- self.setHand(x, y, false, true);
284
- });
285
-
286
- // Mouseup on document
287
- $doc.off(mouseupEvent).on(mouseupEvent, function(e){
288
- $doc.off(mouseupEvent);
289
- e.preventDefault();
290
- var isTouch = /^touch/.test(e.type),
291
- x = (isTouch ? e.originalEvent.changedTouches[0] : e).pageX - x0,
292
- y = (isTouch ? e.originalEvent.changedTouches[0] : e).pageY - y0;
293
- if ((space || moved) && x === dx && y === dy) {
294
- self.setHand(x, y);
295
- }
296
- if (self.currentView === 'hours') {
297
- self.toggleView('minutes', duration / 2);
298
- } else {
299
- if (options.autoclose) {
300
- self.minutesView.addClass('clockpicker-dial-out');
301
- setTimeout(function(){
302
- self.done();
303
- }, duration / 2);
304
- }
305
- }
306
- plate.prepend(canvas);
307
-
308
- // Reset cursor style of body
309
- clearTimeout(movingTimer);
310
- $body.removeClass('clockpicker-moving');
311
-
312
- // Unbind mousemove event
313
- $doc.off(mousemoveEvent);
314
- });
315
- }
316
-
317
- if (svgSupported) {
318
- // Draw clock hands and others
319
- var canvas = popover.find('.clockpicker-canvas'),
320
- svg = createSvgElement('svg');
321
- svg.setAttribute('class', 'clockpicker-svg');
322
- svg.setAttribute('width', diameter);
323
- svg.setAttribute('height', diameter);
324
- var g = createSvgElement('g');
325
- g.setAttribute('transform', 'translate(' + dialRadius + ',' + dialRadius + ')');
326
- var bearing = createSvgElement('circle');
327
- bearing.setAttribute('class', 'clockpicker-canvas-bearing');
328
- bearing.setAttribute('cx', 0);
329
- bearing.setAttribute('cy', 0);
330
- bearing.setAttribute('r', 2);
331
- var hand = createSvgElement('line');
332
- hand.setAttribute('x1', 0);
333
- hand.setAttribute('y1', 0);
334
- var bg = createSvgElement('circle');
335
- bg.setAttribute('class', 'clockpicker-canvas-bg');
336
- bg.setAttribute('r', tickRadius);
337
- var fg = createSvgElement('circle');
338
- fg.setAttribute('class', 'clockpicker-canvas-fg');
339
- fg.setAttribute('r', 3.5);
340
- g.appendChild(hand);
341
- g.appendChild(bg);
342
- g.appendChild(fg);
343
- g.appendChild(bearing);
344
- svg.appendChild(g);
345
- canvas.append(svg);
346
-
347
- this.hand = hand;
348
- this.bg = bg;
349
- this.fg = fg;
350
- this.bearing = bearing;
351
- this.g = g;
352
- this.canvas = canvas;
353
- }
354
-
355
- raiseCallback(this.options.init);
356
- }
357
-
358
- function raiseCallback(callbackFunction) {
359
- if (callbackFunction && typeof callbackFunction === "function") {
360
- callbackFunction();
361
- }
362
- }
363
-
364
- // Default options
365
- ClockPicker.DEFAULTS = {
366
- 'default': '', // default time, 'now' or '13:14' e.g.
367
- fromnow: 0, // set default time to * milliseconds from now (using with default = 'now')
368
- placement: 'bottom', // clock popover placement
369
- align: 'left', // popover arrow align
370
- donetext: 'Done', // done button text
371
- autoclose: false, // auto close when minute is selected
372
- twelvehour: false, // change to 12 hour AM/PM clock from 24 hour
373
- vibrate: true // vibrate the device when dragging clock hand
374
- };
375
-
376
- // Show or hide popover
377
- ClockPicker.prototype.toggle = function(){
378
- this[this.isShown ? 'hide' : 'show']();
379
- };
380
-
381
- // Set popover position
382
- ClockPicker.prototype.locate = function(){
383
- var element = this.element,
384
- popover = this.popover,
385
- offset = element.offset(),
386
- width = element.outerWidth(),
387
- height = element.outerHeight(),
388
- placement = this.options.placement,
389
- align = this.options.align,
390
- styles = {},
391
- self = this;
392
-
393
- popover.show();
394
-
395
- // Place the popover
396
- switch (placement) {
397
- case 'bottom':
398
- styles.top = offset.top + height;
399
- break;
400
- case 'right':
401
- styles.left = offset.left + width;
402
- break;
403
- case 'top':
404
- styles.top = offset.top - popover.outerHeight();
405
- break;
406
- case 'left':
407
- styles.left = offset.left - popover.outerWidth();
408
- break;
409
- }
410
-
411
- // Align the popover arrow
412
- switch (align) {
413
- case 'left':
414
- styles.left = offset.left;
415
- break;
416
- case 'right':
417
- styles.left = offset.left + width - popover.outerWidth();
418
- break;
419
- case 'top':
420
- styles.top = offset.top;
421
- break;
422
- case 'bottom':
423
- styles.top = offset.top + height - popover.outerHeight();
424
- break;
425
- }
426
-
427
- popover.css(styles);
428
- };
429
-
430
- // Show popover
431
- ClockPicker.prototype.show = function(e){
432
- // Not show again
433
- if (this.isShown) {
434
- return;
435
- }
436
-
437
- raiseCallback(this.options.beforeShow);
438
-
439
- var self = this;
440
-
441
- // Initialize
442
- if (! this.isAppended) {
443
- // Append popover to body
444
- $body = $(document.body).append(this.popover);
445
-
446
- // Reset position when resize
447
- $win.on('resize.clockpicker' + this.id, function(){
448
- if (self.isShown) {
449
- self.locate();
450
- }
451
- });
452
-
453
- this.isAppended = true;
454
- }
455
-
456
- // Get the time sets [hour, min]
457
- var inputValue = ((this.input.prop('value') || this.options['default'] || '') + '');
458
- var value = inputValue.split(":");
459
- value[1] = parseInt(value[1]); // 2017-03-14 / dan.legrand@gmail.com: was setting "MM PM" and blanking out
460
- console.log(inputValue);
461
- value[2] = inputValue.match(/am/i) ? "AM" : "PM";
462
- if (value[0] === 'now') {
463
- var now = new Date(+ new Date() + this.options.fromnow);
464
- value = [
465
- now.getHours(),
466
- now.getMinutes()
467
- ];
468
- }
469
- this.hours = + value[0] || 0;
470
- this.minutes = + value[1] || 0;
471
- this.spanHours.html(leadingZero(this.hours));
472
- this.spanMinutes.html(leadingZero(this.minutes));
473
- this.amOrPm = value[2];
474
-
475
- // $('.clockpicker-span-am-pm').empty().append(value[2]);
476
- this.spanAmPm.text(value[2]);
477
-
478
- // Toggle to hours view
479
- this.toggleView('hours');
480
-
481
- // Set position
482
- this.locate();
483
-
484
- this.isShown = true;
485
-
486
- // Hide when clicking or tabbing on any element except the clock, input and addon
487
- $doc.on('click.clockpicker.' + this.id + ' focusin.clockpicker.' + this.id, function(e){
488
- var target = $(e.target);
489
- if (target.closest(self.popover).length === 0 &&
490
- target.closest(self.addon).length === 0 &&
491
- target.closest(self.input).length === 0) {
492
- self.hide();
493
- }
494
- });
495
-
496
- // Hide when ESC is pressed
497
- $doc.on('keyup.clockpicker.' + this.id, function(e){
498
- if (e.keyCode === 27) {
499
- self.hide();
500
- }
501
- });
502
-
503
- raiseCallback(this.options.afterShow);
504
- };
505
-
506
- // Hide popover
507
- ClockPicker.prototype.hide = function(){
508
- raiseCallback(this.options.beforeHide);
509
-
510
- this.isShown = false;
511
-
512
- // Unbinding events on document
513
- $doc.off('click.clockpicker.' + this.id + ' focusin.clockpicker.' + this.id);
514
- $doc.off('keyup.clockpicker.' + this.id);
515
-
516
- this.popover.hide();
517
-
518
- raiseCallback(this.options.afterHide);
519
- };
520
-
521
- // Toggle to hours or minutes view
522
- ClockPicker.prototype.toggleView = function(view, delay){
523
- var raiseAfterHourSelect = false;
524
- if (view === 'minutes' && $(this.hoursView).css("visibility") === "visible") {
525
- raiseCallback(this.options.beforeHourSelect);
526
- raiseAfterHourSelect = true;
527
- }
528
- var isHours = view === 'hours',
529
- nextView = isHours ? this.hoursView : this.minutesView,
530
- hideView = isHours ? this.minutesView : this.hoursView;
531
-
532
- this.currentView = view;
533
-
534
- this.spanHours.toggleClass('text-primary', isHours);
535
- this.spanMinutes.toggleClass('text-primary', ! isHours);
536
-
537
- // Let's make transitions
538
- hideView.addClass('clockpicker-dial-out');
539
- nextView.css('visibility', 'visible').removeClass('clockpicker-dial-out');
540
-
541
- // Reset clock hand
542
- this.resetClock(delay);
543
-
544
- // After transitions ended
545
- clearTimeout(this.toggleViewTimer);
546
- this.toggleViewTimer = setTimeout(function(){
547
- hideView.css('visibility', 'hidden');
548
- }, duration);
549
-
550
- if (raiseAfterHourSelect) {
551
- raiseCallback(this.options.afterHourSelect);
552
- }
553
- };
554
-
555
- // Reset clock hand
556
- ClockPicker.prototype.resetClock = function(delay){
557
- var view = this.currentView,
558
- value = this[view],
559
- isHours = view === 'hours',
560
- unit = Math.PI / (isHours ? 6 : 30),
561
- radian = value * unit,
562
- radius = isHours && value > 0 && value < 13 ? innerRadius : outerRadius,
563
- x = Math.sin(radian) * radius,
564
- y = - Math.cos(radian) * radius,
565
- self = this;
566
- if (svgSupported && delay) {
567
- self.canvas.addClass('clockpicker-canvas-out');
568
- setTimeout(function(){
569
- self.canvas.removeClass('clockpicker-canvas-out');
570
- self.setHand(x, y);
571
- }, delay);
572
- } else {
573
- this.setHand(x, y);
574
- }
575
- };
576
-
577
- // Set clock hand to (x, y)
578
- ClockPicker.prototype.setHand = function(x, y, roundBy5, dragging){
579
- var radian = Math.atan2(x, - y),
580
- isHours = this.currentView === 'hours',
581
- unit = Math.PI / (isHours || roundBy5 ? 6 : 30),
582
- z = Math.sqrt(x * x + y * y),
583
- options = this.options,
584
- inner = isHours && z < (outerRadius + innerRadius) / 2,
585
- radius = inner ? innerRadius : outerRadius,
586
- value;
587
-
588
- if (options.twelvehour) {
589
- radius = outerRadius;
590
- }
591
-
592
- // Radian should in range [0, 2PI]
593
- if (radian < 0) {
594
- radian = Math.PI * 2 + radian;
595
- }
596
-
597
- // Get the round value
598
- value = Math.round(radian / unit);
599
-
600
- // Get the round radian
601
- radian = value * unit;
602
-
603
- // Correct the hours or minutes
604
- if (options.twelvehour) {
605
- if (isHours) {
606
- if (value === 0) {
607
- value = 12;
608
- }
609
- } else {
610
- if (roundBy5) {
611
- value *= 5;
612
- }
613
- if (value === 60) {
614
- value = 0;
615
- }
616
- }
617
- } else {
618
- if (isHours) {
619
- if (value === 12) {
620
- value = 0;
621
- }
622
- value = inner ? (value === 0 ? 12 : value) : value === 0 ? 0 : value + 12;
623
- } else {
624
- if (roundBy5) {
625
- value *= 5;
626
- }
627
- if (value === 60) {
628
- value = 0;
629
- }
630
- }
631
- }
632
-
633
- // Once hours or minutes changed, vibrate the device
634
- if (this[this.currentView] !== value) {
635
- if (vibrate && this.options.vibrate) {
636
- // Do not vibrate too frequently
637
- if (! this.vibrateTimer) {
638
- navigator[vibrate](10);
639
- this.vibrateTimer = setTimeout($.proxy(function(){
640
- this.vibrateTimer = null;
641
- }, this), 100);
642
- }
643
- }
644
- }
645
-
646
- this[this.currentView] = value;
647
- this[isHours ? 'spanHours' : 'spanMinutes'].html(leadingZero(value));
648
-
649
- // If svg is not supported, just add an active class to the tick
650
- if (! svgSupported) {
651
- this[isHours ? 'hoursView' : 'minutesView'].find('.clockpicker-tick').each(function(){
652
- var tick = $(this);
653
- tick.toggleClass('active', value === + tick.html());
654
- });
655
- return;
656
- }
657
-
658
- // Place clock hand at the top when dragging
659
- if (dragging || (! isHours && value % 5)) {
660
- this.g.insertBefore(this.hand, this.bearing);
661
- this.g.insertBefore(this.bg, this.fg);
662
- this.bg.setAttribute('class', 'clockpicker-canvas-bg clockpicker-canvas-bg-trans');
663
- } else {
664
- // Or place it at the bottom
665
- this.g.insertBefore(this.hand, this.bg);
666
- this.g.insertBefore(this.fg, this.bg);
667
- this.bg.setAttribute('class', 'clockpicker-canvas-bg');
668
- }
669
-
670
- // Set clock hand and others' position
671
- var cx = Math.sin(radian) * radius,
672
- cy = - Math.cos(radian) * radius;
673
- this.hand.setAttribute('x2', cx);
674
- this.hand.setAttribute('y2', cy);
675
- this.bg.setAttribute('cx', cx);
676
- this.bg.setAttribute('cy', cy);
677
- this.fg.setAttribute('cx', cx);
678
- this.fg.setAttribute('cy', cy);
679
- };
680
-
681
- // Hours and minutes are selected
682
- ClockPicker.prototype.done = function() {
683
- raiseCallback(this.options.beforeDone);
684
- this.hide();
685
- var last = this.input.prop('value'),
686
- value = leadingZero(this.hours) + ':' + leadingZero(this.minutes);
687
- if (this.options.twelvehour) {
688
- value = value + " " + this.amOrPm;
689
- }
690
-
691
- this.input.prop('value', value);
692
- if (value !== last) {
693
- this.input.triggerHandler('change');
694
- if (! this.isInput) {
695
- this.element.trigger('change');
696
- }
697
- }
698
-
699
- if (this.options.autoclose) {
700
- this.input.trigger('blur');
701
- }
702
-
703
- raiseCallback(this.options.afterDone);
704
- };
705
-
706
- // Remove clockpicker from input
707
- ClockPicker.prototype.remove = function() {
708
- this.element.removeData('clockpicker');
709
- this.input.off('focus.clockpicker click.clockpicker');
710
- this.addon.off('click.clockpicker');
711
- if (this.isShown) {
712
- this.hide();
713
- }
714
- if (this.isAppended) {
715
- $win.off('resize.clockpicker' + this.id);
716
- this.popover.remove();
717
- }
718
- };
719
-
720
- // Extends $.fn.clockpicker
721
- $.fn.clockpicker = function(option){
722
- var args = Array.prototype.slice.call(arguments, 1);
723
- return this.each(function(){
724
- var $this = $(this),
725
- data = $this.data('clockpicker');
726
- if (! data) {
727
- var options = $.extend({}, ClockPicker.DEFAULTS, $this.data(), typeof option == 'object' && option);
728
- $this.data('clockpicker', new ClockPicker($this, options));
729
- } else {
730
- // Manual operatsions. show, hide, remove, e.g.
731
- if (typeof data[option] === 'function') {
732
- data[option].apply(data, args);
733
- }
734
- }
735
- });
736
- };
737
- }());