Skip to content
This repository
Browse code

Merge pull request #379 from brentburgoyne/master

Fix for drop down positioning issue
  • Loading branch information...
commit 12d117024275e739a0be25b009abcfbbebf57025 2 parents e5a2824 + 5580dbb
Igor Vaynberg authored

Showing 1 changed file with 11 additions and 1 deletion. Show diff stats Hide diff stats

  1. +11 1 select2.js
12 select2.js
@@ -867,15 +867,25 @@
867 867 dropHeight = this.dropdown.outerHeight(),
868 868 viewportBottom = $(window).scrollTop() + document.documentElement.clientHeight,
869 869 dropTop = offset.top + height,
  870 + dropLeft = offset.left,
870 871 enoughRoomBelow = dropTop + dropHeight <= viewportBottom,
871 872 enoughRoomAbove = (offset.top - dropHeight) >= this.body().scrollTop(),
872 873 aboveNow = this.dropdown.hasClass("select2-drop-above"),
  874 + bodyOffset,
873 875 above,
874 876 css;
875 877
876 878 // console.log("below/ droptop:", dropTop, "dropHeight", dropHeight, "sum", (dropTop+dropHeight)+" viewport bottom", viewportBottom, "enough?", enoughRoomBelow);
877 879 // console.log("above/ offset.top", offset.top, "dropHeight", dropHeight, "top", (offset.top-dropHeight), "scrollTop", this.body().scrollTop(), "enough?", enoughRoomAbove);
878 880
  881 + // fix positioning when body has an offset and is not position: static
  882 +
  883 + if (this.body().css('position') !== 'static') {
  884 + bodyOffset = this.body().offset();
  885 + dropTop -= bodyOffset.top;
  886 + dropLeft -= bodyOffset.left;
  887 + }
  888 +
879 889 // always prefer the current above/below alignment, unless there is not enough room
880 890
881 891 if (aboveNow) {
@@ -898,7 +908,7 @@
898 908
899 909 css = $.extend({
900 910 top: dropTop,
901   - left: offset.left,
  911 + left: dropLeft,
902 912 width: width
903 913 }, evaluate(this.opts.dropdownCss));
904 914

0 comments on commit 12d1170

Please sign in to comment.
Something went wrong with that request. Please try again.