Skip to content

Commit 529782a

Browse files
committed
Merge latest master in
2 parents b8f284c + a083fe8 commit 529782a

8 files changed

+127
-16
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ Date. Default: End of time
128128

129129
The latest date that may be selected; all later dates will be disabled.
130130

131+
### daysOfWeekDisabled
132+
133+
String, Array. Default: '', []
134+
135+
Days of the week that should be disabled. Values are 0 (Sunday) to 6 (Saturday). Multiple values should be comma-separated. Example: disable weekends: `'0,6'` or `[0,6]`.
136+
131137
### autoclose
132138

133139
Boolean. Default: false
@@ -248,6 +254,21 @@ Omit endDate (or provide an otherwise falsey value) to unset the limit.
248254
$('#datepicker').datepicker('setEndDate');
249255
$('#datepicker').datepicker('setEndDate', null);
250256

257+
### setDaysOfWeekDisabled
258+
259+
Arguments:
260+
261+
* daysOfWeekDisabled (String|Array)
262+
263+
Sets the days of week that should be disabled.
264+
265+
$('#datepicker').datepicker('setDaysOfWeekDisabled', [0,6]);
266+
267+
Omit daysOfWeekDisabled (or provide an otherwise falsey value) to unset the disabled days.
268+
269+
$('#datepicker').datepicker('setDaysOfWeekDisabled');
270+
$('#datepicker').datepicker('setDaysOfWeekDisabled', null);
271+
251272
## Events
252273

253274
Datepicker class exposes a few events for manipulating the dates.

js/bootstrap-datepicker.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
}
6969
$(document).on('mousedown', function (e) {
7070
// Clicked outside the datepicker, hide it
71-
if ($(e.target).closest('.datepicker').length == 0) {
71+
if ($(e.target).closest('.datepicker').length === 0) {
7272
that.hide();
7373
}
7474
});
@@ -87,6 +87,7 @@
8787
this.keyboardNavigation = this.element.data('date-keyboard-navigation');
8888
}
8989

90+
this.viewMode = this.startViewMode = 0;
9091
switch(options.startView || this.element.data('date-start-view')){
9192
case 2:
9293
case 'decade':
@@ -96,11 +97,6 @@
9697
case 'year':
9798
this.viewMode = this.startViewMode = 1;
9899
break;
99-
case 0:
100-
case 'month':
101-
default:
102-
this.viewMode = this.startViewMode = 0;
103-
break;
104100
}
105101

106102
this.todayBtn = (options.todayBtn||this.element.data('date-today-btn')||false);
@@ -110,8 +106,10 @@
110106
this.weekEnd = ((this.weekStart + 6) % 7);
111107
this.startDate = -Infinity;
112108
this.endDate = Infinity;
109+
this.daysOfWeekDisabled = [];
113110
this.setStartDate(options.startDate||this.element.data('date-startdate'));
114111
this.setEndDate(options.endDate||this.element.data('date-enddate'));
112+
this.setDaysOfWeekDisabled(options.daysOfWeekDisabled||this.element.data('date-days-of-week-disabled'));
115113
this.fillDow();
116114
this.fillMonths();
117115
this.update();
@@ -223,7 +221,7 @@
223221

224222
getDate: function() {
225223
var d = this.getUTCDate();
226-
return new Date(d.getTime() + (d.getTimezoneOffset()*60000))
224+
return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
227225
},
228226

229227
getUTCDate: function() {
@@ -274,6 +272,18 @@
274272
this.updateNavArrows();
275273
},
276274

