bootstrap-timepicker-rails-addon 0.2.4.1 → 0.2.5.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -17,6 +17,7 @@
|
|
17
17
|
this.$element = $(element);
|
18
18
|
this.defaultTime = options.defaultTime;
|
19
19
|
this.disableFocus = options.disableFocus;
|
20
|
+
this.disableMousewheel = options.disableMousewheel;
|
20
21
|
this.isOpen = options.isOpen;
|
21
22
|
this.minuteStep = options.minuteStep;
|
22
23
|
this.modalBackdrop = options.modalBackdrop;
|
@@ -33,7 +34,6 @@
|
|
33
34
|
Timepicker.prototype = {
|
34
35
|
|
35
36
|
constructor: Timepicker,
|
36
|
-
|
37
37
|
_init: function() {
|
38
38
|
var self = this;
|
39
39
|
|
@@ -45,21 +45,24 @@
|
|
45
45
|
'focus.timepicker': $.proxy(this.highlightUnit, this),
|
46
46
|
'click.timepicker': $.proxy(this.highlightUnit, this),
|
47
47
|
'keydown.timepicker': $.proxy(this.elementKeydown, this),
|
48
|
-
'blur.timepicker': $.proxy(this.blurElement, this)
|
48
|
+
'blur.timepicker': $.proxy(this.blurElement, this),
|
49
|
+
'mousewheel.timepicker DOMMouseScroll.timepicker': $.proxy(this.mousewheel, this)
|
49
50
|
});
|
50
51
|
} else {
|
51
52
|
if (this.template) {
|
52
53
|
this.$element.on({
|
53
54
|
'focus.timepicker': $.proxy(this.showWidget, this),
|
54
55
|
'click.timepicker': $.proxy(this.showWidget, this),
|
55
|
-
'blur.timepicker': $.proxy(this.blurElement, this)
|
56
|
+
'blur.timepicker': $.proxy(this.blurElement, this),
|
57
|
+
'mousewheel.timepicker DOMMouseScroll.timepicker': $.proxy(this.mousewheel, this)
|
56
58
|
});
|
57
59
|
} else {
|
58
60
|
this.$element.on({
|
59
61
|
'focus.timepicker': $.proxy(this.highlightUnit, this),
|
60
62
|
'click.timepicker': $.proxy(this.highlightUnit, this),
|
61
63
|
'keydown.timepicker': $.proxy(this.elementKeydown, this),
|
62
|
-
'blur.timepicker': $.proxy(this.blurElement, this)
|
64
|
+
'blur.timepicker': $.proxy(this.blurElement, this),
|
65
|
+
'mousewheel.timepicker DOMMouseScroll.timepicker': $.proxy(this.mousewheel, this)
|
63
66
|
});
|
64
67
|
}
|
65
68
|
}
|
@@ -74,7 +77,8 @@
|
|
74
77
|
this.$widget.find('input').each(function() {
|
75
78
|
$(this).on({
|
76
79
|
'click.timepicker': function() { $(this).select(); },
|
77
|
-
'keydown.timepicker': $.proxy(self.widgetKeydown, self)
|
80
|
+
'keydown.timepicker': $.proxy(self.widgetKeydown, self),
|
81
|
+
'keyup.timepicker': $.proxy(self.widgetKeyup, self)
|
78
82
|
});
|
79
83
|
});
|
80
84
|
}
|
@@ -83,10 +87,19 @@
|
|
83
87
|
},
|
84
88
|
|
85
89
|
blurElement: function() {
|
86
|
-
this.highlightedUnit =
|
90
|
+
this.highlightedUnit = null;
|
87
91
|
this.updateFromElementVal();
|
88
92
|
},
|
89
93
|
|
94
|
+
clear: function() {
|
95
|
+
this.hour = '';
|
96
|
+
this.minute = '';
|
97
|
+
this.second = '';
|
98
|
+
this.meridian = '';
|
99
|
+
|
100
|
+
this.$element.val('');
|
101
|
+
},
|
102
|
+
|
90
103
|
decrementHour: function() {
|
91
104
|
if (this.showMeridian) {
|
92
105
|
if (this.hour === 1) {
|
@@ -103,13 +116,12 @@
|
|
103
116
|
this.hour--;
|
104
117
|
}
|
105
118
|
} else {
|
106
|
-
if (this.hour
|
119
|
+
if (this.hour <= 0) {
|
107
120
|
this.hour = 23;
|
108
121
|
} else {
|
109
122
|
this.hour--;
|
110
123
|
}
|
111
124
|
}
|
112
|
-
this.update();
|
113
125
|
},
|
114
126
|
|
115
127
|
decrementMinute: function(step) {
|
@@ -127,7 +139,6 @@
|
|
127
139
|
} else {
|
128
140
|
this.minute = newVal;
|
129
141
|
}
|
130
|
-
this.update();
|
131
142
|
},
|
132
143
|
|
133
144
|
decrementSecond: function() {
|
@@ -139,40 +150,17 @@
|
|
139
150
|
} else {
|
140
151
|
this.second = newVal;
|
141
152
|
}
|
142
|
-
this.update();
|
143
153
|
},
|
144
154
|
|
145
155
|
elementKeydown: function(e) {
|
146
156
|
switch (e.keyCode) {
|
147
157
|
case 9: //tab
|
148
|
-
this.updateFromElementVal();
|
149
|
-
|
150
|
-
switch (this.highlightedUnit) {
|
151
|
-
case 'hour':
|
152
|
-
e.preventDefault();
|
153
|
-
this.highlightNextUnit();
|
154
|
-
break;
|
155
|
-
case 'minute':
|
156
|
-
if (this.showMeridian || this.showSeconds) {
|
157
|
-
e.preventDefault();
|
158
|
-
this.highlightNextUnit();
|
159
|
-
}
|
160
|
-
break;
|
161
|
-
case 'second':
|
162
|
-
if (this.showMeridian) {
|
163
|
-
e.preventDefault();
|
164
|
-
this.highlightNextUnit();
|
165
|
-
}
|
166
|
-
break;
|
167
|
-
}
|
168
|
-
break;
|
169
158
|
case 27: // escape
|
170
159
|
this.updateFromElementVal();
|
171
160
|
break;
|
172
161
|
case 37: // left arrow
|
173
162
|
e.preventDefault();
|
174
163
|
this.highlightPrevUnit();
|
175
|
-
this.updateFromElementVal();
|
176
164
|
break;
|
177
165
|
case 38: // up arrow
|
178
166
|
e.preventDefault();
|
@@ -194,10 +182,10 @@
|
|
194
182
|
this.highlightMeridian();
|
195
183
|
break;
|
196
184
|
}
|
185
|
+
this.update();
|
197
186
|
break;
|
198
187
|
case 39: // right arrow
|
199
188
|
e.preventDefault();
|
200
|
-
this.updateFromElementVal();
|
201
189
|
this.highlightNextUnit();
|
202
190
|
break;
|
203
191
|
case 40: // down arrow
|
@@ -220,18 +208,12 @@
|
|
220
208
|
this.highlightMeridian();
|
221
209
|
break;
|
222
210
|
}
|
211
|
+
|
212
|
+
this.update();
|
223
213
|
break;
|
224
214
|
}
|
225
215
|
},
|
226
216
|
|
227
|
-
formatTime: function(hour, minute, second, meridian) {
|
228
|
-
hour = hour < 10 ? '0' + hour : hour;
|
229
|
-
minute = minute < 10 ? '0' + minute : minute;
|
230
|
-
second = second < 10 ? '0' + second : second;
|
231
|
-
|
232
|
-
return hour + ':' + minute + (this.showSeconds ? ':' + second : '') + (this.showMeridian ? ' ' + meridian : '');
|
233
|
-
},
|
234
|
-
|
235
217
|
getCursorPosition: function() {
|
236
218
|
var input = this.$element.get(0);
|
237
219
|
|
@@ -258,10 +240,10 @@
|
|
258
240
|
templateContent;
|
259
241
|
|
260
242
|
if (this.showInputs) {
|
261
|
-
hourTemplate = '<input type="text"
|
262
|
-
minuteTemplate = '<input type="text"
|
263
|
-
secondTemplate = '<input type="text"
|
264
|
-
meridianTemplate = '<input type="text"
|
243
|
+
hourTemplate = '<input type="text" class="bootstrap-timepicker-hour" maxlength="2"/>';
|
244
|
+
minuteTemplate = '<input type="text" class="bootstrap-timepicker-minute" maxlength="2"/>';
|
245
|
+
secondTemplate = '<input type="text" class="bootstrap-timepicker-second" maxlength="2"/>';
|
246
|
+
meridianTemplate = '<input type="text" class="bootstrap-timepicker-meridian" maxlength="2"/>';
|
265
247
|
} else {
|
266
248
|
hourTemplate = '<span class="bootstrap-timepicker-hour"></span>';
|
267
249
|
minuteTemplate = '<span class="bootstrap-timepicker-minute"></span>';
|
@@ -335,7 +317,11 @@
|
|
335
317
|
},
|
336
318
|
|
337
319
|
getTime: function() {
|
338
|
-
|
320
|
+
if (!this.hour && !this.minute && !this.second) {
|
321
|
+
return '';
|
322
|
+
}
|
323
|
+
|
324
|
+
return this.hour + ':' + (this.minute.toString().length === 1 ? '0' + this.minute : this.minute) + (this.showSeconds ? ':' + (this.second.toString().length === 1 ? '0' + this.second : this.second) : '') + (this.showMeridian ? ' ' + this.meridian : '');
|
339
325
|
},
|
340
326
|
|
341
327
|
hideWidget: function() {
|
@@ -343,10 +329,6 @@
|
|
343
329
|
return;
|
344
330
|
}
|
345
331
|
|
346
|
-
if (this.showInputs) {
|
347
|
-
this.updateFromWidgetInputs();
|
348
|
-
}
|
349
|
-
|
350
332
|
this.$element.trigger({
|
351
333
|
'type': 'hide.timepicker',
|
352
334
|
'time': {
|
@@ -364,7 +346,7 @@
|
|
364
346
|
this.$widget.removeClass('open');
|
365
347
|
}
|
366
348
|
|
367
|
-
$(document).off('mousedown.timepicker');
|
349
|
+
$(document).off('mousedown.timepicker, touchend.timepicker');
|
368
350
|
|
369
351
|
this.isOpen = false;
|
370
352
|
},
|
@@ -416,7 +398,13 @@
|
|
416
398
|
highlightPrevUnit: function() {
|
417
399
|
switch (this.highlightedUnit) {
|
418
400
|
case 'hour':
|
419
|
-
this.
|
401
|
+
if(this.showMeridian){
|
402
|
+
this.highlightMeridian();
|
403
|
+
} else if (this.showSeconds) {
|
404
|
+
this.highlightSecond();
|
405
|
+
} else {
|
406
|
+
this.highlightMinute();
|
407
|
+
}
|
420
408
|
break;
|
421
409
|
case 'minute':
|
422
410
|
this.highlightHour();
|
@@ -435,54 +423,78 @@
|
|
435
423
|
},
|
436
424
|
|
437
425
|
highlightHour: function() {
|
438
|
-
var $element = this.$element.get(0)
|
426
|
+
var $element = this.$element.get(0),
|
427
|
+
self = this;
|
439
428
|
|
440
429
|
this.highlightedUnit = 'hour';
|
441
430
|
|
442
431
|
if ($element.setSelectionRange) {
|
443
432
|
setTimeout(function() {
|
444
|
-
|
433
|
+
if (self.hour < 10) {
|
434
|
+
$element.setSelectionRange(0,1);
|
435
|
+
} else {
|
436
|
+
$element.setSelectionRange(0,2);
|
437
|
+
}
|
445
438
|
}, 0);
|
446
439
|
}
|
447
440
|
},
|
448
441
|
|
449
442
|
highlightMinute: function() {
|
450
|
-
var $element = this.$element.get(0)
|
443
|
+
var $element = this.$element.get(0),
|
444
|
+
self = this;
|
451
445
|
|
452
446
|
this.highlightedUnit = 'minute';
|
453
447
|
|
454
448
|
if ($element.setSelectionRange) {
|
455
449
|
setTimeout(function() {
|
456
|
-
|
450
|
+
if (self.hour < 10) {
|
451
|
+
$element.setSelectionRange(2,4);
|
452
|
+
} else {
|
453
|
+
$element.setSelectionRange(3,5);
|
454
|
+
}
|
457
455
|
}, 0);
|
458
456
|
}
|
459
457
|
},
|
460
458
|
|
461
459
|
highlightSecond: function() {
|
462
|
-
var $element = this.$element.get(0)
|
460
|
+
var $element = this.$element.get(0),
|
461
|
+
self = this;
|
463
462
|
|
464
463
|
this.highlightedUnit = 'second';
|
465
464
|
|
466
465
|
if ($element.setSelectionRange) {
|
467
466
|
setTimeout(function() {
|
468
|
-
|
467
|
+
if (self.hour < 10) {
|
468
|
+
$element.setSelectionRange(5,7);
|
469
|
+
} else {
|
470
|
+
$element.setSelectionRange(6,8);
|
471
|
+
}
|
469
472
|
}, 0);
|
470
473
|
}
|
471
474
|
},
|
472
475
|
|
473
476
|
highlightMeridian: function() {
|
474
|
-
var $element = this.$element.get(0)
|
477
|
+
var $element = this.$element.get(0),
|
478
|
+
self = this;
|
475
479
|
|
476
480
|
this.highlightedUnit = 'meridian';
|
477
481
|
|
478
482
|
if ($element.setSelectionRange) {
|
479
483
|
if (this.showSeconds) {
|
480
484
|
setTimeout(function() {
|
481
|
-
|
485
|
+
if (self.hour < 10) {
|
486
|
+
$element.setSelectionRange(8,10);
|
487
|
+
} else {
|
488
|
+
$element.setSelectionRange(9,11);
|
489
|
+
}
|
482
490
|
}, 0);
|
483
491
|
} else {
|
484
492
|
setTimeout(function() {
|
485
|
-
|
493
|
+
if (self.hour < 10) {
|
494
|
+
$element.setSelectionRange(5,7);
|
495
|
+
} else {
|
496
|
+
$element.setSelectionRange(6,8);
|
497
|
+
}
|
486
498
|
}, 0);
|
487
499
|
}
|
488
500
|
}
|
@@ -503,7 +515,6 @@
|
|
503
515
|
return;
|
504
516
|
}
|
505
517
|
this.hour++;
|
506
|
-
this.update();
|
507
518
|
},
|
508
519
|
|
509
520
|
incrementMinute: function(step) {
|
@@ -520,7 +531,6 @@
|
|
520
531
|
this.minute = newVal - 60;
|
521
532
|
} else {
|
522
533
|
this.minute = newVal;
|
523
|
-
this.update();
|
524
534
|
}
|
525
535
|
},
|
526
536
|
|
@@ -533,7 +543,63 @@
|
|
533
543
|
} else {
|
534
544
|
this.second = newVal;
|
535
545
|
}
|
536
|
-
|
546
|
+
},
|
547
|
+
|
548
|
+
mousewheel: function(e) {
|
549
|
+
if (this.disableMousewheel) {
|
550
|
+
return;
|
551
|
+
}
|
552
|
+
|
553
|
+
e.preventDefault();
|
554
|
+
e.stopPropagation();
|
555
|
+
|
556
|
+
var delta = e.originalEvent.wheelDelta || -e.originalEvent.detail,
|
557
|
+
scrollTo = null;
|
558
|
+
|
559
|
+
if (e.type === 'mousewheel') {
|
560
|
+
scrollTo = (e.originalEvent.wheelDelta * -1);
|
561
|
+
}
|
562
|
+
else if (e.type === 'DOMMouseScroll') {
|
563
|
+
scrollTo = 40 * e.originalEvent.detail;
|
564
|
+
}
|
565
|
+
|
566
|
+
if (scrollTo) {
|
567
|
+
e.preventDefault();
|
568
|
+
$(this).scrollTop(scrollTo + $(this).scrollTop());
|
569
|
+
}
|
570
|
+
|
571
|
+
switch (this.highlightedUnit) {
|
572
|
+
case 'minute':
|
573
|
+
if (delta > 0) {
|
574
|
+
this.incrementMinute();
|
575
|
+
} else {
|
576
|
+
this.decrementMinute();
|
577
|
+
}
|
578
|
+
this.highlightMinute();
|
579
|
+
break;
|
580
|
+
case 'second':
|
581
|
+
if (delta > 0) {
|
582
|
+
this.incrementSecond();
|
583
|
+
} else {
|
584
|
+
this.decrementSecond();
|
585
|
+
}
|
586
|
+
this.highlightSecond();
|
587
|
+
break;
|
588
|
+
case 'meridian':
|
589
|
+
this.toggleMeridian();
|
590
|
+
this.highlightMeridian();
|
591
|
+
break;
|
592
|
+
default:
|
593
|
+
if (delta > 0) {
|
594
|
+
this.incrementHour();
|
595
|
+
} else {
|
596
|
+
this.decrementHour();
|
597
|
+
}
|
598
|
+
this.highlightHour();
|
599
|
+
break;
|
600
|
+
}
|
601
|
+
|
602
|
+
return false;
|
537
603
|
},
|
538
604
|
|
539
605
|
remove: function() {
|
@@ -544,15 +610,31 @@
|
|
544
610
|
delete this.$element.data().timepicker;
|
545
611
|
},
|
546
612
|
|
547
|
-
setDefaultTime: function(defaultTime){
|
613
|
+
setDefaultTime: function(defaultTime) {
|
548
614
|
if (!this.$element.val()) {
|
549
615
|
if (defaultTime === 'current') {
|
550
616
|
var dTime = new Date(),
|
551
617
|
hours = dTime.getHours(),
|
552
|
-
minutes =
|
553
|
-
seconds =
|
618
|
+
minutes = dTime.getMinutes(),
|
619
|
+
seconds = dTime.getSeconds(),
|
554
620
|
meridian = 'AM';
|
555
621
|
|
622
|
+
if (seconds !== 0) {
|
623
|
+
seconds = Math.ceil(dTime.getSeconds() / this.secondStep) * this.secondStep;
|
624
|
+
if (seconds === 60) {
|
625
|
+
minutes += 1;
|
626
|
+
seconds = 0;
|
627
|
+
}
|
628
|
+
}
|
629
|
+
|
630
|
+
if (minutes !== 0) {
|
631
|
+
minutes = Math.ceil(dTime.getMinutes() / this.minuteStep) * this.minuteStep;
|
632
|
+
if (minutes === 60) {
|
633
|
+
hours += 1;
|
634
|
+
minutes = 0;
|
635
|
+
}
|
636
|
+
}
|
637
|
+
|
556
638
|
if (this.showMeridian) {
|
557
639
|
if (hours === 0) {
|
558
640
|
hours = 12;
|
@@ -586,70 +668,120 @@
|
|
586
668
|
}
|
587
669
|
},
|
588
670
|
|
589
|
-
setTime: function(time) {
|
590
|
-
|
591
|
-
|
671
|
+
setTime: function(time, ignoreWidget) {
|
672
|
+
if (!time) {
|
673
|
+
this.clear();
|
674
|
+
return;
|
675
|
+
}
|
592
676
|
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
677
|
+
var timeArray,
|
678
|
+
hour,
|
679
|
+
minute,
|
680
|
+
second,
|
681
|
+
meridian;
|
682
|
+
|
683
|
+
if (typeof time === 'object' && time.getMonth){
|
684
|
+
// this is a date object
|
685
|
+
hour = time.getHours();
|
686
|
+
minute = time.getMinutes();
|
687
|
+
second = time.getSeconds();
|
688
|
+
|
689
|
+
if (this.showMeridian){
|
690
|
+
meridian = 'AM';
|
691
|
+
if (hour > 12){
|
692
|
+
meridian = 'PM';
|
693
|
+
hour = hour % 12;
|
694
|
+
}
|
695
|
+
|
696
|
+
if (hour === 12){
|
697
|
+
meridian = 'PM';
|
698
|
+
}
|
699
|
+
}
|
597
700
|
} else {
|
598
|
-
|
599
|
-
|
701
|
+
if (time.match(/p/i) !== null) {
|
702
|
+
meridian = 'PM';
|
703
|
+
} else {
|
704
|
+
meridian = 'AM';
|
705
|
+
}
|
600
706
|
|
601
|
-
|
602
|
-
this.minute = parseInt(timeArray[1], 10);
|
603
|
-
this.second = parseInt(timeArray[2], 10);
|
707
|
+
time = time.replace(/[^0-9\:]/g, '');
|
604
708
|
|
605
|
-
|
606
|
-
this.hour = 0;
|
607
|
-
}
|
608
|
-
if (isNaN(this.minute)) {
|
609
|
-
this.minute = 0;
|
610
|
-
}
|
709
|
+
timeArray = time.split(':');
|
611
710
|
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
} else if (this.hour < 1) {
|
616
|
-
this.hour = 12;
|
617
|
-
}
|
711
|
+
hour = timeArray[0] ? timeArray[0].toString() : timeArray.toString();
|
712
|
+
minute = timeArray[1] ? timeArray[1].toString() : '';
|
713
|
+
second = timeArray[2] ? timeArray[2].toString() : '';
|
618
714
|
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
715
|
+
// idiot proofing
|
716
|
+
if (hour.length > 4) {
|
717
|
+
second = hour.substr(4, 2);
|
718
|
+
}
|
719
|
+
if (hour.length > 2) {
|
720
|
+
minute = hour.substr(2, 2);
|
721
|
+
hour = hour.substr(0, 2);
|
722
|
+
}
|
723
|
+
if (minute.length > 2) {
|
724
|
+
second = minute.substr(2, 2);
|
725
|
+
minute = minute.substr(0, 2);
|
726
|
+
}
|
727
|
+
if (second.length > 2) {
|
728
|
+
second = second.substr(2, 2);
|
623
729
|
}
|
624
730
|
|
625
|
-
|
626
|
-
|
731
|
+
hour = parseInt(hour, 10);
|
732
|
+
minute = parseInt(minute, 10);
|
733
|
+
second = parseInt(second, 10);
|
734
|
+
|
735
|
+
if (isNaN(hour)) {
|
736
|
+
hour = 0;
|
627
737
|
}
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
738
|
+
if (isNaN(minute)) {
|
739
|
+
minute = 0;
|
740
|
+
}
|
741
|
+
if (isNaN(second)) {
|
742
|
+
second = 0;
|
633
743
|
}
|
634
|
-
}
|
635
744
|
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
745
|
+
if (this.showMeridian) {
|
746
|
+
if (hour < 1) {
|
747
|
+
hour = 1;
|
748
|
+
} else if (hour > 12) {
|
749
|
+
hour = 12;
|
750
|
+
}
|
751
|
+
} else {
|
752
|
+
if (hour >= 24) {
|
753
|
+
hour = 23;
|
754
|
+
} else if (hour < 0) {
|
755
|
+
hour = 0;
|
756
|
+
}
|
757
|
+
if (hour < 13 && meridian === 'PM') {
|
758
|
+
hour = hour + 12;
|
759
|
+
}
|
760
|
+
}
|
641
761
|
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
762
|
+
if (minute < 0) {
|
763
|
+
minute = 0;
|
764
|
+
} else if (minute >= 60) {
|
765
|
+
minute = 59;
|
766
|
+
}
|
767
|
+
|
768
|
+
if (this.showSeconds) {
|
769
|
+
if (isNaN(second)) {
|
770
|
+
second = 0;
|
771
|
+
} else if (second < 0) {
|
772
|
+
second = 0;
|
773
|
+
} else if (second >= 60) {
|
774
|
+
second = 59;
|
775
|
+
}
|
649
776
|
}
|
650
777
|
}
|
651
778
|
|
652
|
-
this.
|
779
|
+
this.hour = hour;
|
780
|
+
this.minute = minute;
|
781
|
+
this.second = second;
|
782
|
+
this.meridian = meridian;
|
783
|
+
|
784
|
+
this.update(ignoreWidget);
|
653
785
|
},
|
654
786
|
|
655
787
|
showWidget: function() {
|
@@ -662,9 +794,9 @@
|
|
662
794
|
}
|
663
795
|
|
664
796
|
var self = this;
|
665
|
-
$(document).on('mousedown.timepicker', function (e) {
|
797
|
+
$(document).on('mousedown.timepicker, touchend.timepicker', function (e) {
|
666
798
|
// Clicked outside the timepicker, hide it
|
667
|
-
if ($(e.target).closest('.bootstrap-timepicker-widget')
|
799
|
+
if ($(e.target).closest('.bootstrap-timepicker-widget').length === 0) {
|
668
800
|
self.hideWidget();
|
669
801
|
}
|
670
802
|
});
|
@@ -684,7 +816,14 @@
|
|
684
816
|
this.$element.blur();
|
685
817
|
}
|
686
818
|
|
687
|
-
|
819
|
+
// widget shouldn't be empty on open
|
820
|
+
if (!this.hour) {
|
821
|
+
if (this.defaultTime) {
|
822
|
+
this.setDefaultTime(this.defaultTime);
|
823
|
+
} else {
|
824
|
+
this.setTime('0:0:0');
|
825
|
+
}
|
826
|
+
}
|
688
827
|
|
689
828
|
if (this.template === 'modal' && this.$widget.modal) {
|
690
829
|
this.$widget.modal('show').on('hidden', $.proxy(this.hideWidget, this));
|
@@ -699,10 +838,9 @@
|
|
699
838
|
|
700
839
|
toggleMeridian: function() {
|
701
840
|
this.meridian = this.meridian === 'AM' ? 'PM' : 'AM';
|
702
|
-
this.update();
|
703
841
|
},
|
704
842
|
|
705
|
-
update: function() {
|
843
|
+
update: function(ignoreWidget) {
|
706
844
|
this.$element.trigger({
|
707
845
|
'type': 'changeTime.timepicker',
|
708
846
|
'time': {
|
@@ -715,7 +853,9 @@
|
|
715
853
|
});
|
716
854
|
|
717
855
|
this.updateElement();
|
718
|
-
|
856
|
+
if (!ignoreWidget) {
|
857
|
+
this.updateWidget();
|
858
|
+
}
|
719
859
|
},
|
720
860
|
|
721
861
|
updateElement: function() {
|
@@ -723,11 +863,7 @@
|
|
723
863
|
},
|
724
864
|
|
725
865
|
updateFromElementVal: function() {
|
726
|
-
|
727
|
-
|
728
|
-
if (val) {
|
729
|
-
this.setTime(val);
|
730
|
-
}
|
866
|
+
this.setTime(this.$element.val());
|
731
867
|
},
|
732
868
|
|
733
869
|
updateWidget: function() {
|
@@ -735,9 +871,9 @@
|
|
735
871
|
return;
|
736
872
|
}
|
737
873
|
|
738
|
-
var hour = this.hour
|
739
|
-
minute = this.minute
|
740
|
-
second = this.second
|
874
|
+
var hour = this.hour,
|
875
|
+
minute = this.minute.toString().length === 1 ? '0' + this.minute : this.minute,
|
876
|
+
second = this.second.toString().length === 1 ? '0' + this.second : this.second;
|
741
877
|
|
742
878
|
if (this.showInputs) {
|
743
879
|
this.$widget.find('input.bootstrap-timepicker-hour').val(hour);
|
@@ -766,47 +902,42 @@
|
|
766
902
|
if (this.$widget === false) {
|
767
903
|
return;
|
768
904
|
}
|
769
|
-
var time = $('input.bootstrap-timepicker-hour', this.$widget).val() + ':' +
|
770
|
-
$('input.bootstrap-timepicker-minute', this.$widget).val() +
|
771
|
-
(this.showSeconds ? ':' + $('input.bootstrap-timepicker-second', this.$widget).val() : '') +
|
772
|
-
(this.showMeridian ? ' ' + $('input.bootstrap-timepicker-meridian', this.$widget).val() : '');
|
773
905
|
|
774
|
-
this.
|
906
|
+
var t = this.$widget.find('input.bootstrap-timepicker-hour').val() + ':' +
|
907
|
+
this.$widget.find('input.bootstrap-timepicker-minute').val() +
|
908
|
+
(this.showSeconds ? ':' + this.$widget.find('input.bootstrap-timepicker-second').val() : '') +
|
909
|
+
(this.showMeridian ? this.$widget.find('input.bootstrap-timepicker-meridian').val() : '')
|
910
|
+
;
|
911
|
+
|
912
|
+
this.setTime(t, true);
|
775
913
|
},
|
776
914
|
|
777
915
|
widgetClick: function(e) {
|
778
916
|
e.stopPropagation();
|
779
917
|
e.preventDefault();
|
780
918
|
|
781
|
-
var
|
919
|
+
var $input = $(e.target),
|
920
|
+
action = $input.closest('a').data('action');
|
921
|
+
|
782
922
|
if (action) {
|
783
923
|
this[action]();
|
784
924
|
}
|
925
|
+
this.update();
|
926
|
+
|
927
|
+
if ($input.is('input')) {
|
928
|
+
$input.get(0).setSelectionRange(0,2);
|
929
|
+
}
|
785
930
|
},
|
786
931
|
|
787
932
|
widgetKeydown: function(e) {
|
788
|
-
var $input = $(e.target)
|
789
|
-
name = $input.attr('
|
933
|
+
var $input = $(e.target),
|
934
|
+
name = $input.attr('class').replace('bootstrap-timepicker-', '');
|
790
935
|
|
791
936
|
switch (e.keyCode) {
|
792
937
|
case 9: //tab
|
793
|
-
if (this.showMeridian) {
|
794
|
-
|
795
|
-
return this.hideWidget();
|
796
|
-
}
|
797
|
-
} else {
|
798
|
-
if (this.showSeconds) {
|
799
|
-
if (name === 'second') {
|
800
|
-
return this.hideWidget();
|
801
|
-
}
|
802
|
-
} else {
|
803
|
-
if (name === 'minute') {
|
804
|
-
return this.hideWidget();
|
805
|
-
}
|
806
|
-
}
|
938
|
+
if ((this.showMeridian && name === 'meridian') || (this.showSeconds && name === 'second') || (!this.showMeridian && !this.showSeconds && name === 'minute')) {
|
939
|
+
return this.hideWidget();
|
807
940
|
}
|
808
|
-
|
809
|
-
this.updateFromWidgetInputs();
|
810
941
|
break;
|
811
942
|
case 27: // escape
|
812
943
|
this.hideWidget();
|
@@ -827,6 +958,8 @@
|
|
827
958
|
this.toggleMeridian();
|
828
959
|
break;
|
829
960
|
}
|
961
|
+
this.setTime(this.getTime());
|
962
|
+
$input.get(0).setSelectionRange(0,2);
|
830
963
|
break;
|
831
964
|
case 40: // down arrow
|
832
965
|
e.preventDefault();
|
@@ -844,12 +977,19 @@
|
|
844
977
|
this.toggleMeridian();
|
845
978
|
break;
|
846
979
|
}
|
980
|
+
this.setTime(this.getTime());
|
981
|
+
$input.get(0).setSelectionRange(0,2);
|
847
982
|
break;
|
848
983
|
}
|
984
|
+
},
|
985
|
+
|
986
|
+
widgetKeyup: function(e) {
|
987
|
+
if ((e.keyCode === 65) || (e.keyCode === 77) || (e.keyCode === 80) || (e.keyCode === 46) || (e.keyCode === 8) || (e.keyCode >= 46 && e.keyCode <= 57)) {
|
988
|
+
this.updateFromWidgetInputs();
|
989
|
+
}
|
849
990
|
}
|
850
991
|
};
|
851
992
|
|
852
|
-
|
853
993
|
//TIMEPICKER PLUGIN DEFINITION
|
854
994
|
$.fn.timepicker = function(option) {
|
855
995
|
var args = Array.apply(null, arguments);
|
@@ -872,6 +1012,7 @@
|
|
872
1012
|
$.fn.timepicker.defaults = {
|
873
1013
|
defaultTime: 'current',
|
874
1014
|
disableFocus: false,
|
1015
|
+
disableMousewheel: false,
|
875
1016
|
isOpen: false,
|
876
1017
|
minuteStep: 15,
|
877
1018
|
modalBackdrop: false,
|