Skip to content

Commit 1f57183

Browse files
committed
Refactor onSelect handler. Bind to grid onclick too.
1 parent b2a1d94 commit 1f57183

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

jquery-ui-timepicker-addon.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ $.extend(Timepicker.prototype, {
401401
}
402402
tp_inst.hour_slider.slider("option", "value", h);
403403
tp_inst._onTimeChange();
404+
tp_inst._onSelectHandler();
404405
}).css({
405406
cursor: 'pointer',
406407
width: (100 / hourGridSize) + '%',
@@ -420,6 +421,7 @@ $.extend(Timepicker.prototype, {
420421
$(this).click(function() {
421422
tp_inst.minute_slider.slider("option", "value", $(this).html());
422423
tp_inst._onTimeChange();
424+
tp_inst._onSelectHandler();
423425
}).css({
424426
cursor: 'pointer',
425427
width: (100 / minuteGridSize) + '%',
@@ -438,6 +440,7 @@ $.extend(Timepicker.prototype, {
438440
$(this).click(function() {
439441
tp_inst.second_slider.slider("option", "value", $(this).html());
440442
tp_inst._onTimeChange();
443+
tp_inst._onSelectHandler();
441444
}).css({
442445
cursor: 'pointer',
443446
width: (100 / secondGridSize) + '%',
@@ -460,16 +463,12 @@ $.extend(Timepicker.prototype, {
460463
}
461464

462465
//Emulate datepicker onSelect behavior. Call on slidestop.
463-
var onSelect = tp_inst._defaults['onSelect'];
464-
if (onSelect) {
465-
var inputEl = tp_inst.$input ? tp_inst.$input[0] : null;
466-
var onSelectHandler = function() {
467-
onSelect.apply(inputEl, [tp_inst.formattedDateTime, tp_inst]); // trigger custom callback*/
468-
}
469-
this.hour_slider.bind('slidestop',onSelectHandler);
470-
this.minute_slider.bind('slidestop',onSelectHandler);
471-
this.second_slider.bind('slidestop',onSelectHandler);
466+
var onSelectDelegate = function() {
467+
tp_inst._onSelectHandler();
472468
}
469+
this.hour_slider.bind('slidestop',onSelectDelegate);
470+
this.minute_slider.bind('slidestop',onSelectDelegate);
471+
this.second_slider.bind('slidestop',onSelectDelegate);
473472
}
474473
},
475474

@@ -572,6 +571,18 @@ $.extend(Timepicker.prototype, {
572571
this.timeDefined = true;
573572
if (hasChanged) this._updateDateTime();
574573
},
574+
575+
//########################################################################
576+
// call custom onSelect.
577+
// bind to sliders slidestop, and grid click.
578+
//########################################################################
579+
_onSelectHandler: function() {
580+
var onSelect = this._defaults['onSelect'];
581+
var inputEl = this.$input ? this.$input[0] : null;
582+
if (onSelect && inputEl) {
583+
onSelect.apply(inputEl, [this.formattedDateTime, this]);
584+
}
585+
},
575586

576587
//########################################################################
577588
// format the time all pretty...

0 commit comments

Comments
 (0)