Skip to content

Commit 4677cfc

Browse files
committed
Updating to newest bootstrap-datetimepicker.
1 parent 35e282a commit 4677cfc

File tree

3 files changed

+66
-38
lines changed

3 files changed

+66
-38
lines changed

bootstrap-datetimepicker

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Bootstrap3Datetimepicker
22
module Rails
3-
VERSION = '3.0.0.1'
3+
VERSION = '3.0.0.2'
44
end
55
end

vendor/assets/javascripts/bootstrap-datetimepicker.js

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ THE SOFTWARE.
4444

4545
(function ($, moment) {
4646
if (typeof moment === 'undefined') {
47-
alert("momentjs is requried");
47+
alert("momentjs is required");
4848
throw new Error('momentjs is required');
4949
};
5050

@@ -54,34 +54,14 @@ THE SOFTWARE.
5454

5555
// ReSharper disable once InconsistentNaming
5656
DateTimePicker = function (element, options) {
57-
var defaults = {
58-
pickDate: true,
59-
pickTime: true,
60-
useMinutes: true,
61-
useSeconds: false,
62-
useCurrent: true,
63-
minuteStepping: 1,
64-
minDate: new pMoment({ y: 1900 }),
65-
maxDate: new pMoment().add(100, "y"),
66-
showToday: true,
67-
collapse: true,
68-
language: "en",
69-
defaultDate: "",
70-
disabledDates: false,
71-
enabledDates: false,
72-
icons: {},
73-
useStrict: false,
74-
direction: "auto",
75-
sideBySide: false,
76-
daysOfWeekDisabled: false
77-
},
57+
var defaults = $.fn.datetimepicker.defaults,
7858

79-
icons = {
80-
time: 'glyphicon glyphicon-time',
81-
date: 'glyphicon glyphicon-calendar',
82-
up: 'glyphicon glyphicon-chevron-up',
83-
down: 'glyphicon glyphicon-chevron-down'
84-
},
59+
icons = {
60+
time: 'glyphicon glyphicon-time',
61+
date: 'glyphicon glyphicon-calendar',
62+
up: 'glyphicon glyphicon-chevron-up',
63+
down: 'glyphicon glyphicon-chevron-down'
64+
},
8565

8666
picker = this,
8767

@@ -201,10 +181,19 @@ THE SOFTWARE.
201181
},
202182

203183
getPickerInput = function () {
184+
var input;
185+
204186
if (picker.isInput) {
205187
return picker.element;
206188
} else {
207-
return dateStr = picker.element.find('input');
189+
input = picker.element.find('.datepickerinput');
190+
if (input.size() === 0) {
191+
input = picker.element.find('input');
192+
}
193+
else if (!input.is('input')) {
194+
throw new Error('CSS class "datepickerinput" cannot be applied to non input element');
195+
}
196+
return input;
208197
}
209198
},
210199

@@ -318,7 +307,7 @@ THE SOFTWARE.
318307
pMoment.lang(picker.options.language);
319308
var dateStr = newDate;
320309
if (!dateStr) {
321-
dateStr = getPickerInput().val()
310+
dateStr = getPickerInput().val();
322311
if (dateStr) picker.date = pMoment(dateStr, picker.format, picker.options.useStrict);
323312
if (!picker.date) picker.date = pMoment();
324313
}
@@ -356,6 +345,7 @@ THE SOFTWARE.
356345
},
357346

358347
fillDate = function () {
348+
if(!picker.options.pickDate) return;
359349
pMoment.lang(picker.options.language);
360350
var year = picker.viewDate.year(),
361351
month = picker.viewDate.month(),
@@ -398,7 +388,7 @@ THE SOFTWARE.
398388
if (prevMonth.isSame(pMoment({ y: picker.date.year(), M: picker.date.month(), d: picker.date.date() }))) {
399389
clsName += ' active';
400390
}
401-
if (isInDisableDates(prevMonth) || !isInEnableDates(prevMonth)) {
391+
if (isInDisableDates(prevMonth, 'day') || !isInEnableDates(prevMonth)) {
402392
clsName += ' disabled';
403393
}
404394
if (picker.options.showToday === true) {
@@ -712,6 +702,11 @@ THE SOFTWARE.
712702
e.preventDefault();
713703
},
714704

705+
keydown = function (e) {
706+
if (e.keyCode === 27) // allow escape to hide picker
707+
picker.hide();
708+
},
709+
715710
change = function (e) {
716711
pMoment.lang(picker.options.language);
717712
var input = $(e.target), oldDate = pMoment(picker.date), newDate = pMoment(input.val(), picker.format, picker.options.useStrict);
@@ -742,6 +737,7 @@ THE SOFTWARE.
742737
picker.widget.on('click', '.datepicker *', $.proxy(click, this)); // this handles date picker clicks
743738
picker.widget.on('click', '[data-action]', $.proxy(doAction, this)); // this handles time picker clicks
744739
picker.widget.on('mousedown', $.proxy(stopEvent, this));
740+
picker.element.on('keydown', $.proxy(keydown, this));
745741
if (picker.options.pickDate && picker.options.pickTime) {
746742
picker.widget.on('click.togglePicker', '.accordion-toggle', function (e) {
747743
e.stopPropagation();
@@ -752,7 +748,7 @@ THE SOFTWARE.
752748

753749
if (expanded && expanded.length) {
754750
collapseData = expanded.data('collapse');
755-
if (collapseData && collapseData.date - transitioning) return;
751+
if (collapseData && collapseData.transitioning) return;
756752
expanded.collapse('hide');
757753
closed.collapse('show');
758754
$this.find('span').toggleClass(picker.options.icons.time + ' ' + picker.options.icons.date);
@@ -868,9 +864,17 @@ THE SOFTWARE.
868864
picker.unset = false;
869865
},
870866

871-
isInDisableDates = function (date) {
867+
isInDisableDates = function (date, timeUnit) {
872868
pMoment.lang(picker.options.language);
873-
if (date.isAfter(picker.options.maxDate) || date.isBefore(picker.options.minDate)) return true;
869+
var maxDate = picker.options.maxDate;
870+
var minDate = picker.options.minDate;
871+
872+
if(timeUnit) {
873+
maxDate = pMoment(maxDate).endOf(timeUnit);
874+
minDate = pMoment(minDate).startOf(timeUnit);
875+
}
876+
877+
if (date.isAfter(maxDate) || date.isBefore(minDate)) return true;
874878
if (picker.options.disabledDates === false) {
875879
return false;
876880
}
@@ -1098,10 +1102,11 @@ THE SOFTWARE.
10981102
var collapse = picker.widget.find('.collapse'), i, collapseData;
10991103
for (i = 0; i < collapse.length; i++) {
11001104
collapseData = collapse.eq(i).data('collapse');
1101-
if (collapseData && collapseData.date - transitioning)
1105+
if (collapseData && collapseData.transitioning)
11021106
return;
11031107
}
11041108
picker.widget.hide();
1109+
picker.widget.removeClass("picker-open");
11051110
picker.viewMode = picker.startViewMode;
11061111
showMode();
11071112
picker.element.trigger({
@@ -1119,7 +1124,7 @@ THE SOFTWARE.
11191124
} else {
11201125
picker.unset = false;
11211126
}
1122-
if (!pMoment.isMoment(newDate)) newDate = pMoment(newDate, picker.format);
1127+
if (!pMoment.isMoment(newDate)) newDate = (newDate instanceof Date) ? pMoment(newDate) : pMoment(newDate, picker.format);
11231128
if (newDate.isValid()) {
11241129
picker.date = newDate;
11251130
set();
@@ -1177,4 +1182,27 @@ THE SOFTWARE.
11771182
if (!data) $this.data('DateTimePicker', new DateTimePicker(this, options));
11781183
});
11791184
};
1185+
1186+
$.fn.datetimepicker.defaults = {
1187+
pickDate: true,
1188+
pickTime: true,
1189+
useMinutes: true,
1190+
useSeconds: false,
1191+
useCurrent: true,
1192+
minuteStepping: 1,
1193+
minDate: new pMoment({ y: 1900 }),
1194+
maxDate: new pMoment().add(100, "y"),
1195+
showToday: true,
1196+
collapse: true,
1197+
language: "en",
1198+
defaultDate: "",
1199+
disabledDates: false,
1200+
enabledDates: false,
1201+
icons: {},
1202+
useStrict: false,
1203+
direction: "auto",
1204+
sideBySide: false,
1205+
daysOfWeekDisabled: false
1206+
};
1207+
11801208
}));

0 commit comments

Comments
 (0)