Skip to content

Commit 4f98864

Browse files
committed
Extend beforeShowMonth event functionality
The event `beforeShowMonth` could only disable the cells. I extended it with the functionality of `beforeShowDay` so you can disable, add classes and set a tooltip. Backwards compatibility is given.
1 parent 9a07a33 commit 4f98864

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

js/bootstrap-datepicker.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,12 +1103,20 @@
11031103
if (this.o.beforeShowMonth !== $.noop){
11041104
var that = this;
11051105
$.each(months, function(i, month){
1106-
if (!$(month).hasClass('disabled')) {
1107-
var moDate = new Date(year, i, 1);
1108-
var before = that.o.beforeShowMonth(moDate);
1109-
if (before === false)
1110-
$(month).addClass('disabled');
1111-
}
1106+
var moDate = new Date(year, i, 1);
1107+
var before = that.o.beforeShowMonth(moDate);
1108+
if (before === undefined)
1109+
before = {};
1110+
else if (typeof(before) === 'boolean')
1111+
before = {enabled: before};
1112+
else if (typeof(before) === 'string')
1113+
before = {classes: before};
1114+
if (before.enabled === false && !$(month).hasClass('disabled'))
1115+
$(month).addClass('disabled');
1116+
if (before.classes)
1117+
$(month).addClass(before.classes);
1118+
if (before.tooltip)
1119+
$(month).prop('title', before.tooltip);
11121120
});
11131121
}
11141122

0 commit comments

Comments
 (0)