Skip to content

Commit fc790d9

Browse files
committed
Merge branch 'master' of github.com:dangrossman/bootstrap-daterangepicker
2 parents 8f2848e + 80758ca commit fc790d9

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed

daterangepicker.js

+44-20
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@
858858

859859
var html, selected, minDate, maxDate = this.maxDate;
860860

861-
if (this.maxSpan && (!this.maxDate || this.startDate.clone().add(this.maxSpan).isAfter(this.maxDate)))
861+
if (this.maxSpan && (!this.maxDate || this.startDate.clone().add(this.maxSpan).isBefore(this.maxDate)))
862862
maxDate = this.startDate.clone().add(this.maxSpan);
863863

864864
if (side == 'left') {
@@ -1037,44 +1037,68 @@
10371037
containerTop = this.element.offset().top - this.container.outerHeight() - parentOffset.top;
10381038
else
10391039
containerTop = this.element.offset().top + this.element.outerHeight() - parentOffset.top;
1040+
1041+
// Force the container to it's actual width
1042+
this.container.css({
1043+
top: 0,
1044+
left: 0,
1045+
right: 'auto'
1046+
});
1047+
var containerWidth = this.container.outerWidth();
1048+
10401049
this.container[this.drops == 'up' ? 'addClass' : 'removeClass']('drop-up');
10411050

10421051
if (this.opens == 'left') {
1043-
this.container.css({
1044-
top: containerTop,
1045-
right: parentRightEdge - this.element.offset().left - this.element.outerWidth(),
1046-
left: 'auto'
1047-
});
1048-
if (this.container.offset().left < 0) {
1052+
var containerRight = parentRightEdge - this.element.offset().left - this.element.outerWidth();
1053+
if (containerWidth + containerRight > $(window).width()) {
10491054
this.container.css({
1055+
top: containerTop,
10501056
right: 'auto',
10511057
left: 9
10521058
});
1059+
} else {
1060+
this.container.css({
1061+
top: containerTop,
1062+
right: containerRight,
1063+
left: 'auto'
1064+
});
10531065
}
10541066
} else if (this.opens == 'center') {
1055-
this.container.css({
1056-
top: containerTop,
1057-
left: this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2
1058-
- this.container.outerWidth() / 2,
1059-
right: 'auto'
1060-
});
1061-
if (this.container.offset().left < 0) {
1067+
var containerLeft = this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2
1068+
- containerWidth / 2;
1069+
if (containerLeft < 0) {
10621070
this.container.css({
1071+
top: containerTop,
10631072
right: 'auto',
10641073
left: 9
10651074
});
1075+
} else if (containerLeft + containerWidth > $(window).width()) {
1076+
this.container.css({
1077+
top: containerTop,
1078+
left: 'auto',
1079+
right: 0
1080+
});
1081+
} else {
1082+
this.container.css({
1083+
top: containerTop,
1084+
left: containerLeft,
1085+
right: 'auto'
1086+
});
10661087
}
10671088
} else {
1068-
this.container.css({
1069-
top: containerTop,
1070-
left: this.element.offset().left - parentOffset.left,
1071-
right: 'auto'
1072-
});
1073-
if (this.container.offset().left + this.container.outerWidth() > $(window).width()) {
1089+
var containerLeft = this.element.offset().left - parentOffset.left;
1090+
if (containerLeft + containerWidth > $(window).width()) {
10741091
this.container.css({
1092+
top: containerTop,
10751093
left: 'auto',
10761094
right: 0
10771095
});
1096+
} else {
1097+
this.container.css({
1098+
top: containerTop,
1099+
left: containerLeft,
1100+
right: 'auto'
1101+
});
10781102
}
10791103
}
10801104
},

0 commit comments

Comments
 (0)