summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordoublerebel <charles@doublerebel.com>2010-12-05 16:51:48 -0800
committerdoublerebel <charles@doublerebel.com>2010-12-05 16:51:48 -0800
commitf31d5ecbeb0801bb65003a34a74fb2cac74ab83f (patch)
tree0dd3ae167d8be8b8a1b9bf3c9866dbfdfba46c2e
parentaef1408c876440dbc00fe1abd18535bbc51e4493 (diff)
downloadjQuery-Timepicker-Addon-f31d5ecbeb0801bb65003a34a74fb2cac74ab83f.zip
jQuery-Timepicker-Addon-f31d5ecbeb0801bb65003a34a74fb2cac74ab83f.tar.gz
jQuery-Timepicker-Addon-f31d5ecbeb0801bb65003a34a74fb2cac74ab83f.tar.bz2
Change timepicker initialization to support setting/getting time/date before date/timepicker has been opened
-rw-r--r--jquery-ui-timepicker-addon.js26
1 files changed, 13 insertions, 13 deletions
diff --git a/jquery-ui-timepicker-addon.js b/jquery-ui-timepicker-addon.js
index dad0b08..62e1894 100644
--- a/jquery-ui-timepicker-addon.js
+++ b/jquery-ui-timepicker-addon.js
@@ -97,6 +97,13 @@ $.extend(Timepicker.prototype, {
var tp_inst = new Timepicker(),
inlineSettings = {};
+ tp_inst.hour = tp_inst._defaults.hour;
+ tp_inst.minute = tp_inst._defaults.minute;
+ tp_inst.second = tp_inst._defaults.second;
+ tp_inst.ampm = '';
+ tp_inst.$input = $input;
+
+
for (var attrName in this._defaults) {
var attrValue = $input.attr('time:' + attrName);
if (attrValue) {
@@ -109,18 +116,12 @@ $.extend(Timepicker.prototype, {
}
tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, {
beforeShow: function(input, dp_inst) {
- tp_inst.hour = tp_inst._defaults.hour;
- tp_inst.minute = tp_inst._defaults.minute;
- tp_inst.second = tp_inst._defaults.second;
- tp_inst.ampm = '';
- tp_inst.$input = $(input);
if (o.altField)
tp_inst.$altInput = $($.datepicker._get(dp_inst, 'altField'))
.css({ cursor: 'pointer' })
.focus(function(){
$input.trigger("focus");
});
- tp_inst.inst = dp_inst;
if ($.isFunction(o.beforeShow))
o.beforeShow(input, dp_inst);
},
@@ -166,6 +167,8 @@ $.extend(Timepicker.prototype, {
order = this._getFormatPositions(),
treg;
+ if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]);
+
if (withDate || !this._defaults.timeOnly) {
// the time should come after x number of characters and a space.
// x = at least the length of text specified by the date format
@@ -462,7 +465,6 @@ $.extend(Timepicker.prototype, {
this._formatTime();
if (this.$timeObj) this.$timeObj.text(this.formattedTime);
this.timeDefined = true;
-
if (hasChanged) this._updateDateTime();
},
@@ -506,8 +508,8 @@ $.extend(Timepicker.prototype, {
//########################################################################
// update our input with the new date time..
//########################################################################
- _updateDateTime: function() {
- var dp_inst = this.inst,
+ _updateDateTime: function(dp_inst) {
+ dp_inst = this.inst || dp_inst,
dt = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay),
dateFmt = $.datepicker._get(dp_inst, 'dateFormat'),
formatCfg = $.datepicker._getFormatConfig(dp_inst),
@@ -732,10 +734,8 @@ $.datepicker._getDateDatepicker = function(target, noDefault) {
if (tp_inst) {
this._setDateFromField(inst, noDefault);
var date = this._getDate(inst);
- date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second);
- return (!inst.currentYear || (inst.input && inst.input.val() == '')) ?
- null :
- date;
+ if (date && tp_inst._parseTime($(target).val(), true)) date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second);
+ return date;
}
else return this._base_getDateDatepicker(inst);
};