1
0
mirror of synced 2024-11-23 05:26:10 +03:00

Merge pull request #576 from MaxxSoftware/master

DropLeft recount when DropDown not fit on the right
This commit is contained in:
Igor Vaynberg 2012-11-15 08:17:27 -08:00
commit 2fa9f73e3b

View File

@ -886,11 +886,14 @@ the specific language governing permissions and limitations under the Apache Lic
height = this.container.outerHeight(false), height = this.container.outerHeight(false),
width = this.container.outerWidth(false), width = this.container.outerWidth(false),
dropHeight = this.dropdown.outerHeight(false), dropHeight = this.dropdown.outerHeight(false),
viewPortRight = $(window).scrollLeft() + document.documentElement.clientWidth,
viewportBottom = $(window).scrollTop() + document.documentElement.clientHeight, viewportBottom = $(window).scrollTop() + document.documentElement.clientHeight,
dropTop = offset.top + height, dropTop = offset.top + height,
dropLeft = offset.left, dropLeft = offset.left,
enoughRoomBelow = dropTop + dropHeight <= viewportBottom, enoughRoomBelow = dropTop + dropHeight <= viewportBottom,
enoughRoomAbove = (offset.top - dropHeight) >= this.body().scrollTop(), enoughRoomAbove = (offset.top - dropHeight) >= this.body().scrollTop(),
dropWidth = this.dropdown.outerWidth(false),
enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight,
aboveNow = this.dropdown.hasClass("select2-drop-above"), aboveNow = this.dropdown.hasClass("select2-drop-above"),
bodyOffset, bodyOffset,
above, above,
@ -917,6 +920,10 @@ the specific language governing permissions and limitations under the Apache Lic
if (!enoughRoomBelow && enoughRoomAbove) above = true; if (!enoughRoomBelow && enoughRoomAbove) above = true;
} }
if (!enoughRoomOnRight) {
dropLeft = offset.left + width - dropWidth;
}
if (above) { if (above) {
dropTop = offset.top - dropHeight; dropTop = offset.top - dropHeight;
this.container.addClass("select2-drop-above"); this.container.addClass("select2-drop-above");