@@ -1222,9 +1222,10 @@ the specific language governing permissions and limitations under the Apache Lic
12221222 // abstract
12231223 positionDropdown : function ( ) {
12241224 var $dropdown = this . dropdown ,
1225- offset = this . container . offset ( ) ,
1226- height = this . container . outerHeight ( false ) ,
1227- width = this . container . outerWidth ( false ) ,
1225+ container = this . container ,
1226+ offset = container . offset ( ) ,
1227+ height = container . outerHeight ( false ) ,
1228+ width = container . outerWidth ( false ) ,
12281229 dropHeight = $dropdown . outerHeight ( false ) ,
12291230 $window = $ ( window ) ,
12301231 windowWidth = $window . width ( ) ,
@@ -1236,7 +1237,12 @@ the specific language governing permissions and limitations under the Apache Lic
12361237 enoughRoomBelow = dropTop + dropHeight <= viewportBottom ,
12371238 enoughRoomAbove = ( offset . top - dropHeight ) >= $window . scrollTop ( ) ,
12381239 dropWidth = $dropdown . outerWidth ( false ) ,
1239- enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight ,
1240+ enoughRoomOnRight = function ( ) {
1241+ return dropLeft + dropWidth <= viewPortRight ;
1242+ } ,
1243+ enoughRoomOnLeft = function ( ) {
1244+ return offset . left + viewPortLeft + container . outerWidth ( false ) > dropWidth ;
1245+ } ,
12401246 aboveNow = $dropdown . hasClass ( "select2-drop-above" ) ,
12411247 bodyOffset ,
12421248 above ,
@@ -1271,7 +1277,6 @@ the specific language governing permissions and limitations under the Apache Lic
12711277 dropTop = offset . top + height ;
12721278 dropLeft = offset . left ;
12731279 dropWidth = $dropdown . outerWidth ( false ) ;
1274- enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight ;
12751280 $dropdown . show ( ) ;
12761281
12771282 // 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
12861291 dropWidth = $dropdown . outerWidth ( false ) + ( resultsListNode . scrollHeight === resultsListNode . clientHeight ? 0 : scrollBarDimensions . width ) ;
12871292 dropWidth > width ? width = dropWidth : dropWidth = width ;
12881293 dropHeight = $dropdown . outerHeight ( false ) ;
1289- enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight ;
12901294 }
12911295 else {
12921296 this . container . removeClass ( 'select2-drop-auto-width' ) ;
@@ -1302,7 +1306,7 @@ the specific language governing permissions and limitations under the Apache Lic
13021306 dropLeft -= bodyOffset . left ;
13031307 }
13041308
1305- if ( ! enoughRoomOnRight ) {
1309+ if ( ! enoughRoomOnRight ( ) && enoughRoomOnLeft ( ) ) {
13061310 dropLeft = offset . left + this . container . outerWidth ( false ) - dropWidth ;
13071311 }
13081312
0 commit comments