Skip to content

Commit

Permalink
Added maxViewMode to options
Browse files Browse the repository at this point in the history
Fixed bower version mismatch

Applied maxViewMode to view states

Revert "Fixed bower version mismatch"

This reverts commit 0693900.

Added docs
  • Loading branch information
Bob Olde Hampsink committed Mar 31, 2015
1 parent bf11f8b commit affed43
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
10 changes: 9 additions & 1 deletion docs/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,17 @@ minViewMode

Number, String. Default: 0, "days"

Set a limit for the view mode. Accepts: "days" or 0, "months" or 1, and "years" or 2.
Set a minimum limit for the view mode. Accepts: "days" or 0, "months" or 1, and "years" or 2.
Gives the ability to pick only a month or an year. The day is set to the 1st for "months", and the month is set to January for "years".

maxViewMode
-----------

Number, String. Default: 2, "years"

Set a maximum limit for the view mode. Accepts: "days" or 0, "months" or 1, and "years" or 2.
Gives the ability to pick only a day or a month. The day is set to the 1st for "months", and the month is set to January for "years".

multidate
---------

Expand Down
30 changes: 23 additions & 7 deletions js/bootstrap-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,20 @@
o.minViewMode = 0;
}

switch (o.maxViewMode) {
case 0:
case 'days':
o.maxViewMode = 0;
break;
case 1:
case 'months':
o.maxViewMode = 1;
break;
default:
o.maxViewMode = 2;
}

o.startView = Math.min(o.startView, o.maxViewMode);
o.startView = Math.max(o.startView, o.minViewMode);

// true, false, or Number > 0
Expand Down Expand Up @@ -235,7 +249,7 @@
o.daysOfWeekDisabled = $.map(o.daysOfWeekDisabled, function(d){
return parseInt(d, 10);
});

o.daysOfWeekHighlighted = o.daysOfWeekHighlighted||[];
if (!$.isArray(o.daysOfWeekHighlighted))
o.daysOfWeekHighlighted = o.daysOfWeekHighlighted.split(/[,\s]*/);
Expand Down Expand Up @@ -630,7 +644,7 @@
this.updateNavArrows();
return this;
},

setDaysOfWeekHighlighted: function(daysOfWeekHighlighted){
this._process_options({daysOfWeekHighlighted: daysOfWeekHighlighted});
this.update();
Expand Down Expand Up @@ -888,8 +902,8 @@
if (isNaN(year) || isNaN(month))
return;
this.picker.find('.datepicker-days thead .datepicker-switch')
.text(dates[this.o.language].months[month]+' '+year);
this.picker.find('tfoot .today')
.text(dates[this.o.language].months[month]+' '+ (this.o.maxViewMode < 2 ? '' : year));
this.picker.find('tfoot .today')
.text(todaytxt)
.toggle(this.o.todayBtn !== false);
this.picker.find('tfoot .clear')
Expand Down Expand Up @@ -956,7 +970,7 @@

var months = this.picker.find('.datepicker-months')
.find('th:eq(1)')
.text(year)
.text(this.o.maxViewMode < 2 ? 'Months' : year)
.end()
.find('span').removeClass('active');

Expand Down Expand Up @@ -1039,13 +1053,13 @@
break;
case 1:
case 2:
if (this.o.startDate !== -Infinity && year <= this.o.startDate.getUTCFullYear()){
if (this.o.startDate !== -Infinity && year <= this.o.startDate.getUTCFullYear() || this.o.maxViewMode < 2){
this.picker.find('.prev').css({visibility: 'hidden'});
}
else {
this.picker.find('.prev').css({visibility: 'visible'});
}
if (this.o.endDate !== Infinity && year >= this.o.endDate.getUTCFullYear()){
if (this.o.endDate !== Infinity && year >= this.o.endDate.getUTCFullYear() || this.o.maxViewMode < 2){
this.picker.find('.next').css({visibility: 'hidden'});
}
else {
Expand Down Expand Up @@ -1397,6 +1411,7 @@
showMode: function(dir){
if (dir){
this.viewMode = Math.max(this.o.minViewMode, Math.min(2, this.viewMode + dir));
this.viewMode = Math.max(this.o.minViewMode, Math.min(2, this.viewMode + dir, this.o.maxViewMode));
}
this.picker
.children('div')
Expand Down Expand Up @@ -1571,6 +1586,7 @@
keyboardNavigation: true,
language: 'en',
minViewMode: 0,
maxViewMode: 2,
multidate: false,
multidateSeparator: ',',
orientation: "auto",
Expand Down

0 comments on commit affed43

Please sign in to comment.