├── LICENSE
├── README.md
├── index.html
├── jquery-clock-timepicker.js
├── jquery-clock-timepicker.min.js
├── package-lock.json
└── package.json
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Andreas Marc Loeber
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Clock Timepicker Plugin for jQuery
2 | ==================================
3 |
4 |
5 |
6 | [See a demo here](https://plugins.slyweb.ch/jquery-clock-timepicker)
7 |
8 | A free jQuery Plug-in to select the time with a clock inspired by the Android time picker. This plugin works on Desktop and Mobile phones.
9 |
10 |
11 | Requirements
12 | ------------
13 | * [jQuery](https://jquery.com/)
14 |
15 | Note: You need the regular version of jQuery as the slim version does not include effects, which this library requires.
16 |
17 |
18 | Installation
19 | ------------
20 |
21 | Install from [NPM](https://www.npmjs.com/package/jquery-clock-timepicker) as ```jquery-clock-timepicker```.
22 |
23 | ```npm install jquery-clock-timepicker```
24 |
25 |
26 | Usage
27 | -----
28 |
29 | ```javascript
30 | $('.your-time-field').clockTimePicker(options);
31 | ```
32 |
33 | Include the file `jquery-clock-timepicker.min.js` in your page. There is no need of a CSS file.
34 |
35 | The Plug-in is customizable through the optional ```options``` object passed to the jQuery method, i.e.
36 |
37 | ```javascript
38 | $('.your-time-field').clockTimePicker({
39 | duration: true,
40 | durationNegative: true,
41 | precision: 5,
42 | i18n: {
43 | cancelButton: 'Abbrechen'
44 | },
45 | onAdjust: function(newVal, oldVal) {
46 | //...
47 | }
48 | });
49 | ```
50 |
51 | It is also possible to configure the ClockTimePicker element by using data attributes of the DOM element, i.e.
52 |
53 | ```html
54 |
55 | ```
56 |
57 | You can combine the configuration by JavaScript and by the DOM data attributes. For example, you can use the JavaScript configuration to make a standard configuration
58 | for all your ClockTimePicker elements on the site and use the DOM data attributes to change configuration for individual elements. The data attributes have precedence
59 | over the JavaScript settings.
60 |
61 | If you want to set new options at runtime (after an input element already has been intialized), just call the function again with all desired options.
62 |
63 | If you want to dispose/destroy an initialized clock time picker element, please use the following code:
64 |
65 | ```javascript
66 | $('.your-time-field').clockTimePicker('dispose');
67 | ```
68 |
69 | If you want to change the value programmatically at runtime on an already initialized clock time picker element, use the following code:
70 |
71 | ```javascript
72 | $('.your-time-field').clockTimePicker('value', '08:00');
73 | ```
74 |
75 | Use the following code to show or hide a clock time picker programmatically:
76 |
77 | ```javascript
78 | $('.your-time-field').clockTimePicker('show');
79 | $('.your-time-field').clockTimePicker('hide');
80 | ```
81 |
82 |
83 |
84 | Options
85 | -------
86 |
87 | - **afternoonHoursInOuterCircle**
88 | Set this option to true to display the afternoon hours in the outer circle instead of the inner circle.
89 | *default: false*
90 |
91 | - **alwaysSelectHoursFirst**
92 | By default, if you click on the minutes part of your input field, the popup is opened to directly select the minutes. If you set this option to true, popup is always opened to select hours first before selecting the minutes.
93 | *default: false*
94 |
95 | - **autosize**
96 | Set this to true, if the width of the input field should be automatically adjusted to its content.
97 | *default: false*
98 |
99 | - **colors.buttonTextColor**
100 | The text color of the buttons display on the mobile phone.
101 | *default: '#0797FF'*
102 |
103 | - **colors.clockFaceColor**
104 | The color of the clock face.
105 | *default: '#EEEEEE'*
106 |
107 | - **colors.clockInnerCircleTextColor**
108 | The text color of the numbers displayed in the inner circle.
109 | *default: '#888888'*
110 |
111 | - **colors.clockInnerCircleUnselectableTextColor**
112 | The text color of the unselectable numbers displayed in the inner circle. (only used in combination with ```minimum``` and ```maximum``` option)
113 | *default: '#888888'*
114 |
115 | - **colors.clockOuterCircleTextColor**
116 | The text color of the numbers displayed in the outer circle.
117 | *default: '#000000'*
118 |
119 | - **colors.clockOuterCircleUnselectableTextColor**
120 | The text color of the unselectable numbers displayed in the outer circle. (only used in combination with ```minimum``` and ```maximum``` option)
121 | *default: '#000000'*
122 |
123 | - **colors.hoverCircleColor**
124 | The color of the circle when hovering over an hour or minute.
125 | *default: '#DDDDDD'*
126 |
127 | - **colors.popupBackgroundColor**
128 | The background color of the popup.
129 | *default: '#FFFFFF'*
130 |
131 | - **colors.popupHeaderBackgroundColor**
132 | The background color of the popup header displayed only on the mobile phone.
133 | *default: '#0797FF'*
134 |
135 | - **colors.popupHeaderTextColor**
136 | The text color of the popup header displayed only on the mobile phone.
137 | *default: '#FFFFFF'*
138 |
139 | - **colors.selectorColor**
140 | The color of the time selector.
141 | *default: '#0797FF'*
142 |
143 | - **colors.selectorNumberColor**
144 | The text color of the number that is selected.
145 | *default: '#FFFFFF'*
146 |
147 | - **contextmenu**
148 | If true, the browser's or a custom context menu is shown on right click.
149 | If false, the right click behaves like the left click and the clock is shown.
150 | *default: false*
151 |
152 | - **duration**
153 | If true, the hours can be greater than 23.
154 | *default: false*
155 |
156 | - **durationNegative**
157 | If true, the duration can be negative. This settings only has effect if the setting **duration** is set to true.
158 | *default: false*
159 |
160 | - **fonts.buttonFontSize**
161 | The font size of the buttons. These buttons are only displayed in the mobile version.
162 | *default: 20*
163 |
164 | - **fonts.clockInnerCircleFontSize**
165 | The font size of the numbers that are displayed in the inner circle.
166 | *default: 12*
167 |
168 | - **fonts.clockOuterCircleFontSize**
169 | The font size of the numbers that are displayed in the outer circle.
170 | *default: 14*
171 |
172 | - **fonts.fontFamily**
173 | The font family used to display the numbers.
174 | *default: 'Arial'*
175 |
176 | - **hideUnselectableNumbers**
177 | Set this option to true if you want to completely hide the unselectable numbers (in case you're using ```minimum``` and ```maximum``` option).
178 | *default: false*
179 |
180 | - **i18n.cancelButton**
181 | The name of the button to cancel the time change. Only displayed on mobile phones.
182 | *default: 'Cancel'*
183 |
184 | - **i18n.okButton**
185 | The name of the button to confirm the time change. Only displayed on mobile phones.
186 | *default: 'OK'*
187 |
188 | - **maximum**
189 | With this option you can define the maximum duration/time. Syntax: hh:mm, i.e. 8:30, 12:00, 24:00, 100:00, ...
190 | *default: '23:59'*
191 |
192 | - **minimum**
193 | With this option you can define the minimum duration/time. Syntax: hh:mm, i.e. 06:00, -10:00, -15:45, ...
194 | *default: '-23:59'*
195 |
196 | - **modeSwitchSpeed**
197 | The speed in milliseconds of the switch animation when changing between hour and minute selection.
198 | *default: 500*
199 |
200 | - **onlyShowClockOnMobile**
201 | If true, the clock time picker is not shown on Desktop version.
202 | *default: false*
203 |
204 | - **onAdjust**
205 | Called when the time value is been adjusting. Compared to onChange this function is called each time when the value is changing, also while dragging the time selector...
206 | *default: function(newValue, oldValue) {}*
207 |
208 | - **onChange**
209 | Called when the time value has been changed. This function is called when the input field is loosing its focus.
210 | *default: function(newValue, oldValue) {}*
211 |
212 | - **onClose**
213 | Called when timepicker popup has been closed.
214 | *default: function() {}*
215 |
216 | - **onModeSwitch**
217 | Called when timepicker is switching between hour and minute selection mode. Argument *selectionMode* is "HOUR" or "MINUTE".
218 | *default: function(selectionMode) {}*
219 |
220 | - **onOpen**
221 | Called when timepicker popup has been opened.
222 | *default: function() {}*
223 |
224 | - **popupWidthOnDesktop**
225 | The width of the popup in the Desktop version in pixels. On the mobile phone the width is automatically calculated.
226 | *default: 200*
227 |
228 | - **precision**
229 | When setting the precision to i.e. 5, user may only choose time in 5 minutes steps (8:00, 8:05, 8:10, ...). Valid values for precision are: 1, 5, 10, 15, 30, 60.
230 | *default: 1*
231 |
232 | - **required**
233 | If this option is set to true, a user cannot empty the field by hitting delete or backspace.
234 | *default: false*
235 |
236 | - **separator**
237 | The separator separating the hour and the minute parts.
238 | *default: :*
239 |
240 | - **useDurationPlusSign**
241 | If set to true, positive durations use the plus sign (+) as a prefix.
242 | *default: false*
243 |
244 | - **vibrate**
245 | If this is activated the mobile phone vibrates while changing the time.
246 | *default: true*
247 |
248 |
249 |
250 | Help
251 | ----
252 |
253 | Submit a [GitHub Issues request](https://github.com/loebi-ch/jquery-clock-timepicker/issues/new).
254 |
255 |
256 |
257 | Changelog
258 | ---------
259 |
260 | **Version 2.6.4**
261 | - for loop variable i declared with let.
262 |
263 | **Version 2.6.3**
264 | - Made disturbing blinking cursor transparent, so it's not visible anymore.
265 |
266 | **Version 2.6.2**
267 | - New configuration setting ```contextmenu``` added. See above in the Options section for explanation. Closes pull request #43.
268 |
269 | **Version 2.6.1**
270 | - jQuery version notice included in README.md
271 | - ClockTimePicker's version number included as query parameter when loading ```jquery-clock-timepicker.min.js``` in index.html to solve browser caching issue for new released versions.
272 |
273 | **Version 2.6.0**
274 | - Minified JavaScript without eval() to solve issue #34.
275 | - Setting HTML value attribute upon time change.
276 | - Get value by calling ```$('.your-time-field').clockTimePicker('value');``` or ```$('.your-time-field').clockTimePicker('val');```
277 | - Set value by calling ```$('.your-time-field').clockTimePicker('value', '08:00');``` or ```$('.your-time-field').clockTimePicker('val', '08:00');```
278 |
279 | **Version 2.5.0**
280 | - Don't open clock canvas when setting value programmatically with ```$('.your-time-field').clockTimePicker('value', '08:00');```
281 | - New function to show clock canvas programmatically with ```$('.your-time-field').clockTimePicker('show');```
282 | - New function to hide clock canvas programmatically with ```$('.your-time-field').clockTimePicker('hide');```
283 |
284 | **Version 2.4.0**
285 | - Position popup "fixed" instead of "absolute" to prevent popup from cut-off in containers with overflow: hidden.
286 | - Slow down scroll wheel event so that the clock timepicker doesn't spin uncontrollable when using touchpad.
287 | - Update to jQuery 3.5
288 |
289 | **Version 2.3.5**
290 | - Issue #29 fixed.
291 | - Blur input element on enter.
292 |
293 | **Version 2.3.4**
294 | - Method ```onInputElementKeyUp``` completely refactored to simplify and to solve issue #21.
295 | - Arrow keys and +/- sign behavior refactored. No wheelspin anymore, stop at ```minimum``` and ```maximum``` values.
296 | - Bugfix for bluring input element when switching from one clock timepicker element to another one.
297 |
298 | **Version 2.3.3**
299 | - Issue #14 fixed by inserting code Yauheni-Butski proposed.
300 | - Issue #28 fixed by changing code as proposed by Yauheni-Butski.
301 |
302 | **Version 2.3.2**
303 | - Issue #22 fixed. Using div and spans instead of input element on mobile phones to prevent context menu and cursors to show up.
304 | - Issue #23 fixed. Rounding problem on initialization solved when using option ```precision```.
305 | - Issue #25 fixed. New option ```alwaysSelectHoursFirst``` inserted.
306 |
307 | **Version 2.3.1**
308 | - Bugfix for entering durations with keyboard when ```useDurationPlusSign``` is set to ```true```
309 | - Removed unwanted Console.log
310 |
311 | **Version 2.3.0**
312 | - Issue #15 solved.
313 | - Feature request #17 implemented: Showing unselectable numbers when using ```minimum``` and ```maximum``` options.
314 | - Hide unselectable numbers completely by using ```hideUnselectableNumbers``` option.
315 | - Configure text colors for unselectable numbers with new options ```clockInnerCircleUnselectableTextColor``` and ```clockOuterCircleUnselectableTextColor```.
316 | - Feature request #18 implemented: Use of data attributes to configure ClockTimePicker element.
317 | - Bugfix for wrong hovering when using ```afternoonHoursInOuterCircle``` (Issue #16).
318 |
319 | **Version 2.2.5**
320 | - Fixed a converting bug when switching between minus and plus sign.
321 |
322 | **Version 2.2.4**
323 | - Hide example console output that was deployed in version 2.2.3 by mistake.
324 |
325 | **Version 2.2.3**
326 | - Option ```useDurationPlusSign``` implemented.
327 |
328 | **Version 2.2.2**
329 | - Issue #12 fixed.
330 |
331 | **Version 2.2.1**
332 | - Issue #9 perfectionated to select hour/minute part with mouse click.
333 | - Parse number settings as integer to prevent errors in calculations in case that a string is passed.
334 | - Pull request #11 from reclaimingmytime inserted.
335 |
336 | **Version 2.2.0**
337 | - Issue #7 fixed. Now this plugin works in both portrait and landscape mode on the mobile phone.
338 |
339 | **Version 2.1.10**
340 | - Bluring issues fixed.
341 |
342 | **Version 2.1.9**
343 | - Directly select minute when clicking inside the minute part.
344 | - Bluring issues fixed.
345 | - Issue #9 perfectionated to select hour/minute part with mouse click.
346 | - Autosizing adjusted so that jquery-clock-timepicker works together with sortablejs.
347 | - Hide time picker when deleting content with delete or backspace.
348 | - Show 00:00 when focusing an empty timepicker.
349 |
350 | **Version 2.1.8**
351 | - Fixed an issue with overlapping popup when input element has a top margin.
352 |
353 | **Version 2.1.7**
354 | - Issue #9 fixed. Better approach to select hour/minute part with mouse click.
355 |
356 | **Version 2.1.6**
357 | - Bugfix when entering time/duration with keyboard on an empty input field.
358 | - Bugfix for keys "+" and "-" in 2.1.5 leaded to another bug with negative duration fields. Corrected in this version.
359 |
360 | **Version 2.1.5**
361 | - Precision 60 bugfix: In some cases the time picker switched to minute mode although precision 60 was set.
362 | - Bugfix for keys "+" and "-" to adjust value in correct direction: + = plus, - = minus.
363 |
364 | **Version 2.1.4**
365 | - Added function to set value on an already initialized clock time picker element at runtime.
366 |
367 | **Version 2.1.3**
368 | - Support for keypad with num lock.
369 |
370 | **Version 2.1.2**
371 | - Call event functions with call() using the element as context so that you can use $(this) inside the callback function to access the element.
372 |
373 | **Version 2.1.1**
374 | - Bugfix: Sign button clickable on mobile phone
375 |
376 | **Version 2.1.0**
377 | - Make it possible to dispose an already initialized clock time picker element.
378 | - Changed the default value for the option ```autosize``` from true to false.
379 | - New option ```required``` added: If you don't want the user to empty the input element, you can set this option to true.
380 | - New event ```onAddjust``` added: This option is called on each adjustment of the value, including dragging the timeselector.
381 | - Sign button +/- implemented in canvas instead of an HTML element to prevent styling issues depending on different global CSS layouts.
382 | - Selection of hour and minute part with the mouse improved (now also taking account of input element's padding).
383 | - Key handling improved for backspace, delete and minus key.
384 | - Arrow keys up and down switched.
385 | - Context menu on right click disabled.
386 | - Implementation of ```maximum``` and ```minimum``` option.
387 |
388 | **Version 2.0.0**
389 | - Event management completeley refactored so that one can use the input's default onchange event.
390 |
391 | **Version 1.x**
392 | - No changelog available for the first versions of this jQuery component.
393 |
394 |
395 | - - -
396 |
397 | This software is made available under the open source MIT License. © 2022 [Andreas Loeber](http://github.com/loebi-ch) and [contributors](https://github.com/loebi-ch/jquery-clock-timepicker/graphs/contributors)
398 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | jQuery Clock Time Picker
6 |
7 |
8 |
25 |
38 |
39 |
40 |
41 |
jQuery Clock Time Picker v2.6.4
42 |
NPM package "jquery-clock-timepicker"
43 |
A free jQuery Plug-in to select the time with a clock inspired by the Android time picker. This plugin works on Desktop and Mobile phones.
44 |
Install with NPM or download it directly from GitHub:
https://github.com/loebi-ch/jquery-clock-timepicker
45 |
The manual can be found on GitHub.
46 |
Examples
47 |
(with the most important settings. Of course, you can combine these different settings...)
48 |
49 | Standard time picker
50 | (no settings specified)
51 |
52 |
53 |
54 | Required time picker
55 | { required: true }
56 |
57 |
58 |
59 | Time picker with different separator
60 | { seperator: '.' }
61 |
62 |
63 |
64 | Time picker with precision
65 |
89 |
90 |
91 | Time picker - show clock picker only on mobile phones
92 | { onlyShowClockOnMobile: true }
93 |
94 |
95 |
96 | Duration picker
97 | { duration: true, maximum: '80:00' }
98 |
99 |
100 |
101 | Duration picker that allows to select negative durations
102 | { duration: true, durationNegative: true }
103 |
104 |
105 |
106 | Duration picker with minimum and maximum
107 | { duration: true, minimum: '1:00', maximum: '5:30' }
108 |
109 |
110 |
111 | Negative duration picker with minimum and maximum
112 | { duration: true, durationNegative: true, minimum: '-5:00', maximum: '5:00', precision: 5 }
113 |
114 |
115 |
116 | Find more settings in the README on GitHub.
117 | If you miss settings, please feel free to submit a GitHub issue request.
118 |
119 |
120 |
121 |
--------------------------------------------------------------------------------
/jquery-clock-timepicker.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Author: Andreas Loeber
3 | * Plugin: jquery-clock-timerpicker
4 | * Version: 2.6.4
5 | */
6 | (function($) {
7 |
8 | $.fn.clockTimePicker = function(options, _value) {
9 | if (typeof options == 'string' && (options == 'value' || options == 'val') && !_value) return $(this).val();
10 |
11 | /************************************************************************************************
12 | DEFAULT SETTINGS (CAN BE OVERRIDDEN WITH THE OPTIONS ARGUMENT)
13 | ************************************************************************************************/
14 | var settings = $.extend(true, {
15 | afternoonHoursInOuterCircle: false,
16 | alwaysSelectHoursFirst: false,
17 | autosize: false,
18 | contextmenu: false,
19 | colors: {
20 | buttonTextColor: '#0797FF',
21 | clockFaceColor: '#EEEEEE',
22 | clockInnerCircleTextColor: '#888888',
23 | clockInnerCircleUnselectableTextColor: '#CCCCCC',
24 | clockOuterCircleTextColor: '#000000',
25 | clockOuterCircleUnselectableTextColor: '#CCCCCC',
26 | hoverCircleColor: '#DDDDDD',
27 | popupBackgroundColor: '#FFFFFF',
28 | popupHeaderBackgroundColor: '#0797FF',
29 | popupHeaderTextColor: '#FFFFFF',
30 | selectorColor: '#0797FF',
31 | selectorNumberColor: '#FFFFFF',
32 | signButtonColor: '#FFFFFF',
33 | signButtonBackgroundColor: '#0797FF'
34 | },
35 | duration: false,
36 | durationNegative: false,
37 | fonts: {
38 | fontFamily: 'Arial',
39 | clockOuterCircleFontSize: 14,
40 | clockInnerCircleFontSize: 12,
41 | buttonFontSize: 20
42 | },
43 | hideUnselectableNumbers: false,
44 | i18n: {
45 | okButton: 'OK',
46 | cancelButton: 'Cancel'
47 | },
48 | maximum: '23:59',
49 | minimum: '-23:59',
50 | modeSwitchSpeed: 500,
51 | onlyShowClockOnMobile: false,
52 | onAdjust: function(newVal, oldVal) { /*console.log('Value adjusted from ' + oldVal + ' to ' + newVal + '.');*/ },
53 | onChange: function(newVal, oldVal) { /*console.log('Value changed from ' + oldVal + ' to ' + newVal + '.');*/ },
54 | onClose: function() { },
55 | onModeSwitch: function() { },
56 | onOpen: function() { },
57 | popupWidthOnDesktop: 200,
58 | precision: 1,
59 | required: false,
60 | separator: ':',
61 | useDurationPlusSign: false,
62 | vibrate: true
63 | }, typeof options == 'object' ? options : {});
64 |
65 |
66 | /************************************************************************************************
67 | DYNAMICALLY INSERT CSS CODE FOR SELECTION ON MOBILE
68 | ************************************************************************************************/
69 | var css = '.clock-timepicker input { caret-color: transparent; }';
70 | if (isMobile()) css += ' .clock-timepicker input::selection { background:rgba(255,255,255,0.6); } .clock-timepicker input::-moz-selection { background:rgba(255,255,255,0.6); }';
71 | function cssAlreadyInitialized() {
72 | var cssFound = false;
73 | $('head style').each(function() {
74 | if ($(this).text() == css) {
75 | cssFound = true;
76 | return false;
77 | }
78 | });
79 | if (cssFound) return true;
80 | else return false;
81 | }
82 | if (!cssAlreadyInitialized()) {
83 | var style = document.createElement('style');
84 | style.type = 'text/css';
85 | if (style.styleSheet) style.styleSheet.cssText = css;
86 | else style.appendChild(document.createTextNode(css));
87 | (document.head || document.getElementsByTagName('head')[0]).appendChild(style);
88 | }
89 |
90 | //for each selected element
91 | return this.each(function() {
92 |
93 | var element = $(this);
94 |
95 | //Adjust settings by data attributes
96 | var dataOptions = {}, _data = element.data();
97 | for (var dataOption in _data) {
98 | if (settings.hasOwnProperty(dataOption)) {
99 | settings[dataOption] = _data[dataOption];
100 | }
101 | }
102 |
103 | //Validate settings
104 | validateSettings();
105 |
106 | //VIBRATION API
107 | if (!('vibrate' in navigator)) settings.vibrate = false;
108 |
109 | if (typeof options == 'string') {
110 | if (!$(this).parent().hasClass('clock-timepicker')) console.log('%c[jquery-clock-timepicker] Before calling a function, please initialize the ClockTimePicker!', 'color:red');
111 | else {
112 | options = options.toLowerCase();
113 | if (options == 'dispose') disposeTimePicker($(this));
114 | else if (options == 'value' || options == 'val') {
115 | $(this).val(formatTime(_value));
116 | var mobileInput = $(this).parent().find('.clock-timepicker-mobile-input');
117 | if (mobileInput.length > 0) mobileInput.val(formatTime(_value));
118 | }
119 | else if (options == 'show') {
120 | $(this).parent().find('canvas:first').trigger('keydown');
121 | }
122 | else if (options == 'hide') {
123 | $(this).parent().find('.clock-timepicker-popup').css('display', 'none');
124 | $(this).blur();
125 | }
126 | else console.log('%c[jquery-clock-timepicker] Invalid option passed to clockTimePicker: ' + options, 'color:red');
127 | }
128 | return;
129 | } else {
130 | if ($(this).parent().hasClass('clock-timepicker')) disposeTimePicker($(this));
131 | }
132 |
133 |
134 |
135 | /************************************************************************************************
136 | INITIALIZE VARIABLES
137 | ************************************************************************************************/
138 | element.val(formatTime(element.val()));
139 | if (isMobile()) element.prop('readonly', true);
140 | var oldValue = element.val();
141 | var enteredDigits = '';
142 | var selectionMode = 'HOUR'; //2 modes: 'HOUR' or 'MINUTE'
143 | var isDragging = false;
144 | var touchSignButton = false;
145 | var popupWidth = isMobile() ? $(document).width() - 80 : settings.popupWidthOnDesktop;
146 | var canvasSize = popupWidth - (isMobile() ? 50 : 20);
147 | var clockRadius = parseInt(canvasSize / 2);
148 | var clockCenterX = parseInt(canvasSize / 2);
149 | var clockCenterY = parseInt(canvasSize / 2);
150 | var clockOuterRadius = clockRadius - 16;
151 | var clockInnerRadius = clockOuterRadius - 29;
152 | var isTimeChanged = false;
153 | var lastMouseWheelTimestamp = 0;
154 |
155 |
156 |
157 | /************************************************************************************************
158 | INITIALIZE A NEW PARENT ELEMENT THAT ENCAPSULATES THE INPUT FIELD
159 | ************************************************************************************************/
160 | element.wrap('');
161 |
162 |
163 |
164 | /************************************************************************************************
165 | TEMPORARY AUTOSIZE ELEMENT
166 | ************************************************************************************************/
167 | var tempAutosizeElement = $('
');
168 | tempAutosizeElement.css('position', 'absolute')
169 | .css('opacity', 0)
170 | .css('display', 'none')
171 | .css('top', parseInt(element.css('margin-top')) + 'px')
172 | .css('left', '0px')
173 | .css('font-size', element.css('font-size'))
174 | .css('font-family', element.css('font-family'))
175 | .css('font-weight', element.css('font-weight'))
176 | .css('line-height', element.css('line-height'));
177 | element.parent().append(tempAutosizeElement);
178 | element.css('min-width', element.outerWidth());
179 | autosize();
180 |
181 |
182 |
183 | /************************************************************************************************
184 | INITIALIZE THE DIV TO DARKEN THE WEBSITE WHILE CHOOSING A TIME
185 | ************************************************************************************************/
186 | var background;
187 | if (isMobile()) {
188 | background = $('
');
189 | background.css('zIndex', 99998)
190 | .css('display', 'none')
191 | .css('position', 'fixed')
192 | .css('top', '0px')
193 | .css('left', '0px')
194 | .css('width', '100%')
195 | .css('height', '100%')
196 | .css('backgroundColor', 'rgba(0,0,0,0.6)');
197 | element.parent().append(background);
198 |
199 | function onBackgroundTouchMove(event) {
200 | event.preventDefault();
201 | }
202 | background.off('touchmove', onBackgroundTouchMove);
203 | background.on('touchmove', onBackgroundTouchMove);
204 |
205 | function onBackgroundClick(event) {
206 | event.preventDefault();
207 | event.stopImmediatePropagation();
208 | if (selectionMode == 'HOUR') selectHourOnInputElement();
209 | else selectMinuteOnInputElement();
210 | return false;
211 | }
212 | background.off('click', onBackgroundClick);
213 | background.on('click', onBackgroundClick);
214 | }
215 |
216 |
217 |
218 | /************************************************************************************************
219 | INITIALIZE POPUP
220 | ************************************************************************************************/
221 | var popup = $('