|
1920 | 1920 | * @param string method Can be used to specify the type of picker to be added |
1921 | 1921 | * @return jQuery |
1922 | 1922 | */ |
1923 | | - $.timepicker.dateTimeRange = function(startTime, endTime, options) { |
1924 | | - $.timepicker.dateRange(startTime, endTime, options, 'datetimepicker'); |
| 1923 | + $.timepicker.datetimeRange = function(startTime, endTime, options) { |
| 1924 | + $.timepicker.handleRange('datetimepicker', startTime, endTime, options); |
1925 | 1925 | }; |
1926 | 1926 |
|
1927 | 1927 | /** |
|
1931 | 1931 | * @param Element endTime |
1932 | 1932 | * @param obj options Options for the `timepicker()` call. Also supports `reformat`, |
1933 | 1933 | * a boolean value that can be used to reformat the input values to the `dateFormat`. |
1934 | | - * @param string method Can be used to specify the type of picker to be added |
1935 | 1934 | * @return jQuery |
1936 | 1935 | */ |
1937 | | - $.timepicker.dateRange = function(startTime, endTime, options, method) { |
1938 | | - method = method || 'datepicker'; |
1939 | | - $.timepicker.handleRange(method, startTime, endTime, options); |
| 1936 | + $.timepicker.dateRange = function(startTime, endTime, options) { |
| 1937 | + $.timepicker.handleRange('datepicker', startTime, endTime, options); |
1940 | 1938 | }; |
1941 | 1939 |
|
1942 | 1940 | /** |
|
1952 | 1950 | $.timepicker.handleRange = function(method, startTime, endTime, options) { |
1953 | 1951 | $.fn[method].call(startTime, $.extend({ |
1954 | 1952 | onClose: function(dateText, inst) { |
1955 | | - checkDates(this, endTime, dateText); |
| 1953 | + checkDates($(this), endTime, dateText); |
1956 | 1954 | }, |
1957 | 1955 | onSelect: function(selectedDateTime) { |
1958 | | - selected(this, endTime, 'minDate'); |
| 1956 | + selected($(this), endTime, 'minDate'); |
1959 | 1957 | } |
1960 | 1958 | }, options, options.start)); |
1961 | 1959 | $.fn[method].call(endTime, $.extend({ |
1962 | 1960 | onClose: function(dateText, inst) { |
1963 | | - checkDates(this, startTime, dateText); |
| 1961 | + checkDates($(this), startTime, dateText); |
1964 | 1962 | }, |
1965 | 1963 | onSelect: function(selectedDateTime) { |
1966 | | - selected(this, startTime, 'maxDate'); |
| 1964 | + selected($(this), startTime, 'maxDate'); |
1967 | 1965 | } |
1968 | 1966 | }, options, options.end)); |
1969 | 1967 | // timepicker doesn't provide access to its 'timeFormat' option, |
1970 | 1968 | // nor could I get datepicker.formatTime() to behave with times, so I |
1971 | 1969 | // have disabled reformatting for timepicker |
1972 | 1970 | if (method != 'timepicker' && options.reformat) { |
1973 | 1971 | $([startTime, endTime]).each(function() { |
1974 | | - var format = $(this)[method].call($(this), 'option', 'dateFormat'), |
1975 | | - date = new Date($(this).val()); |
1976 | | - if ($(this).val() && date) { |
1977 | | - $(this).val($.datepicker.formatDate(format, date)); |
| 1972 | + var $t = $(this), |
| 1973 | + format = $t[method].call($t, 'option', 'dateFormat'), |
| 1974 | + date = new Date($t.val()); |
| 1975 | + if ($t.val() && date) { |
| 1976 | + $t.val($.datepicker.formatDate(format, date)); |
1978 | 1977 | } |
1979 | 1978 | }); |
1980 | 1979 | } |
| 1980 | + |
1981 | 1981 | checkDates(startTime, endTime, startTime.val()); |
| 1982 | + selected(startTime, endTime, 'minDate'); |
| 1983 | + selected(endTime, startTime, 'maxDate'); |
1982 | 1984 |
|
1983 | 1985 | function checkDates(changed, other, dateText) { |
1984 | | - if (other.val() && (new Date(startTime.val()) > new Date(endTime.val()))) { |
| 1986 | + var startdt = startTime[method]('getDate'), |
| 1987 | + enddt = endTime[method]('getDate'); |
| 1988 | + |
| 1989 | + if (other.val() && startdt > enddt) { |
1985 | 1990 | other.val(dateText); |
1986 | 1991 | } |
1987 | 1992 | } |
1988 | | - selected(startTime, endTime, 'minDate'); |
1989 | | - selected(endTime, startTime, 'maxDate'); |
1990 | 1993 |
|
1991 | 1994 | function selected(changed, other, option) { |
1992 | | - if (!$(changed).val()) { |
| 1995 | + if (!changed.val()) { |
1993 | 1996 | return; |
1994 | 1997 | } |
1995 | | - var date = $(changed)[method].call($(changed), 'getDate'); |
1996 | | - // timepicker doesn't implement 'getDate' and returns a jQuery |
| 1998 | + var date = changed[method].call(changed, 'getDate'); |
1997 | 1999 | if (date.getTime) { |
1998 | | - $(other)[method].call($(other), 'option', option, date); |
| 2000 | + other[method].call(other, 'option', option, date); |
1999 | 2001 | } |
2000 | 2002 | } |
2001 | 2003 | return $([startTime.get(0), endTime.get(0)]); |
|
0 commit comments