@@ -1225,9 +1225,10 @@ the specific language governing permissions and limitations under the Apache Lic
12251225 // abstract
12261226 positionDropdown : function ( ) {
12271227 var $dropdown = this . dropdown ,
1228- offset = this . container . offset ( ) ,
1229- height = this . container . outerHeight ( false ) ,
1230- width = this . container . outerWidth ( false ) ,
1228+ container = this . container ,
1229+ offset = container . offset ( ) ,
1230+ height = container . outerHeight ( false ) ,
1231+ width = container . outerWidth ( false ) ,
12311232 dropHeight = $dropdown . outerHeight ( false ) ,
12321233 $window = $ ( window ) ,
12331234 windowWidth = $window . width ( ) ,
@@ -1239,7 +1240,12 @@ the specific language governing permissions and limitations under the Apache Lic
12391240 enoughRoomBelow = dropTop + dropHeight <= viewportBottom ,
12401241 enoughRoomAbove = ( offset . top - dropHeight ) >= $window . scrollTop ( ) ,
12411242 dropWidth = $dropdown . outerWidth ( false ) ,
1242- enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight ,
1243+ enoughRoomOnRight = function ( ) {
1244+ return dropLeft + dropWidth <= viewPortRight ;
1245+ } ,
1246+ enoughRoomOnLeft = function ( ) {
1247+ return offset . left + viewPortLeft + container . outerWidth ( false ) > dropWidth ;
1248+ } ,
12431249 aboveNow = $dropdown . hasClass ( "select2-drop-above" ) ,
12441250 bodyOffset ,
12451251 above ,
@@ -1274,7 +1280,6 @@ the specific language governing permissions and limitations under the Apache Lic
12741280 dropTop = offset . top + height ;
12751281 dropLeft = offset . left ;
12761282 dropWidth = $dropdown . outerWidth ( false ) ;
1277- enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight ;
12781283 $dropdown . show ( ) ;
12791284
12801285 // fix so the cursor does not move to the left within the search-textbox in IE
@@ -1289,7 +1294,6 @@ the specific language governing permissions and limitations under the Apache Lic
12891294 dropWidth = $dropdown . outerWidth ( false ) + ( resultsListNode . scrollHeight === resultsListNode . clientHeight ? 0 : scrollBarDimensions . width ) ;
12901295 dropWidth > width ? width = dropWidth : dropWidth = width ;
12911296 dropHeight = $dropdown . outerHeight ( false ) ;
1292- enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight ;
12931297 }
12941298 else {
12951299 this . container . removeClass ( 'select2-drop-auto-width' ) ;
@@ -1305,7 +1309,7 @@ the specific language governing permissions and limitations under the Apache Lic
13051309 dropLeft -= bodyOffset . left ;
13061310 }
13071311
1308- if ( ! enoughRoomOnRight ) {
1312+ if ( ! enoughRoomOnRight ( ) && enoughRoomOnLeft ( ) ) {
13091313 dropLeft = offset . left + this . container . outerWidth ( false ) - dropWidth ;
13101314 }
13111315
0 commit comments