From 1f57183f820cc3c36595afa91af747e87f9fd378 Mon Sep 17 00:00:00 2001 From: kumm Date: Sun, 6 Feb 2011 18:53:31 +0100 Subject: [PATCH] Refactor onSelect handler. Bind to grid onclick too. --- jquery-ui-timepicker-addon.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/jquery-ui-timepicker-addon.js b/jquery-ui-timepicker-addon.js index 6ebb5ae..5c3e9e7 100644 --- a/jquery-ui-timepicker-addon.js +++ b/jquery-ui-timepicker-addon.js @@ -401,6 +401,7 @@ $.extend(Timepicker.prototype, { } tp_inst.hour_slider.slider("option", "value", h); tp_inst._onTimeChange(); + tp_inst._onSelectHandler(); }).css({ cursor: 'pointer', width: (100 / hourGridSize) + '%', @@ -420,6 +421,7 @@ $.extend(Timepicker.prototype, { $(this).click(function() { tp_inst.minute_slider.slider("option", "value", $(this).html()); tp_inst._onTimeChange(); + tp_inst._onSelectHandler(); }).css({ cursor: 'pointer', width: (100 / minuteGridSize) + '%', @@ -438,6 +440,7 @@ $.extend(Timepicker.prototype, { $(this).click(function() { tp_inst.second_slider.slider("option", "value", $(this).html()); tp_inst._onTimeChange(); + tp_inst._onSelectHandler(); }).css({ cursor: 'pointer', width: (100 / secondGridSize) + '%', @@ -460,16 +463,12 @@ $.extend(Timepicker.prototype, { } //Emulate datepicker onSelect behavior. Call on slidestop. - var onSelect = tp_inst._defaults['onSelect']; - if (onSelect) { - 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); + var onSelectDelegate = function() { + tp_inst._onSelectHandler(); } + this.hour_slider.bind('slidestop',onSelectDelegate); + this.minute_slider.bind('slidestop',onSelectDelegate); + this.second_slider.bind('slidestop',onSelectDelegate); } }, @@ -572,6 +571,18 @@ $.extend(Timepicker.prototype, { this.timeDefined = true; 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...