275+
setDaysOfWeekDisabled: function(daysOfWeekDisabled){
276+
this.daysOfWeekDisabled = daysOfWeekDisabled||[];
277+
if (!$.isArray(this.daysOfWeekDisabled)) {
278+
this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
279+
}
280+
this.daysOfWeekDisabled = $.map(this.daysOfWeekDisabled, function (d) {
281+
return parseInt(d, 10);
282+
});
283+
this.update();
284+
this.updateNavArrows();
285+
},
286+
277287
place: function(){
278288
if(this.isInline) return;
279289
var zIndex = parseInt(this.element.parents().filter(function() {
@@ -311,8 +321,8 @@
311321
},
312322

313323
fillDow: function(){
314-
var dowCnt = this.weekStart;
315-
var html = '<tr>';
324+
var dowCnt = this.weekStart,
325+
html = '<tr>';
316326
while (dowCnt < this.weekStart + 7) {
317327
html += '<th class="dow">'+dates[this.language].daysMin[(dowCnt++)%7]+'</th>';
318328
}
@@ -321,8 +331,8 @@
321331
},
322332

323333
fillMonths: function(){
324-
var html = '';
325-
var i = 0
334+
var html = '',
335+
i = 0;
326336
while (i < 12) {
327337
html += '<span class="month">'+dates[this.language].monthsShort[i++]+'</span>';
328338
}
@@ -375,7 +385,8 @@
375385
if (prevMonth.valueOf() == currentDate) {
376386
clsName += ' active';
377387
}
378-
if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate) {
388+
if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
389+
$.inArray(prevMonth.getUTCDay(), this.daysOfWeekDisabled) !== -1) {
379390
clsName += ' disabled';
380391
}
381392
html.push('<td class="day'+clsName+'">'+prevMonth.getUTCDate() + '</td>');
@@ -516,7 +527,7 @@
516527
var year = this.viewDate.getUTCFullYear(),
517528
month = this.viewDate.getUTCMonth();
518529
if (target.is('.old')) {
519-
if (month == 0) {
530+
if (month === 0) {
520531
month = 11;
521532
year -= 1;
522533
} else {
@@ -556,8 +567,8 @@
556567
}
557568
if (element) {
558569
element.change();
559-
if (this.autoclose) {
560-
this.hide();
570+
if (this.autoclose && (!which || which == 'date')) {
571+
this.hide();
561572
}
562573
}
563574
},
@@ -746,7 +757,7 @@
746757
monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
747758
today: "Today"
748759
}
749-
}
760+
};
750761

751762
var DPGlobal = {
752763
modes: [

js/locales/bootstrap-datepicker.lt.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
daysMin: ["Sk", "Pr", "An", "Tr", "Ke", "Pn", "Št", "Sk"],
1111
months: ["Sausis", "Vasaris", "Kovas", "Balandis", "Gegužė", "Birželis", "Liepa", "Rugpjūtis", "Rugsėjis", "Spalis", "Lapkritis", "Gruodis"],
1212
monthsShort: ["Sau", "Vas", "Kov", "Bal", "Geg", "Bir", "Lie", "Rugp", "Rugs", "Spa", "Lap", "Gru"],
13+
today: "Šiandien",
1314
weekStart: 1
1415
};
1516
}(jQuery));

js/locales/bootstrap-datepicker.ro.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Romanian translation for bootstrap-datepicker
3+
* Cristian Vasile <cristi.mie@gmail.com>
4+
*/
5+
;(function($){
6+
$.fn.datepicker.dates['ro'] = {
7+
days: ["Duminică", "Luni", "Marţi", "Miercuri", "Joi", "Vineri", "Sâmbătă", "Duminică"],
8+
daysShort: ["Dum", "Lun", "Mar", "Mie", "Joi", "Vin", "Sâm", "Dum"],
9+
daysMin: ["Du", "Lu", "Ma", "Mi", "Jo", "Vi", "Sâ", "Du"],
10+
months: ["Ianuarie", "Februarie", "Martie", "Aprilie", "Mai", "Iunie", "Iulie", "August", "Septembrie", "Octombrie", "Noiembrie", "Decembrie"],
11+
monthsShort: ["Ian", "Feb", "Mar", "Apr", "Mai", "Iun", "Iul", "Aug", "Sep", "Oct", "Nov", "Dec"],
12+
today: "Astăzi",
13+
weekStart: 1
14+
};
15+
}(jQuery));
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Serbian latin translation for bootstrap-datepicker
3+
* Bojan Milosavlević <milboj@gmail.com>
4+
*/
5+
;(function($){
6+
$.fn.datepicker.dates['rs'] = {
7+
days: ["Nedelja","Ponedeljak", "Utorak", "Sreda", "Četvrtak", "Petak", "Subota", "Nedelja"],
8+
daysShort: ["Ned", "Pon", "Uto", "Sre", "Čet", "Pet", "Sub", "Ned"],
9+
daysMin: ["N", "Po", "U", "Sr", "Č", "Pe", "Su", "N"],
10+
months: ["Januar", "Februar", "Mart", "April", "Maj", "Jun", "Jul", "Avgust", "Septembar", "Oktobar", "Novembar", "Decembar"],
11+
monthsShort: ["Jan", "Feb", "Mar", "Apr", "Maj", "Jun", "Jul", "Avg", "Sep", "Okt", "Nov", "Dec"],
12+
today: "Danas"
13+
};
14+
}(jQuery));

js/locales/bootstrap-datepicker.rs.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Serbian cyrillic translation for bootstrap-datepicker
3+
* Bojan Milosavlević <milboj@gmail.com>
4+
*/
5+
;(function($){
6+
$.fn.datepicker.dates['rs'] = {
7+
days: ["Недеља","Понедељак", "Уторак", "Среда", "Четвртак", "Петак", "Субота", "Недеља"],
8+
daysShort: ["Нед", "Пон", "Уто", "Сре", "Чет", "Пет", "Суб", "Нед"],
9+
daysMin: ["Н", "По", "У", "Ср", "Ч", "Пе", "Су", "Н"],
10+
months: ["Јануар", "Фебруар", "Март", "Април", "Мај", "Јун", "Јул", "Август", "Септембар", "Октобар", "Новембар", "Децембар"],
11+
monthsShort: ["Јан", "Феб", "Мар", "Апр", "Мај", "Јун", "Јул", "Авг", "Сеп", "Окт", "Нов", "Дец"],
12+
today: "Данас"
13+
};
14+
}(jQuery));

js/locales/bootstrap-datepicker.sk.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Slovak translation for bootstrap-datepicker
3+
* Marek Lichtner <marek@licht.sk>
4+
*/
5+
;(function($){
6+
$.fn.datepicker.dates["sk"] = {
7+
days: ["Nedeľa", "Pondelok", "Utorok", "Streda", "Štvrtok", "Piatok", "Sobota", "Nedeľa"],
8+
daysShort: ["Ne", "Po", "Ut", "St", "Št", "Pi", "So", "Ne"],
9+
daysMin: ["Ne", "Po", "Ut", "St", "Št", "Pi", "So", "Ne"],
10+
months: ["Január", "Február", "Marec", "Apríl", "Máj", "Jún", "Júl", "August", "September", "Október", "November", "December"],
11+
monthsShort: ["Jan", "Feb", "Mar", "Apr", "Máj", "Jún", "Júl", "Aug", "Sep", "Okt", "Nov", "Dec"],
12+
today: "Dnes"
13+
};
14+
}(jQuery));

tests/suites/options.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,24 @@ test('Today Highlight: today\'s date is highlighted when not active', patch_date
262262
ok(!target.hasClass('today'), 'Tomorrow is not marked with "today" class');
263263
}));
264264

265+
test('DaysOfWeekDisabled', function(){
266+
var input = $('<input />')
267+
.appendTo('#qunit-fixture')
268+
.val('2012-10-26')
269+
.datepicker({
270+
format: 'yyyy-mm-dd',
271+
daysOfWeekDisabled: '1,5'
272+
}),
273+
dp = input.data('datepicker'),
274+
picker = dp.picker,
275+
target;
276+
277+
278+
input.focus();
279+
target = picker.find('.datepicker-days tbody td:nth(22)');
280+
ok(target.hasClass('disabled'), 'Day of week is disabled');
281+
target = picker.find('.datepicker-days tbody td:nth(24)');
282+
ok(!target.hasClass('disabled'), 'Day of week is enabled');
283+
target = picker.find('.datepicker-days tbody td:nth(26)');
284+
ok(target.hasClass('disabled'), 'Day of week is disabled');
285+
});

0 commit comments

Comments
 (0)