Refactor onSelect handler. Bind to grid onclick too.

This commit is contained in:
kumm 2011-02-06 18:53:31 +01:00
parent b2a1d9440a
commit 1f57183f82

View file

@ -401,6 +401,7 @@ $.extend(Timepicker.prototype, {
} }
tp_inst.hour_slider.slider("option", "value", h); tp_inst.hour_slider.slider("option", "value", h);
tp_inst._onTimeChange(); tp_inst._onTimeChange();
tp_inst._onSelectHandler();
}).css({ }).css({
cursor: 'pointer', cursor: 'pointer',
width: (100 / hourGridSize) + '%', width: (100 / hourGridSize) + '%',
@ -420,6 +421,7 @@ $.extend(Timepicker.prototype, {
$(this).click(function() { $(this).click(function() {
tp_inst.minute_slider.slider("option", "value", $(this).html()); tp_inst.minute_slider.slider("option", "value", $(this).html());
tp_inst._onTimeChange(); tp_inst._onTimeChange();
tp_inst._onSelectHandler();
}).css({ }).css({
cursor: 'pointer', cursor: 'pointer',
width: (100 / minuteGridSize) + '%', width: (100 / minuteGridSize) + '%',
@ -438,6 +440,7 @@ $.extend(Timepicker.prototype, {
$(this).click(function() { $(this).click(function() {
tp_inst.second_slider.slider("option", "value", $(this).html()); tp_inst.second_slider.slider("option", "value", $(this).html());
tp_inst._onTimeChange(); tp_inst._onTimeChange();
tp_inst._onSelectHandler();
}).css({ }).css({
cursor: 'pointer', cursor: 'pointer',
width: (100 / secondGridSize) + '%', width: (100 / secondGridSize) + '%',
@ -460,16 +463,12 @@ $.extend(Timepicker.prototype, {
} }
//Emulate datepicker onSelect behavior. Call on slidestop. //Emulate datepicker onSelect behavior. Call on slidestop.
var onSelect = tp_inst._defaults['onSelect']; var onSelectDelegate = function() {
if (onSelect) { tp_inst._onSelectHandler();
var inputEl = tp_inst.$input ? tp_inst.$input[0] : null;
var onSelectHandler = function() {
onSelect.apply(inputEl, [tp_inst.formattedDateTime, tp_inst]); // trigger custom callback*/
}
this.hour_slider.bind('slidestop',onSelectHandler);
this.minute_slider.bind('slidestop',onSelectHandler);
this.second_slider.bind('slidestop',onSelectHandler);
} }
this.hour_slider.bind('slidestop',onSelectDelegate);
this.minute_slider.bind('slidestop',onSelectDelegate);
this.second_slider.bind('slidestop',onSelectDelegate);
} }
}, },
@ -573,6 +572,18 @@ $.extend(Timepicker.prototype, {
if (hasChanged) this._updateDateTime(); if (hasChanged) this._updateDateTime();
}, },
//########################################################################
// call custom onSelect.
// bind to sliders slidestop, and grid click.
//########################################################################
_onSelectHandler: function() {
var onSelect = this._defaults['onSelect'];
var inputEl = this.$input ? this.$input[0] : null;
if (onSelect && inputEl) {
onSelect.apply(inputEl, [this.formattedDateTime, this]);
}
},
//######################################################################## //########################################################################
// format the time all pretty... // format the time all pretty...
//######################################################################## //########################################################################