Skip to content

Commit 9c10031

Browse files
Merge pull request trentrichardson#325 from rossj/dev
Merge pull request by rossj
2 parents 5eb5402 + caea8b1 commit 9c10031

File tree

1 file changed

+61
-61
lines changed

1 file changed

+61
-61
lines changed

jquery-ui-timepicker-addon.js

+61-61
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
22
* jQuery timepicker addon
33
* By: Trent Richardson [http://trentrichardson.com]
4-
* Version 0.9.9
4+
* Version 1.0.0-dev
55
* Last Modified: 02/05/2012
6-
*
6+
*
77
* Copyright 2012 Trent Richardson
88
* Dual licensed under the MIT and GPL licenses.
99
* http://trentrichardson.com/Impromptu/GPL-LICENSE.txt
1010
* http://trentrichardson.com/Impromptu/MIT-LICENSE.txt
11-
*
11+
*
1212
* HERES THE CSS:
1313
* .ui-timepicker-div .ui-widget-header { margin-bottom: 8px; }
1414
* .ui-timepicker-div dl { text-align: left; }
@@ -20,7 +20,13 @@
2020

2121
(function($) {
2222

23-
$.extend($.ui, { timepicker: { version: "0.9.9" } });
23+
// Prevent "Uncaught RangeError: Maximum call stack size exceeded"
24+
$.ui.timepicker = $.ui.timepicker || {};
25+
if ($.ui.timepicker.version) {
26+
return;
27+
}
28+
29+
$.extend($.ui, { timepicker: { version: "1.0.0" } });
2430

2531
/* Time picker manager.
2632
Use the singleton instance of this class, $.timepicker, to interact with the time picker.
@@ -133,7 +139,7 @@ $.extend(Timepicker.prototype, {
133139
_newInst: function($input, o) {
134140
var tp_inst = new Timepicker(),
135141
inlineSettings = {};
136-
142+
137143
for (var attrName in this._defaults) {
138144
var attrValue = $input.attr('time:' + attrName);
139145
if (attrValue) {
@@ -163,8 +169,8 @@ $.extend(Timepicker.prototype, {
163169
},
164170
timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
165171
});
166-
tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) { return val.toUpperCase() });
167-
tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) { return val.toUpperCase() });
172+
tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) { return val.toUpperCase(); });
173+
tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) { return val.toUpperCase(); });
168174

169175
if (tp_inst._defaults.timezoneList === null) {
170176
var timezoneList = [];
@@ -188,7 +194,7 @@ $.extend(Timepicker.prototype, {
188194
tp_inst.$altInput = $(o.altField)
189195
.css({ cursor: 'pointer' })
190196
.focus(function(){ $input.trigger("focus"); });
191-
197+
192198
if(tp_inst._defaults.minDate==0 || tp_inst._defaults.minDateTime==0)
193199
{
194200
tp_inst._defaults.minDate=new Date();
@@ -197,7 +203,7 @@ $.extend(Timepicker.prototype, {
197203
{
198204
tp_inst._defaults.maxDate=new Date();
199205
}
200-
206+
201207
// datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime..
202208
if(tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date)
203209
tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime());
@@ -215,7 +221,7 @@ $.extend(Timepicker.prototype, {
215221
//########################################################################
216222
_addTimePicker: function(dp_inst) {
217223
var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ?
218-
this.$input.val() + ' ' + this.$altInput.val() :
224+
this.$input.val() + ' ' + this.$altInput.val() :
219225
this.$input.val();
220226

221227
this.timeDefined = this._parseTime(currDT);
@@ -249,7 +255,7 @@ $.extend(Timepicker.prototype, {
249255
var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g");
250256
regstr = '^.{' + dp_dateFormat.length + ',}?' + this._defaults.separator.replace(specials, "\\$&") + regstr;
251257
}
252-
258+
253259
treg = timeString.match(new RegExp(regstr, 'i'));
254260

255261
if (treg) {
@@ -297,7 +303,7 @@ $.extend(Timepicker.prototype, {
297303
}
298304
this.timezone = tz;
299305
}
300-
306+
301307
return true;
302308

303309
}
@@ -308,13 +314,13 @@ $.extend(Timepicker.prototype, {
308314
// pattern for standard and localized AM/PM markers
309315
//########################################################################
310316
_getPatternAmpm: function() {
311-
var markers = [];
317+
var markers = [],
312318
o = this._defaults;
313319
if (o.amNames)
314320
$.merge(markers, o.amNames);
315321
if (o.pmNames)
316322
$.merge(markers, o.pmNames);
317-
markers = $.map(markers, function(val) { return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&') });
323+
markers = $.map(markers, function(val) { return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&'); });
318324
return '(' + markers.join('|') + ')?';
319325
},
320326

@@ -364,7 +370,7 @@ $.extend(Timepicker.prototype, {
364370
minuteGridSize = 0,
365371
secondGridSize = 0,
366372
millisecGridSize = 0,
367-
size;
373+
size = null;
368374

369375
// Hours
370376
html += '<dd class="ui_tpicker_hour"><div id="ui_tpicker_hour_' + dp_id + '"' +
@@ -472,7 +478,7 @@ $.extend(Timepicker.prototype, {
472478
}
473479
});
474480

475-
481+
476482
// Updated by Peter Medeiros:
477483
// - Pass in Event and UI instance into slide function
478484
this.minute_slider = $tp.find('#ui_tpicker_minute_'+ dp_id).slider({
@@ -634,7 +640,7 @@ $.extend(Timepicker.prototype, {
634640
this.minute_slider.bind('slidestop',onSelectDelegate);
635641
this.second_slider.bind('slidestop',onSelectDelegate);
636642
this.millisec_slider.bind('slidestop',onSelectDelegate);
637-
643+
638644
// slideAccess integration: http://trentrichardson.com/2011/11/11/jquery-ui-sliders-and-touch-accessibility/
639645
if (this._defaults.addSliderAccess){
640646
var sliderAccessArgs = this._defaults.sliderAccessArgs;
@@ -651,15 +657,15 @@ $.extend(Timepicker.prototype, {
651657
oldMarginLeft = $g.css('marginLeft').toString().replace('%',''),
652658
newWidth = oldWidth - sliderAccessWidth,
653659
newMarginLeft = ((oldMarginLeft * newWidth)/oldWidth) + '%';
654-
660+
655661
$g.css({ width: newWidth, marginLeft: newMarginLeft });
656662
});
657663
}
658664
}
659665
},0);
660666
}
661667
// end slideAccess integration
662-
668+
663669
}
664670
},
665671

@@ -770,7 +776,7 @@ $.extend(Timepicker.prototype, {
770776

771777
},
772778

773-
779+
774780
//########################################################################
775781
// when a slider moves, set the internal time...
776782
// on time change is also called when the time is updated in the text field
@@ -803,30 +809,30 @@ $.extend(Timepicker.prototype, {
803809
|| (this.ampm.length > 0
804810
&& (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1))
805811
|| timezone != this.timezone);
806-
812+
807813
if (hasChanged) {
808814

809815
if (hour !== false)this.hour = hour;
810816
if (minute !== false) this.minute = minute;
811817
if (second !== false) this.second = second;
812818
if (millisec !== false) this.millisec = millisec;
813819
if (timezone !== false) this.timezone = timezone;
814-
820+
815821
if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]);
816-
822+
817823
this._limitMinMaxDateTime(this.inst, true);
818824
}
819825
if (o.ampm) this.ampm = ampm;
820-
826+
821827
//this._formatTime();
822828
this.formattedTime = $.datepicker.formatTime(this._defaults.timeFormat, this, this._defaults);
823829
if (this.$timeObj) this.$timeObj.text(this.formattedTime + o.timeSuffix);
824830
this.timeDefined = true;
825831
if (hasChanged) this._updateDateTime();
826832
},
827-
833+
828834
//########################################################################
829-
// call custom onSelect.
835+
// call custom onSelect.
830836
// bind to sliders slidestop, and grid click.
831837
//########################################################################
832838
_onSelectHandler: function() {
@@ -845,7 +851,7 @@ $.extend(Timepicker.prototype, {
845851
var tmptime = (format || this._defaults.timeFormat).toString();
846852

847853
tmptime = $.datepicker.formatTime(tmptime, time, this._defaults);
848-
854+
849855
if (arguments.length) return tmptime;
850856
else this.formattedTime = tmptime;
851857
},
@@ -883,7 +889,7 @@ $.extend(Timepicker.prototype, {
883889
} else {
884890
this.$input.val(formattedDateTime);
885891
}
886-
892+
887893
this.$input.trigger("change");
888894
}
889895

@@ -909,13 +915,12 @@ $.fn.extend({
909915
//########################################################################
910916
datetimepicker: function(o) {
911917
o = o || {};
912-
var $input = this,
913918
tmp_args = arguments;
914919

915920
if (typeof(o) == 'string'){
916-
if(o == 'getDate')
921+
if(o == 'getDate')
917922
return $.fn.datepicker.apply($(this[0]), tmp_args);
918-
else
923+
else
919924
return this.each(function() {
920925
var $t = $(this);
921926
$t.datepicker.apply($t, tmp_args);
@@ -930,7 +935,7 @@ $.fn.extend({
930935
});
931936

932937
//########################################################################
933-
// format the time all pretty...
938+
// format the time all pretty...
934939
// format = string format of the time
935940
// time = a {}, not a Date() for timezones
936941
// options = essentially the regional[].. amNames, pmNames, ampm
@@ -939,7 +944,7 @@ $.datepicker.formatTime = function(format, time, options) {
939944
options = options || {};
940945
options = $.extend($.timepicker._defaults, options);
941946
time = $.extend({hour:0, minute:0, second:0, millisec:0, timezone:'+0000'}, time);
942-
947+
943948
var tmptime = format;
944949
var ampmName = options['amNames'][0];
945950

@@ -975,7 +980,7 @@ $.datepicker.formatTime = function(format, time, options) {
975980

976981
tmptime = $.trim(tmptime);
977982
return tmptime;
978-
}
983+
};
979984

980985
//########################################################################
981986
// the bad hack :/ override datepicker so it doesnt close on select
@@ -1015,9 +1020,9 @@ $.datepicker._updateDatepicker = function(inst) {
10151020
}
10161021

10171022
if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {
1018-
1023+
10191024
this._base_updateDatepicker(inst);
1020-
1025+
10211026
// Reload the time control when changing something in the input text field.
10221027
var tp_inst = this._get(inst, 'timepicker');
10231028
if(tp_inst) tp_inst._addTimePicker(inst);
@@ -1055,7 +1060,7 @@ $.datepicker._doKeyPress = function(event) {
10551060
return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1);
10561061
}
10571062
}
1058-
1063+
10591064
return $.datepicker._base_doKeyPress(event);
10601065
};
10611066

@@ -1102,7 +1107,7 @@ $.datepicker._gotoToday = function(id) {
11021107
tp_inst.timezone_select.val(tzoffset);
11031108
}
11041109
this._setTime(inst, now);
1105-
$( '.ui-datepicker-today', $dp).click();
1110+
$( '.ui-datepicker-today', $dp).click();
11061111
};
11071112

11081113
//#######################################################################################
@@ -1245,14 +1250,11 @@ $.datepicker.parseDate = function(format, value, settings) {
12451250
//#######################################################################################
12461251
// override formatDate to set date with time to the input
12471252
//#######################################################################################
1248-
$.datepicker._base_formatDate=$.datepicker._formatDate;
1253+
$.datepicker._base_formatDate = $.datepicker._formatDate;
12491254
$.datepicker._formatDate = function(inst, day, month, year){
12501255
var tp_inst = this._get(inst, 'timepicker');
1251-
if(tp_inst)
1252-
{
1253-
if(day)
1254-
var b = this._base_formatDate(inst, day, month, year);
1255-
tp_inst._updateDateTime(inst);
1256+
if(tp_inst) {
1257+
tp_inst._updateDateTime(inst);
12561258
return tp_inst.$input.val();
12571259
}
12581260
return this._base_formatDate(inst);
@@ -1266,16 +1268,16 @@ $.datepicker._optionDatepicker = function(target, name, value) {
12661268
var inst = this._getInst(target),
12671269
tp_inst = this._get(inst, 'timepicker');
12681270
if (tp_inst) {
1269-
var min,max,onselect;
1271+
var min = null, max = null, onselect = null;
12701272
if (typeof name == 'string') { // if min/max was set with the string
1271-
if (name==='minDate' || name==='minDateTime' )
1273+
if (name === 'minDate' || name === 'minDateTime' )
12721274
min = value;
1273-
else if (name==='maxDate' || name==='maxDateTime')
1275+
else if (name === 'maxDate' || name === 'maxDateTime')
12741276
max = value;
1275-
else if (name==='onSelect')
1276-
onselect=value;
1277+
else if (name === 'onSelect')
1278+
onselect = value;
12771279
} else if (typeof name == 'object') { //if min/max was set with the JSON
1278-
if(name.minDate)
1280+
if (name.minDate)
12791281
min = name.minDate;
12801282
else if (name.minDateTime)
12811283
min = name.minDateTime;
@@ -1284,24 +1286,23 @@ $.datepicker._optionDatepicker = function(target, name, value) {
12841286
else if (name.maxDateTime)
12851287
max = name.maxDateTime;
12861288
}
1287-
if(min){ //if min was set
1288-
if(min==0)
1289-
min=new Date();
1289+
if(min) { //if min was set
1290+
if (min == 0)
1291+
min = new Date();
12901292
else
1291-
min= new Date(min);
1292-
1293+
min = new Date(min);
1294+
12931295
tp_inst._defaults.minDate = min;
12941296
tp_inst._defaults.minDateTime = min;
1295-
} else if (max){ //if max was set
1297+
} else if (max) { //if max was set
12961298
if(max==0)
12971299
max=new Date();
12981300
else
12991301
max= new Date(max);
13001302
tp_inst._defaults.maxDate = max;
13011303
tp_inst._defaults.maxDateTime = max;
1302-
}
1303-
else if (onselect)
1304-
tp_inst._defaults.onSelect=onselect;
1304+
} else if (onselect)
1305+
tp_inst._defaults.onSelect = onselect;
13051306
}
13061307
if (value === undefined)
13071308
return this._base_optionDatepicker(target, name);
@@ -1320,7 +1321,6 @@ function extendRemove(target, props) {
13201321
};
13211322

13221323
$.timepicker = new Timepicker(); // singleton instance
1323-
$.timepicker.version = "0.9.9";
1324+
$.timepicker.version = "1.0.0";
13241325

13251326
})(jQuery);
1326-

0 commit comments

Comments
 (0)