Skip to content

Commit 1dd304b

Browse files
Removed unneeded commas breaking IE and updated to vhochstein localization contributions
1 parent c9eb9ef commit 1dd304b

File tree

1 file changed

+69
-34
lines changed

1 file changed

+69
-34
lines changed

jquery-ui-timepicker-addon.js

Lines changed: 69 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/*
1+
/*
22
* jQuery timepicker addon
33
* By: Trent Richardson [http://trentrichardson.com]
44
* Version 0.6
5-
* Last Modified: 9/1/2010
5+
* Last Modified: 9/15/2010
66
*
77
* Copyright 2010 Trent Richardson
88
* Dual licensed under the MIT and GPL licenses.
@@ -16,7 +16,35 @@
1616
*/
1717

1818
(function($) {
19-
function Timepicker() { }
19+
function Timepicker(singleton) {
20+
if(typeof(singleton) === 'boolean' && singleton == true) {
21+
this.regional = []; // Available regional settings, indexed by language code
22+
this.regional[''] = { // Default regional settings
23+
ampm: false,
24+
timeFormat: 'hh:mm tt'
25+
};
26+
this.defaults = { // Global defaults for all the datetime picker instances
27+
holdDatepickerOpen: true,
28+
showButtonPanel: true,
29+
timeOnly: false,
30+
showHour: true,
31+
showMinute: true,
32+
showSecond: false,
33+
showTime: true,
34+
stepHour: 0.05,
35+
stepMinute: 0.05,
36+
stepSecond: 0.05,
37+
hour: 0,
38+
minute: 0,
39+
second: 0,
40+
alwaysSetTime: true
41+
};
42+
$.extend(this.defaults, this.regional['']);
43+
} else {
44+
this.defaults = $.extend({}, $.timepicker.defaults);
45+
}
46+
47+
}
2048

2149
Timepicker.prototype = {
2250
$input: null,
@@ -33,25 +61,6 @@
3361
formattedTime: '',
3462
formattedDateTime: '',
3563

36-
defaults: {
37-
holdDatepickerOpen: true,
38-
showButtonPanel: true,
39-
timeOnly: false,
40-
showHour: true,
41-
showMinute: true,
42-
showSecond: false,
43-
showTime: true,
44-
stepHour: 0.05,
45-
stepMinute: 0.05,
46-
stepSecond: 0.05,
47-
ampm: false,
48-
hour: 0,
49-
minute: 0,
50-
second: 0,
51-
timeFormat: 'hh:mm tt',
52-
alwaysSetTime: true
53-
},
54-
5564
//########################################################################
5665
// add our sliders to the calendar
5766
//########################################################################
@@ -101,10 +110,14 @@
101110

102111
tp_inst.timeDefined = (treg) ? true : false;
103112

113+
if (typeof(dp_inst.stay_open) !== 'boolean' || dp_inst.stay_open === false) {
104114
// wait for datepicker to create itself.. 60% of the time it works every time..
105-
setTimeout(function() {
106-
tp_inst.injectTimePicker(dp_inst, tp_inst);
107-
}, 10);
115+
setTimeout(function() {
116+
tp_inst.injectTimePicker(dp_inst, tp_inst);
117+
}, 10);
118+
} else {
119+
tp_inst.injectTimePicker(dp_inst, tp_inst);
120+
}
108121

109122
},
110123

@@ -174,7 +187,7 @@
174187
slide: function(event, ui) {
175188
tp_inst.hour_slider.slider( "option", "value", ui.value );
176189
tp_inst.onTimeChange(dp_inst, tp_inst);
177-
},
190+
}
178191
});
179192

180193
// Updated by Peter Medeiros:
@@ -189,7 +202,7 @@
189202
// update the global minute slider instance value with the current slider value
190203
tp_inst.minute_slider.slider( "option", "value", ui.value );
191204
tp_inst.onTimeChange(dp_inst, tp_inst);
192-
},
205+
}
193206
});
194207

195208
tp_inst.second_slider = $tp.find('#ui_tpicker_second').slider({
@@ -201,7 +214,7 @@
201214
slide: function(event, ui) {
202215
tp_inst.second_slider.slider( "option", "value", ui.value );
203216
tp_inst.onTimeChange(dp_inst, tp_inst);
204-
},
217+
}
205218
});
206219

207220
$dp.find('.ui-datepicker-calendar').after($tp);
@@ -299,7 +312,12 @@
299312

300313
this.formattedDateTime = formattedDateTime;
301314
this.$input.val(formattedDateTime);
302-
}
315+
},
316+
317+
setDefaults: function(settings) {
318+
extendRemove(this.defaults, settings || {});
319+
return this;
320+
}
303321
};
304322

305323
//########################################################################
@@ -340,7 +358,7 @@
340358
tp.defaults = $.extend({}, tp.defaults, opts, {
341359
beforeShow: beforeShowFunc,
342360
onChangeMonthYear: onChangeMonthYearFunc,
343-
onClose: onCloseFunc,
361+
onClose: onCloseFunc
344362
});
345363

346364
$(this).datepicker(tp.defaults);
@@ -363,7 +381,9 @@
363381
var target = $(id);
364382
var inst = this._getInst(target[0]);
365383
inst.inline = true;
384+
inst.stay_open = true;
366385
$.datepicker._selectDateOverload(id, dateStr);
386+
inst.stay_open = false;
367387
inst.inline = false;
368388
this._notifyChange(inst);
369389
this._updateDatepicker(inst);
@@ -372,18 +392,23 @@
372392
$.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker;
373393
//#############################################################################################
374394
// second bad hack :/ override datepicker so it triggers an event when changing the input field
395+
// and does not redraw the datepicker on every selectDate event
375396
//#############################################################################################
376397
// Generate the date picker content.
377398
$.datepicker._updateDatepicker = function(inst) {
378-
this._base_updateDatepicker(inst);
379-
// Reload the time control when changing something in the input text field.
380-
this._beforeShow(inst.input, inst);
399+
if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {
400+
this._base_updateDatepicker(inst);
401+
// Reload the time control when changing something in the input text field.
402+
this._beforeShow(inst.input, inst);
403+
}
381404
};
382405

383406
$.datepicker._beforeShow = function(input, inst) {
384407
var beforeShow = this._get(inst, 'beforeShow');
385408
if (beforeShow) {
409+
inst.stay_open = true;
386410
beforeShow.apply((inst.input ? inst.input[0] : null), [inst.input, inst]);
411+
inst.stay_open = false;
387412
}
388413
};
389414

@@ -400,5 +425,15 @@
400425
return event.ctrlKey || (chr < ' ' || !dateChars || dateChars.indexOf(chr) > -1 || event.keyCode == 58 || event.keyCode == 32);
401426
}
402427
};
403-
428+
429+
/* jQuery extend now ignores nulls! */
430+
function extendRemove(target, props) {
431+
$.extend(target, props);
432+
for (var name in props)
433+
if (props[name] == null || props[name] == undefined)
434+
target[name] = props[name];
435+
return target;
436+
};
437+
438+
$.timepicker = new Timepicker(true); // singleton instance
404439
})(jQuery);

0 commit comments

Comments
 (0)