summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrent Richardson <trentdrichardson@gmail.com>2013-04-30 16:57:59 -0400
committerTrent Richardson <trentdrichardson@gmail.com>2013-04-30 16:57:59 -0400
commit3cdc47890a91ffcdecdc01fc2cabebf34870e038 (patch)
treebbe4f20b889d717f0ff0d4dbd823c513b42f2a96
parentd424bb8ec8b505c24dae800524fe310b7789c9bc (diff)
downloadjQuery-Timepicker-Addon-3cdc47890a91ffcdecdc01fc2cabebf34870e038.zip
jQuery-Timepicker-Addon-3cdc47890a91ffcdecdc01fc2cabebf34870e038.tar.gz
jQuery-Timepicker-Addon-3cdc47890a91ffcdecdc01fc2cabebf34870e038.tar.bz2
min/maxInterval options for handleRange
-rw-r--r--index.html2
-rw-r--r--jquery-ui-timepicker-addon.js59
2 files changed, 39 insertions, 22 deletions
diff --git a/index.html b/index.html
index 0569468..243f776 100644
--- a/index.html
+++ b/index.html
@@ -830,7 +830,7 @@ var startDateTextBox = $('#rest_example_4_start');
var endDateTextBox = $('#rest_example_4_end');
$.timepicker.datetimeRange(startDateTextBox, endDateTextBox, {
- reformat: true,
+ minInterval: (1000*60*60),
start: { }, // start datetime options
end: { } // end datetime options
});
diff --git a/jquery-ui-timepicker-addon.js b/jquery-ui-timepicker-addon.js
index 17b64c5..5bbb0fd 100644
--- a/jquery-ui-timepicker-addon.js
+++ b/jquery-ui-timepicker-addon.js
@@ -2001,9 +2001,16 @@
* @return jQuery
*/
$.timepicker.handleRange = function(method, startTime, endTime, options) {
+ options = $.extend({}, {
+ minInterval: 0, // min allowed interval in milliseconds
+ maxInterval: 0, // max allowed interval in milliseconds
+ start: {}, // options for start picker
+ end: {} // options for end picker
+ }, options);
+
$.fn[method].call(startTime, $.extend({
onClose: function(dateText, inst) {
- checkDates($(this), endTime, dateText);
+ checkDates($(this), endTime);
},
onSelect: function(selectedDateTime) {
selected($(this), endTime, 'minDate');
@@ -2011,36 +2018,38 @@
}, options, options.start));
$.fn[method].call(endTime, $.extend({
onClose: function(dateText, inst) {
- checkDates($(this), startTime, dateText);
+ checkDates($(this), startTime);
},
onSelect: function(selectedDateTime) {
selected($(this), startTime, 'maxDate');
}
}, options, options.end));
- // timepicker doesn't provide access to its 'timeFormat' option,
- // nor could I get datepicker.formatTime() to behave with times, so I
- // have disabled reformatting for timepicker
- if (method != 'timepicker' && options.reformat) {
- $([startTime, endTime]).each(function() {
- var $t = $(this),
- format = $t[method].call($t, 'option', 'dateFormat'),
- date = new Date($t.val());
- if ($t.val() && date) {
- $t.val($.datepicker.formatDate(format, date));
- }
- });
- }
- checkDates(startTime, endTime, startTime.val());
+ checkDates(startTime, endTime);
selected(startTime, endTime, 'minDate');
selected(endTime, startTime, 'maxDate');
- function checkDates(changed, other, dateText) {
+ function checkDates(changed, other) {
var startdt = startTime[method]('getDate'),
- enddt = endTime[method]('getDate');
-
- if (other.val() && startdt > enddt) {
- other.val(dateText);
+ enddt = endTime[method]('getDate'),
+ changeddt = changed[method]('getDate');
+
+ if(startdt !== null){
+ var minDate = new Date(startdt.getTime()),
+ maxDate = new Date(startdt.getTime());
+
+ minDate.setMilliseconds(minDate.getMilliseconds() + options.minInterval);
+ maxDate.setMilliseconds(maxDate.getMilliseconds() + options.maxInterval);
+
+ if(options.minInterval > 0 && minDate > enddt){ // minInterval check
+ endTime[method]('setDate',minDate);
+ }
+ else if(options.maxInterval > 0 && maxDate < enddt){ // max interval check
+ endTime[method]('setDate',maxDate);
+ }
+ else if (startdt > enddt) {
+ other[method]('setDate',changeddt);
+ }
}
}
@@ -2049,6 +2058,14 @@
return;
}
var date = changed[method].call(changed, 'getDate');
+ if(date !== null && options.minInterval > 0){
+ if(option == 'minDate'){
+ date.setMilliseconds(date.getMilliseconds() + options.minInterval);
+ }
+ if(option == 'maxDate'){
+ date.setMilliseconds(date.getMilliseconds() - options.minInterval);
+ }
+ }
if (date.getTime) {
other[method].call(other, 'option', option, date);
}