only switch right to left drop when enough room available
This commit is contained in:
parent
3c17d3b5bb
commit
d2c9b9aac3
18
select2.js
18
select2.js
@ -1222,9 +1222,10 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
// abstract
|
// abstract
|
||||||
positionDropdown: function() {
|
positionDropdown: function() {
|
||||||
var $dropdown = this.dropdown,
|
var $dropdown = this.dropdown,
|
||||||
offset = this.container.offset(),
|
container = this.container,
|
||||||
height = this.container.outerHeight(false),
|
offset = container.offset(),
|
||||||
width = this.container.outerWidth(false),
|
height = container.outerHeight(false),
|
||||||
|
width = container.outerWidth(false),
|
||||||
dropHeight = $dropdown.outerHeight(false),
|
dropHeight = $dropdown.outerHeight(false),
|
||||||
$window = $(window),
|
$window = $(window),
|
||||||
windowWidth = $window.width(),
|
windowWidth = $window.width(),
|
||||||
@ -1236,7 +1237,12 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
enoughRoomBelow = dropTop + dropHeight <= viewportBottom,
|
enoughRoomBelow = dropTop + dropHeight <= viewportBottom,
|
||||||
enoughRoomAbove = (offset.top - dropHeight) >= $window.scrollTop(),
|
enoughRoomAbove = (offset.top - dropHeight) >= $window.scrollTop(),
|
||||||
dropWidth = $dropdown.outerWidth(false),
|
dropWidth = $dropdown.outerWidth(false),
|
||||||
enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight,
|
enoughRoomOnRight = function() {
|
||||||
|
return dropLeft + dropWidth <= viewPortRight;
|
||||||
|
},
|
||||||
|
enoughRoomOnLeft = function() {
|
||||||
|
return offset.left + viewPortLeft + container.outerWidth(false) > dropWidth;
|
||||||
|
},
|
||||||
aboveNow = $dropdown.hasClass("select2-drop-above"),
|
aboveNow = $dropdown.hasClass("select2-drop-above"),
|
||||||
bodyOffset,
|
bodyOffset,
|
||||||
above,
|
above,
|
||||||
@ -1271,7 +1277,6 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
dropTop = offset.top + height;
|
dropTop = offset.top + height;
|
||||||
dropLeft = offset.left;
|
dropLeft = offset.left;
|
||||||
dropWidth = $dropdown.outerWidth(false);
|
dropWidth = $dropdown.outerWidth(false);
|
||||||
enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight;
|
|
||||||
$dropdown.show();
|
$dropdown.show();
|
||||||
|
|
||||||
// fix so the cursor does not move to the left within the search-textbox in IE
|
// fix so the cursor does not move to the left within the search-textbox in IE
|
||||||
@ -1286,7 +1291,6 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
dropWidth = $dropdown.outerWidth(false) + (resultsListNode.scrollHeight === resultsListNode.clientHeight ? 0 : scrollBarDimensions.width);
|
dropWidth = $dropdown.outerWidth(false) + (resultsListNode.scrollHeight === resultsListNode.clientHeight ? 0 : scrollBarDimensions.width);
|
||||||
dropWidth > width ? width = dropWidth : dropWidth = width;
|
dropWidth > width ? width = dropWidth : dropWidth = width;
|
||||||
dropHeight = $dropdown.outerHeight(false);
|
dropHeight = $dropdown.outerHeight(false);
|
||||||
enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.container.removeClass('select2-drop-auto-width');
|
this.container.removeClass('select2-drop-auto-width');
|
||||||
@ -1302,7 +1306,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
dropLeft -= bodyOffset.left;
|
dropLeft -= bodyOffset.left;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!enoughRoomOnRight) {
|
if (!enoughRoomOnRight() && enoughRoomOnLeft()) {
|
||||||
dropLeft = offset.left + this.container.outerWidth(false) - dropWidth;
|
dropLeft = offset.left + this.container.outerWidth(false) - dropWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user