app/assets/javascripts/jquery.xdan.datetimepicker.full.js in xdan-datetimepicker-rails-2.5.3 vs app/assets/javascripts/jquery.xdan.datetimepicker.full.js in xdan-datetimepicker-rails-2.5.4
- old
+ new
@@ -573,11 +573,11 @@
}
return '';
}
};
})();/**
- * @preserve jQuery DateTimePicker plugin v2.5.1
+ * @preserve jQuery DateTimePicker plugin v2.5.4
* @homepage http://xdsoft.net/jqplugins/datetimepicker/
* @author Chupurnov Valeriy (<chupurnov@gmail.com>)
*/
/*global DateFormatter, document,window,jQuery,setTimeout,clearTimeout,HighlightedDate,getCurrentValue*/
;(function (factory) {
@@ -1499,11 +1499,12 @@
timerclick,
current_time_index,
setPos,
timer = 0,
_xdsoft_datetime,
- forEachAncestorOf;
+ forEachAncestorOf,
+ throttle;
if (options.id) {
datetimepicker.attr('id', options.id);
}
if (options.style) {
@@ -1753,26 +1754,28 @@
.off('blur.xdsoft')
.on('blur.xdsoft', function () {
if (options.allowBlank && (!$.trim($(this).val()).length || (typeof options.mask == "string" && $.trim($(this).val()) === options.mask.replace(/[0-9]/g, '_')))) {
$(this).val(null);
datetimepicker.data('xdsoft_datetime').empty();
- } else if (!dateHelper.parseDate($(this).val(), options.format)) {
- var splittedHours = +([$(this).val()[0], $(this).val()[1]].join('')),
- splittedMinutes = +([$(this).val()[2], $(this).val()[3]].join(''));
-
- // parse the numbers as 0312 => 03:12
- if (!options.datepicker && options.timepicker && splittedHours >= 0 && splittedHours < 24 && splittedMinutes >= 0 && splittedMinutes < 60) {
- $(this).val([splittedHours, splittedMinutes].map(function (item) {
- return item > 9 ? item : '0' + item;
- }).join(':'));
+ } else {
+ var d = dateHelper.parseDate($(this).val(), options.format);
+ if (d) { // parseDate() may skip some invalid parts like date or time, so make it clear for user: show parsed date/time
+ $(this).val(dateHelper.formatDate(d, options.format));
} else {
- $(this).val(dateHelper.formatDate(_xdsoft_datetime.now(), options.format));
+ var splittedHours = +([$(this).val()[0], $(this).val()[1]].join('')),
+ splittedMinutes = +([$(this).val()[2], $(this).val()[3]].join(''));
+
+ // parse the numbers as 0312 => 03:12
+ if (!options.datepicker && options.timepicker && splittedHours >= 0 && splittedHours < 24 && splittedMinutes >= 0 && splittedMinutes < 60) {
+ $(this).val([splittedHours, splittedMinutes].map(function (item) {
+ return item > 9 ? item : '0' + item;
+ }).join(':'));
+ } else {
+ $(this).val(dateHelper.formatDate(_xdsoft_datetime.now(), options.format));
+ }
}
-
datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
- } else {
- datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
}
datetimepicker.trigger('changedatetime.xdsoft');
datetimepicker.trigger('close.xdsoft');
});
@@ -1850,12 +1853,24 @@
return false;
}
return !isNaN(d.getTime());
};
- _this.setCurrentTime = function (dTime) {
- _this.currentTime = (typeof dTime === 'string') ? _this.strToDateTime(dTime) : _this.isValidDate(dTime) ? dTime : _this.now();
+ _this.setCurrentTime = function (dTime, requireValidDate) {
+ if (typeof dTime === 'string') {
+ _this.currentTime = _this.strToDateTime(dTime);
+ }
+ else if (_this.isValidDate(dTime)) {
+ _this.currentTime = dTime;
+ }
+ else if (!dTime && !requireValidDate && options.allowBlank) {
+ _this.currentTime = null;
+ }
+ else {
+ _this.currentTime = _this.now();
+ }
+
datetimepicker.trigger('xchange.xdsoft');
};
_this.empty = function () {
_this.currentTime = null;
@@ -2004,11 +2019,11 @@
});
mounth_picker
.find('.xdsoft_today_button')
.on('touchend mousedown.xdsoft', function () {
datetimepicker.data('changed', true);
- _xdsoft_datetime.setCurrentTime(0);
+ _xdsoft_datetime.setCurrentTime(0, true);
datetimepicker.trigger('afterOpen.xdsoft');
}).on('dblclick.xdsoft', function () {
var currentDate = _xdsoft_datetime.getCurrentTime(), minDate, maxDate;
currentDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate());
minDate = _xdsoft_datetime.strToDate(options.minDate);
@@ -2101,10 +2116,14 @@
.on('xchange.xdsoft', function (event) {
clearTimeout(xchangeTimer);
xchangeTimer = setTimeout(function () {
if (_xdsoft_datetime.currentTime === undefined || _xdsoft_datetime.currentTime === null) {
+ //In case blanks are allowed, delay construction until we have a valid date
+ if (options.allowBlank)
+ return;
+
_xdsoft_datetime.currentTime = _xdsoft_datetime.now();
}
var table = '',
start = new Date(_xdsoft_datetime.currentTime.getFullYear(), _xdsoft_datetime.currentTime.getMonth(), 1, 12, 0, 0),
@@ -2826,10 +2845,10 @@
if (input.is(':disabled')) {
return;
}
triggerAfterOpen = true;
- _xdsoft_datetime.setCurrentTime(getCurrentValue());
+ _xdsoft_datetime.setCurrentTime(getCurrentValue(), true);
if(options.mask) {
setMask(options);
}
datetimepicker.trigger('open.xdsoft');
}, 100);