vendor/assets/javascripts/bootstrap-datetimepicker.js in bootstrap3-datetimepicker-rails-2.1.20.1 vs vendor/assets/javascripts/bootstrap-datetimepicker.js in bootstrap3-datetimepicker-rails-2.1.30
- old
+ new
@@ -1,7 +1,7 @@
/**
- * version 2.1.20
+ * version 2.1.30
* @license
* =========================================================
* bootstrap-datetimepicker.js
* http://www.eyecon.ro/bootstrap-datepicker
* =========================================================
@@ -40,17 +40,17 @@
}
}
}
(function ($, moment) {
- if (typeof moment === 'undefined') {
+ if (typeof moment === 'undefined') {
alert("momentjs is requried");
- throw new Error('momentjs is requried');
+ throw new Error('momentjs is required');
};
-
+
var dpgId = 0,
-
+
pMoment = moment,
// ReSharper disable once InconsistentNaming
DateTimePicker = function (element, options) {
var defaults = {
@@ -60,16 +60,17 @@
useSeconds: false,
minuteStepping: 1,
startDate: new pMoment({ y: 1970 }),
endDate: new pMoment().add(50, "y"),
collapse: true,
- language: "en",
+ language: pMoment.lang(),
defaultDate: "",
disabledDates: [],
enabledDates: false,
icons: {},
- useStrict: false
+ useStrict: false,
+ direction: "auto"
},
icons = {
time: 'glyphicon glyphicon-time',
date: 'glyphicon glyphicon-calendar',
@@ -82,15 +83,15 @@
init = function () {
var icon = false, i, dDate, longDateFormat;
picker.options = $.extend({}, defaults, options);
picker.options.icons = $.extend({}, icons, picker.options.icons);
-
+
picker.element = $(element);
-
+
dataToOptions();
-
+
if (!(picker.options.pickTime || picker.options.pickDate))
throw new Error('Must choose at least one picker');
picker.id = dpgId++;
pMoment.lang(picker.options.language);
@@ -199,11 +200,11 @@
update();
showMode();
attachDatePickerEvents();
if (picker.options.defaultDate !== "") picker.setValue(picker.options.defaultDate);
},
-
+
dataToOptions = function () {
var eData = picker.element.data();
if (eData.pickdate !== undefined) picker.options.pickDate = eData.pickdate;
if (eData.picktime !== undefined) picker.options.pickTime = eData.picktime;
if (eData.useminutes !== undefined) picker.options.useMinutes = eData.useminutes;
@@ -223,13 +224,19 @@
place = function () {
var position = 'absolute',
offset = picker.component ? picker.component.offset() : picker.element.offset(), $window = $(window);
picker.width = picker.component ? picker.component.outerWidth() : picker.element.outerWidth();
offset.top = offset.top + picker.element.outerHeight();
+
+ // if (picker.options.direction === 'up' || picker.options.direction === 'auto' && offset.top + picker.widget.height() > $window.height()) {
+ // offset.top -= picker.widget.height() + picker.element.outerHeight();
+ // picker.widget.addClass('up');
+ // } else if (picker.options.direction === 'down' || picker.options.direction === 'auto' && offset.top + picker.widget.height() <= $window.height()) {
+ // offset.top += picker.element.outerHeight();
+ // picker.widget.addClass('down');
+ // }
- //if (offset.top + picker.widget.height() > $window.height()) offset.top = offset.top - (picker.widget.height() + picker.height + 10);
-
if (picker.options.width !== undefined) {
picker.widget.width(picker.options.width);
}
if (picker.options.orientation === 'left') {
@@ -264,11 +271,11 @@
picker.element.trigger({
type: 'change.dp',
date: pMoment(picker.date),
oldDate: pMoment(oldDate)
});
-
+
if (eventType !== 'change')
picker.element.change();
},
notifyError = function (date) {
@@ -363,11 +370,11 @@
clsName += ' new';
}
if (prevMonth.isSame(pMoment({ y: picker.date.year(), M: picker.date.month(), d: picker.date.date() }))) {
clsName += ' active';
}
- if ((pMoment(prevMonth).add(1, "d") <= picker.options.startDate) || (prevMonth > picker.options.endDate) || isInDisableDates(prevMonth) || !isInEnableDates(prevMonth)) {
+ if (isInDisableDates(prevMonth) || !isInEnableDates(prevMonth)) {
clsName += ' disabled';
}
row.append('<td class="day' + clsName + '">' + prevMonth.date() + '</td>');
prevMonth.add(1, "d");
}
@@ -450,11 +457,11 @@
}
html += '</tr>';
}
table.html(html);
},
-
+
fillSeconds = function () {
var table = picker.widget.find('.timepicker .timepicker-seconds table'), html = '', current = 0, i, j;
table.parent().hide();
for (i = 0; i < 5; i++) {
html += '<tr>';
@@ -639,35 +646,35 @@
var oldDate = pMoment(picker.date), action = $(e.currentTarget).data('action'), rv = actions[action].apply(picker, arguments);
stopEvent(e);
if (!picker.date) picker.date = pMoment({ y: 1970 });
set();
fillTime();
- notifyChange(oldDate);
+ notifyChange(oldDate, e.type);
return rv;
},
stopEvent = function (e) {
e.stopPropagation();
e.preventDefault();
},
change = function (e) {
pMoment.lang(picker.options.language);
- var input = $(e.target), oldDate = pMoment(picker.date), d = pMoment(input.val(), picker.format, picker.options.useStrict);
- if (d.isValid()) {
+ var input = $(e.target), oldDate = pMoment(picker.date), newDate = pMoment(input.val(), picker.format, picker.options.useStrict);
+ if (newDate.isValid() && !isInDisableDates(newDate) && isInEnableDates(newDate)) {
update();
- picker.setValue(d);
- notifyChange(oldDate);
+ picker.setValue(newDate);
+ notifyChange(oldDate, e.type);
set();
}
else {
picker.viewDate = oldDate;
+ input.val(pMoment(oldDate).format(picker.format));
//picker.setValue(""); // unset the date when the input is erased
- notifyChange(oldDate);
- notifyError(d);
+ notifyChange(oldDate, e.type);
+ notifyError(newDate);
picker.unset = true;
- input.val('');
}
},
showMode = function (dir) {
if (dir) {
@@ -799,25 +806,27 @@
newDate.add(amount, unit);
}
else {
newDate = pMoment(picker.date).subtract(amount, unit);
}
- if (newDate.isAfter(picker.options.endDate) || pMoment(newDate.subtract(amount, unit)).isBefore(picker.options.startDate) || isInDisableDates(newDate)) {
+ if (isInDisableDates(pMoment(newDate.subtract(amount, unit))) || isInDisableDates(newDate)) {
notifyError(newDate.format(picker.format));
return;
}
if (direction == "add") {
picker.date.add(amount, unit);
}
else {
picker.date.subtract(amount, unit);
}
+ picker.unset = false;
},
isInDisableDates = function (date) {
pMoment.lang(picker.options.language);
+ if (date.isAfter(picker.options.endDate) || date.isBefore(picker.options.startDate)) return true;
var disabled = picker.options.disabledDates, i;
for (i in disabled) {
if (disabled[i] == pMoment(date).format("L")) {
return true;
}
@@ -983,21 +992,21 @@
}
},
picker.disable = function () {
var input = picker.element.find('input');
- if(!input.prop('disabled')) return;
+ if(input.prop('disabled')) return;
input.prop('disabled', true);
detachDatePickerEvents();
},
picker.enable = function () {
var input = picker.element.find('input');
if(!input.prop('disabled')) return;
- input.prop('disabled', true);
+ input.prop('disabled', false);
attachDatePickerEvents();
},
picker.hide = function (event) {
if (event && $(event.target).is(picker.element.attr("id")))
@@ -1053,23 +1062,19 @@
picker.setEnabledDates = function (dates) {
if (!dates) picker.options.enabledDates = false;
else picker.options.enabledDates = dates;
if (picker.viewDate) update();
},
-
+
picker.setEndDate = function (date) {
+ if (date == undefined) return;
picker.options.endDate = pMoment(date);
- if (!picker.options.endDate.isValid()) {
- picker.options.endDate = pMoment().add(50, "y");
- }
if (picker.viewDate) update();
},
picker.setStartDate = function (date) {
+ if (date == undefined) return;
picker.options.startDate = pMoment(date);
- if (!picker.options.startDate.isValid()) {
- picker.options.startDate = pMoment({ y: 1970 });
- }
if (picker.viewDate) update();
};
init();
};
\ No newline at end of file