Skip to content

Commit 953b6f2

Browse files
author
Dave Smith
committed
Fix mask height/width when document is shorter than window
When the document element (e.g., the body) is shorter than the window, the select2-drop-mask was not extending all the way to the bottom of the browser viewport, leading to an area below the body that was clickable but that select2 did not notice. Thus, if a user clicked down there, the drop would not disappear. This is particularly troublesome if the page contains absolutely positioned elements at the bottom of the browser window.
1 parent 66860b2 commit 953b6f2

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

select2.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,9 +1121,7 @@ the specific language governing permissions and limitations under the Apache Lic
11211121
this.dropdown.attr("id", "select2-drop");
11221122

11231123
// show the elements
1124-
mask.css({
1125-
width: document.documentElement.scrollWidth,
1126-
height: document.documentElement.scrollHeight});
1124+
mask.css(_makeMaskCss());
11271125
mask.show();
11281126
this.dropdown.show();
11291127
this.positionDropdown();
@@ -1136,14 +1134,19 @@ the specific language governing permissions and limitations under the Apache Lic
11361134
var that = this;
11371135
this.container.parents().add(window).each(function () {
11381136
$(this).bind(resize+" "+scroll+" "+orient, function (e) {
1139-
$("#select2-drop-mask").css({
1140-
width:document.documentElement.scrollWidth,
1141-
height:document.documentElement.scrollHeight});
1137+
$("#select2-drop-mask").css(_makeMaskCss());
11421138
that.positionDropdown();
11431139
});
11441140
});
11451141

11461142
this.focusSearch();
1143+
1144+
function _makeMaskCss() {
1145+
return {
1146+
width : Math.max(document.documentElement.scrollWidth, $(window).width()),
1147+
height : Math.max(document.documentElement.scrollHeight, $(window).height())
1148+
}
1149+
}
11471150
},
11481151

11491152
// abstract

0 commit comments

Comments
 (0)