Skip to content

Commit 520fb81

Browse files
committed
pull 0.9.6 from trentrichardson
2 parents aa9a5ca + 4496926 commit 520fb81

18 files changed

+321
-120
lines changed

README

Lines changed: 0 additions & 8 deletions
This file was deleted.

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
jQuery Timepicker Addon
2+
=======================
3+
4+
Use
5+
---
6+
- To use this plugin you must include jQuery and jQuery UI with datepicker and slider
7+
- Include timepicker-addon script
8+
- now use timepicker with $('#selector').datetimepicker() or $('#selector').timepicker()
9+
10+
Contributing Code - Please Read!
11+
--------------------------------
12+
All code contributions and bug reports are much appreciated. Please be sure to apply your fixes to the "dev" branch.

jquery-ui-timepicker-addon.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.ui-timepicker-div dl dt { height: 25px; }
44
.ui-timepicker-div dl dd { margin: -25px 10px 10px 65px; }
55
.ui-timepicker-div td { font-size: 90%; }
6+
.ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; }

jquery-ui-timepicker-addon.js

Lines changed: 81 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* jQuery timepicker addon
33
* By: Trent Richardson [http://trentrichardson.com]
4-
* Version 0.9.5
5-
* Last Modified: 05/25/2011
4+
* Version 0.9.6
5+
* Last Modified: 07/20/2011
66
*
77
* Copyright 2011 Trent Richardson
88
* Dual licensed under the MIT and GPL licenses.
@@ -19,7 +19,7 @@
1919

2020
(function($) {
2121

22-
$.extend($.ui, { timepicker: { version: "0.9.5" } });
22+
$.extend($.ui, { timepicker: { version: "0.9.6" } });
2323

2424
/* Time picker manager.
2525
Use the singleton instance of this class, $.timepicker, to interact with the time picker.
@@ -33,6 +33,7 @@ function Timepicker() {
3333
closeText: 'Done',
3434
ampm: false,
3535
timeFormat: 'hh:mm tt',
36+
timeSuffix: '',
3637
timeOnlyTitle: 'Choose Time',
3738
timeText: 'Time',
3839
hourText: 'Hour',
@@ -161,7 +162,7 @@ $.extend(Timepicker.prototype, {
161162
tp_inst.$altInput = $(o.altField)
162163
.css({ cursor: 'pointer' })
163164
.focus(function(){ $input.trigger("focus"); });
164-
165+
165166
// datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime..
166167
if(tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date)
167168
tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime());
@@ -171,7 +172,7 @@ $.extend(Timepicker.prototype, {
171172
tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime());
172173
if(tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date)
173174
tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime());
174-
175+
175176
return tp_inst;
176177
},
177178

@@ -198,7 +199,7 @@ $.extend(Timepicker.prototype, {
198199
.replace(/s{1,2}/ig, '(\\d?\\d)')
199200
.replace(/t{1,2}/ig, '(am|pm|a|p)?')
200201
.replace(/z{1}/ig, '((\\+|-)\\d\\d\\d\\d)?')
201-
.replace(/\s/g, '\\s?') + '$',
202+
.replace(/\s/g, '\\s?') + this._defaults.timeSuffix + '$',
202203
order = this._getFormatPositions(),
203204
treg;
204205

@@ -288,9 +289,9 @@ $.extend(Timepicker.prototype, {
288289
if (o.showHour && o.hourGrid > 0) {
289290
html += '<dd class="ui_tpicker_hour">' +
290291
'<div id="ui_tpicker_hour_' + dp_id + '"' + ((o.showHour) ? '' : noDisplay) + '></div>' +
291-
'<div style="padding-left: 1px"><table><tr>';
292+
'<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>';
292293

293-
for (var h = o.hourMin; h < hourMax; h += o.hourGrid) {
294+
for (var h = o.hourMin; h <= hourMax; h += o.hourGrid) {
294295
hourGridSize++;
295296
var tmph = (o.ampm && h > 12) ? h-12 : h;
296297
if (tmph < 10) tmph = '0' + tmph;
@@ -314,9 +315,9 @@ $.extend(Timepicker.prototype, {
314315
html += '<dd class="ui_tpicker_minute ui_tpicker_minute_' + o.minuteGrid + '">' +
315316
'<div id="ui_tpicker_minute_' + dp_id + '"' +
316317
((o.showMinute) ? '' : noDisplay) + '></div>' +
317-
'<div style="padding-left: 1px"><table><tr>';
318+
'<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>';
318319

319-
for (var m = o.minuteMin; m < minMax; m += o.minuteGrid) {
320+
for (var m = o.minuteMin; m <= minMax; m += o.minuteGrid) {
320321
minuteGridSize++;
321322
html += '<td>' + ((m < 10) ? '0' : '') + m + '</td>';
322323
}
@@ -335,7 +336,7 @@ $.extend(Timepicker.prototype, {
335336
((o.showSecond) ? '' : noDisplay) + '></div>' +
336337
'<div style="padding-left: 1px"><table><tr>';
337338

338-
for (var s = o.secondMin; s < secMax; s += o.secondGrid) {
339+
for (var s = o.secondMin; s <= secMax; s += o.secondGrid) {
339340
secondGridSize++;
340341
html += '<td>' + ((s < 10) ? '0' : '') + s + '</td>';
341342
}
@@ -428,7 +429,7 @@ $.extend(Timepicker.prototype, {
428429
var h = $(this).html();
429430
if(o.ampm) {
430431
var ap = h.substring(2).toLowerCase(),
431-
aph = parseInt(h.substring(0,2));
432+
aph = parseInt(h.substring(0,2), 10);
432433
if (ap == 'a') {
433434
if (aph == 12) h = 0;
434435
else h = aph;
@@ -518,8 +519,8 @@ $.extend(Timepicker.prototype, {
518519

519520
if(!this._defaults.showTimepicker) return; // No time so nothing to check here
520521

521-
if(this._defaults.minDateTime !== null && dp_date){
522-
var minDateTime = this._defaults.minDateTime,
522+
if($.datepicker._get(dp_inst, 'minDateTime') !== null && dp_date){
523+
var minDateTime = $.datepicker._get(dp_inst, 'minDateTime'),
523524
minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0);
524525

525526
if(this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null){
@@ -551,8 +552,8 @@ $.extend(Timepicker.prototype, {
551552
}
552553
}
553554

554-
if(this._defaults.maxDateTime !== null && dp_date){
555-
var maxDateTime = this._defaults.maxDateTime,
555+
if($.datepicker._get(dp_inst, 'maxDateTime') !== null && dp_date){
556+
var maxDateTime = $.datepicker._get(dp_inst, 'maxDateTime'),
556557
maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0);
557558

558559
if(this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null){
@@ -568,7 +569,7 @@ $.extend(Timepicker.prototype, {
568569
this._defaults.minuteMax = maxDateTime.getMinutes();
569570
if (this.minute >= this._defaults.minuteMax) {
570571
this.minute = this._defaults.minuteMax;
571-
this._defaults.secondMin = maxDateTime.getSeconds();
572+
this._defaults.secondMax = maxDateTime.getSeconds();
572573
} else {
573574
if(this.second > this._defaults.secondMax) this.second = this._defaults.secondMax;
574575
this._defaults.secondMax = this.secondMaxOriginal;
@@ -585,9 +586,16 @@ $.extend(Timepicker.prototype, {
585586
}
586587

587588
if(adjustSliders !== undefined && adjustSliders === true){
588-
this.hour_slider.slider("option", { min: this._defaults.hourMin, max: this._defaults.hourMax }).slider('value', this.hour);
589-
this.minute_slider.slider("option", { min: this._defaults.minuteMin, max: this._defaults.minuteMax }).slider('value', this.minute);
590-
this.second_slider.slider("option", { min: this._defaults.secondMin, max: this._defaults.secondMax }).slider('value', this.second);
589+
var hourMax = (this._defaults.hourMax - (this._defaults.hourMax % this._defaults.stepHour)).toFixed(0),
590+
minMax = (this._defaults.minuteMax - (this._defaults.minuteMax % this._defaults.stepMinute)).toFixed(0),
591+
secMax = (this._defaults.secondMax - (this._defaults.secondMax % this._defaults.stepSecond)).toFixed(0);
592+
593+
if(this.hour_slider)
594+
this.hour_slider.slider("option", { min: this._defaults.hourMin, max: hourMax }).slider('value', this.hour);
595+
if(this.minute_slider)
596+
this.minute_slider.slider("option", { min: this._defaults.minuteMin, max: minMax }).slider('value', this.minute);
597+
if(this.second_slider)
598+
this.second_slider.slider("option", { min: this._defaults.secondMin, max: secMax }).slider('value', this.second);
591599
}
592600

593601
},
@@ -602,13 +610,18 @@ $.extend(Timepicker.prototype, {
602610
minute = (this.minute_slider) ? this.minute_slider.slider('value') : false,
603611
second = (this.second_slider) ? this.second_slider.slider('value') : false,
604612
timezone = (this.timezone_select) ? this.timezone_select.val() : false;
605-
613+
614+
if (typeof(hour) == 'object') hour = false;
615+
if (typeof(minute) == 'object') minute = false;
616+
if (typeof(second) == 'object') second = false;
617+
if (typeof(timezone) == 'object') timezone = false;
618+
606619
if (hour !== false) hour = parseInt(hour,10);
607620
if (minute !== false) minute = parseInt(minute,10);
608621
if (second !== false) second = parseInt(second,10);
609622

610623
var ampm = (hour < 12) ? 'AM' : 'PM';
611-
624+
612625
// If the update was done in the input field, the input field should not be updated.
613626
// If the update was done using the sliders, update the input field.
614627
var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || (this.ampm.length > 0 && this.ampm != ampm) || timezone != this.timezone);
@@ -619,12 +632,15 @@ $.extend(Timepicker.prototype, {
619632
if (minute !== false) this.minute = minute;
620633
if (second !== false) this.second = second;
621634
if (timezone !== false) this.timezone = timezone;
635+
636+
if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]);
637+
622638
this._limitMinMaxDateTime(this.inst, true);
623639
}
624640
if (this._defaults.ampm) this.ampm = ampm;
625641

626642
this._formatTime();
627-
if (this.$timeObj) this.$timeObj.text(this.formattedTime);
643+
if (this.$timeObj) this.$timeObj.text(this.formattedTime + this._defaults.timeSuffix);
628644
this.timeDefined = true;
629645
if (hasChanged) this._updateDateTime();
630646
},
@@ -699,7 +715,7 @@ $.extend(Timepicker.prototype, {
699715
if (this._defaults.timeOnly === true) {
700716
formattedDateTime = this.formattedTime;
701717
} else if (this._defaults.timeOnly !== true && (this._defaults.alwaysSetTime || timeAvailable)) {
702-
formattedDateTime += this._defaults.separator + this.formattedTime;
718+
formattedDateTime += this._defaults.separator + this.formattedTime + this._defaults.timeSuffix;
703719
}
704720

705721
this.formattedDateTime = formattedDateTime;
@@ -774,7 +790,7 @@ $.datepicker._selectDate = function (id, dateStr) {
774790
tp_inst._limitMinMaxDateTime(inst, true);
775791
inst.inline = inst.stay_open = true;
776792
//This way the onSelect handler called from calendarpicker get the full dateTime
777-
this._base_selectDate(id, dateStr + tp_inst._defaults.separator + tp_inst.formattedTime);
793+
this._base_selectDate(id, dateStr + tp_inst._defaults.separator + tp_inst.formattedTime + tp_inst._defaults.timeSuffix);
778794
inst.inline = inst.stay_open = false;
779795
this._notifyChange(inst);
780796
this._updateDatepicker(inst);
@@ -788,6 +804,16 @@ $.datepicker._selectDate = function (id, dateStr) {
788804
//#############################################################################################
789805
$.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker;
790806
$.datepicker._updateDatepicker = function(inst) {
807+
808+
// don't popup the datepicker if there is another instance already opened
809+
var input = inst.input[0];
810+
if($.datepicker._curInst &&
811+
$.datepicker._curInst != inst &&
812+
$.datepicker._datepickerShowing &&
813+
$.datepicker._lastInput != input) {
814+
return;
815+
}
816+
791817
if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {
792818

793819
this._base_updateDatepicker(inst);
@@ -799,7 +825,7 @@ $.datepicker._updateDatepicker = function(inst) {
799825
};
800826

801827
//#######################################################################################
802-
// third bad hack :/ override datepicker so it allows spaces and colan in the input field
828+
// third bad hack :/ override datepicker so it allows spaces and colon in the input field
803829
//#######################################################################################
804830
$.datepicker._base_doKeyPress = $.datepicker._doKeyPress;
805831
$.datepicker._doKeyPress = function(event) {
@@ -809,6 +835,7 @@ $.datepicker._doKeyPress = function(event) {
809835
if (tp_inst) {
810836
if ($.datepicker._get(inst, 'constrainInput')) {
811837
var ampm = tp_inst._defaults.ampm,
838+
dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
812839
datetimeChars = tp_inst._defaults.timeFormat.toString()
813840
.replace(/[hms]/g, '')
814841
.replace(/TT/g, ampm ? 'APM' : '')
@@ -819,9 +846,11 @@ $.datepicker._doKeyPress = function(event) {
819846
.replace(/t/g, ampm ? 'ap' : '') +
820847
" " +
821848
tp_inst._defaults.separator +
822-
$.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
849+
tp_inst._defaults.timeSuffix +
850+
(tp_inst._defaults.showTimezone ? tp_inst._defaults.timezoneList.join('') : '') +
851+
dateChars,
823852
chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
824-
return event.ctrlKey || (chr < ' ' || !datetimeChars || datetimeChars.indexOf(chr) > -1);
853+
return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1);
825854
}
826855
}
827856

@@ -902,12 +931,13 @@ $.datepicker._setTime = function(inst, date) {
902931
second = defaults.secondMin;
903932
}
904933

934+
tp_inst.hour = hour;
935+
tp_inst.minute = minute;
936+
tp_inst.second = second;
937+
905938
if (tp_inst.hour_slider) tp_inst.hour_slider.slider('value', hour);
906-
else tp_inst.hour = hour;
907939
if (tp_inst.minute_slider) tp_inst.minute_slider.slider('value', minute);
908-
else tp_inst.minute = minute;
909940
if (tp_inst.second_slider) tp_inst.second_slider.slider('value', second);
910-
else tp_inst.second = second;
911941

912942
tp_inst._onTimeChange();
913943
tp_inst._updateDateTime(inst);
@@ -968,13 +998,31 @@ $.datepicker._getDateDatepicker = function(target, noDefault) {
968998
return this._base_getDateDatepicker(target, noDefault);
969999
};
9701000

1001+
//#######################################################################################
1002+
// override parseDate() because UI 1.8.14 throws an error about "Extra characters"
1003+
// An option in datapicker to ignore extra format characters would be nicer.
1004+
//#######################################################################################
1005+
$.datepicker._base_parseDate = $.datepicker.parseDate;
1006+
$.datepicker.parseDate = function(format, value, settings) {
1007+
var date;
1008+
try {
1009+
date = this._base_parseDate(format, value, settings);
1010+
} catch (err) {
1011+
// Hack! The error message ends with a colon, a space, and
1012+
// the "extra" characters. We rely on that instead of
1013+
// attempting to perfectly reproduce the parsing algorithm.
1014+
date = this._base_parseDate(format, value.substring(0,value.length-(err.length-err.indexOf(':')-2)), settings);
1015+
}
1016+
return date;
1017+
};
1018+
9711019
//#######################################################################################
9721020
// override options setter to add time to maxDate(Time) and minDate(Time)
9731021
//#######################################################################################
9741022
$.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker;
9751023
$.datepicker._optionDatepicker = function(target, name, value) {
9761024
this._base_optionDatepicker(target, name, value);
977-
var inst = this._getInst(target),
1025+
var inst = this._getInst(target),
9781026
tp_inst = this._get(inst, 'timepicker');
9791027
if (tp_inst) {
9801028
//Set minimum and maximum date values if we have timepicker
@@ -1007,6 +1055,6 @@ function extendRemove(target, props) {
10071055
}
10081056

10091057
$.timepicker = new Timepicker(); // singleton instance
1010-
$.timepicker.version = "0.9.5";
1058+
$.timepicker.version = "0.9.6";
10111059

10121060
})(jQuery);
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
/* Czech translation for the jQuery Timepicker Addon */
22
/* Written by Ondřej Vodáček */
3-
$.timepicker.regional['cs'] = {
4-
timeOnlyTitle: 'Vyberte čas',
5-
timeText: 'Čas',
6-
hourText: 'Hodiny',
7-
minuteText: 'Minuty',
8-
secondText: 'Vteřiny',
9-
timezoneText: 'Časové pásmo',
10-
currentText: 'Nyní',
11-
closeText: 'Zavřít',
12-
timeFormat: 'h:m',
13-
ampm: false
14-
};
15-
$.timepicker.setDefaults($.timepicker.regional['cs']);
3+
(function($) {
4+
$.timepicker.regional['cs'] = {
5+
timeOnlyTitle: 'Vyberte čas',
6+
timeText: 'Čas',
7+
hourText: 'Hodiny',
8+
minuteText: 'Minuty',
9+
secondText: 'Vteřiny',
10+
timezoneText: 'Časové pásmo',
11+
currentText: 'Nyní',
12+
closeText: 'Zavřít',
13+
timeFormat: 'h:m',
14+
ampm: false
15+
};
16+
$.timepicker.setDefaults($.timepicker.regional['cs']);
17+
})(jQuery);
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
/* German translation for the jQuery Timepicker Addon */
22
/* Written by Marvin */
3-
$.timepicker.regional['de'] = {
4-
timeOnlyTitle: 'Zeit Wählen',
5-
timeText: 'Zeit',
6-
hourText: 'Stunde',
7-
minuteText: 'Minute',
8-
secondText: 'Sekunde',
9-
timezoneText: 'Zeitzone',
10-
currentText: 'Jetzt',
11-
closeText: 'Fertig',
12-
timeFormat: 'hh:mm tt',
13-
ampm: false
14-
};
15-
$.timepicker.setDefaults($.timepicker.regional['de']);
3+
(function($) {
4+
$.timepicker.regional['de'] = {
5+
timeOnlyTitle: 'Zeit Wählen',
6+
timeText: 'Zeit',
7+
hourText: 'Stunde',
8+
minuteText: 'Minute',
9+
secondText: 'Sekunde',
10+
timezoneText: 'Zeitzone',
11+
currentText: 'Jetzt',
12+
closeText: 'Fertig',
13+
timeFormat: 'hh:mm tt',
14+
ampm: false
15+
};
16+
$.timepicker.setDefaults($.timepicker.regional['de']);
17+
})(jQuery);

0 commit comments

Comments
 (0)