소스 검색

fixed above/below dropdown opening bug

Igor Vaynberg 13 년 전
부모
커밋
39aa17a790
1개의 변경된 파일9개의 추가작업 그리고 4개의 파일을 삭제
  1. 9 4
      select2.js

+ 9 - 4
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(),