Skip to content

Commit 01f45ae

Browse files
committed
#67 fix calendar topIndex month does not fit
1 parent 896382e commit 01f45ae

File tree

5 files changed

+14
-26
lines changed

5 files changed

+14
-26
lines changed

css/material-datetimepicker.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ md-menu-content.dtp-year-list {
137137
}
138138

139139
.dtp div.dtp-picker-month, .dtp div.dtp-actual-time {
140-
font-size: 1.2em;
140+
font-size: 1em;
141141
font-weight: 500;
142142
text-align: center;
143143
}
@@ -164,7 +164,7 @@ md-menu-content.dtp-year-list {
164164

165165
.dtp table.dtp-picker-days {
166166
margin: 0;
167-
min-height: 220px;
167+
min-height: 260px;
168168
}
169169

170170
.dtp md-virtual-repeat-container.months {
@@ -176,7 +176,7 @@ md-menu-content.dtp-year-list {
176176
}
177177

178178
.dtp table.dtp-picker-days tr > td {
179-
font-size: 11px;
179+
font-size: 12px;
180180
text-align: center;
181181
padding: 0;
182182
}
@@ -229,7 +229,7 @@ md-menu-content.dtp-year-list {
229229
color: #757575;
230230
text-align: center;
231231
font-weight: 700;
232-
padding: 4px 3px;
232+
padding: 2px 3px;
233233
width: 38px;
234234
height: 28px;
235235
}

dist/angular-material-datetimepicker.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-material-datetimepicker.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/material-datetimepicker.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/angular-material-datetimepicker.js

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -547,29 +547,20 @@
547547
return this.meridien === 'PM';
548548
},
549549
incrementMonth: function (amount) {
550-
if (amount === 1 && this.isNextMonthVisible()) {
551-
this.selectDate(this.currentDate.add(amount, 'month'));
552-
}
553-
554-
if (amount === -1 && this.isPreviousMonthVisible()) {
550+
if ((amount === 1 && this.isNextMonthVisible()) || (amount === -1 && this.isPreviousMonthVisible())) {
555551
this.selectDate(this.currentDate.add(amount, 'month'));
556552
}
557553
},
558554
incrementYear: function (amount) {
559-
if (amount === 1 && this.isNextYearVisible()) {
560-
this.selectDate(this.currentDate.add(amount, 'year'));
561-
}
562-
563-
if (amount === -1 && this.isPreviousYearVisible()) {
555+
if ((amount === 1 && this.isNextYearVisible()) || (amount === -1 && this.isPreviousYearVisible())) {
564556
this.selectDate(this.currentDate.add(amount, 'year'));
565557
}
566558
},
567559
openMenu: function ($mdMenu, ev) {
568560
$mdMenu.open(ev);
569561
},
570562
monthsAvailable: function () {
571-
var monthsArr = [],
572-
_date = moment(this.currentDate);
563+
var monthsArr = [], _date = moment(this.currentDate);
573564

574565
for (var m = 0; m < 12; m++) {
575566
var curMonth = _date.month(m);
@@ -788,17 +779,14 @@
788779
var YEAR_MIN = 1920,
789780
YEAR_MAX = new Date().getFullYear() + 30,
790781
MONTHS_IN_ALL = (YEAR_MAX - YEAR_MIN + 1) * 12,
791-
ITEM_HEIGHT = 240,
792782
MONTHS = [];
793783
for (var i = 0; i < MONTHS_IN_ALL; i++) {
794784
MONTHS.push(i);
795785
}
796786

797787
var currentMonthIndex = function (date, low) {
798788
low = low ? low : 0;
799-
var year = date.year();
800-
var month = date.month();
801-
return (((year - YEAR_MIN) * 12) + month - 1) - low;
789+
return (((date.year() - YEAR_MIN) * 12) + date.month() - 1) - low;
802790
};
803791

804792
return {
@@ -826,7 +814,7 @@
826814
calendar.months = MONTHS;
827815
} else {
828816
var low = picker.minDate ? currentMonthIndex(picker.minDate) : 0;
829-
var high = picker.maxDate ? (currentMonthIndex(picker.maxDate) + 1) : MONTHS_IN_ALL;
817+
var high = picker.maxDate ? (currentMonthIndex(picker.maxDate) +1) : MONTHS_IN_ALL;
830818
calendar.months = MONTHS.slice(low, high);
831819
}
832820

@@ -847,7 +835,7 @@
847835
}, function (val2, val1) {
848836
if (val2 != val1) {
849837
var nDate = moment(val2, 'YYYY-MM');
850-
var low = picker.minDate ? currentMonthIndex(picker.minDate) : 0;
838+
var low = picker.minDate ? currentMonthIndex(picker.minDate): 0;
851839
var index = currentMonthIndex(nDate, low);
852840
if (calendar.topIndex != index) {
853841
calendar.topIndex = index;
@@ -927,7 +915,7 @@
927915
}],
928916
template:
929917
'<md-virtual-repeat-container md-top-index="cal.topIndex" class="months">' +
930-
'<div md-virtual-repeat="idx in ::cal.months" md-auto-shrink md-item-size="' + ITEM_HEIGHT + '">' +
918+
'<div md-virtual-repeat="idx in cal.months">' +
931919
' <div mdc-datetime-picker-calendar-month idx="idx"></div>' +
932920
'</div>' +
933921
'</md-virtual-repeat-container>'

0 commit comments

Comments
 (0)