From 39aa17a7906d2b26a2a17ef040550902242b0a87 Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Wed, 18 Jul 2012 00:26:49 +0300 Subject: [PATCH] fixed above/below dropdown opening bug --- select2.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/select2.js b/select2.js index 87b994af..d6f9254d 100755 --- a/select2.js +++ b/select2.js @@ -736,11 +736,14 @@ viewportBottom = $(window).scrollTop() + document.documentElement.clientHeight, dropTop = offset.top + height, enoughRoomBelow = dropTop + dropHeight <= viewportBottom, - enoughRoomAbove = (offset.top - dropHeight) >= this.body().scrollTop, + enoughRoomAbove = (offset.top - dropHeight) >= this.body().scrollTop(), aboveNow = this.dropdown.hasClass("select2-drop-above"), above, css; + //console.log("droptop:", dropTop, "dropHeight", dropHeight, "sum", (dropTop+dropHeight)+" viewport bottom", viewportBottom, "enough?", enoughRoomBelow); + //console.log("offset.top", offset.top, "dropHeight", dropHeight, "top", (offset.top-dropHeight), "scrollTop", this.body().scrollTop(), "enough?", enoughRoomAbove); + // always prefer the current above/below alignment, unless there is not enough room if (aboveNow) { @@ -814,8 +817,7 @@ if (this.search.val() === " ") { this.search.val(""); } this.dropdown.addClass("select2-drop-active"); - - this.positionDropdown(); + this.container.addClass("select2-dropdown-open").addClass("select2-container-active"); this.updateResults(true); @@ -826,7 +828,7 @@ this.dropdown.show(); this.ensureHighlightVisible(); this.focusSearch(); - this.container.addClass("select2-dropdown-open").addClass("select2-container-active"); + }, // abstract @@ -1003,6 +1005,9 @@ return; } + // position dropdown before making a potentially long request + this.positionDropdown(); + this.resultsPage = 1; opts.query({ term: search.val(),