ivaynberg/select2 — pull request #2595 by rodnaph (2014-08-07 10:55:37+00:00)
Title: Adds check for enough room before switching right to left drop

Previously, a check was done to see if there was enough space to the right to display the dropdown. If there was not then the dropdown was moved to the left. But, there may not be enough room on the left either (which is my case) which would leave the user only able to see the far right of the dropdown, missing most of the text.

![image](https://cloud.githubusercontent.com/assets/447579/3840638/cadd27ac-1e20-11e4-96e8-9dad3362d7c3.png)

This change checks if there is room on the left before making this switch.

If this check fails then it seems there isn't enough room on the left or right to display the dropdown, but I think it's better (in the case of LTR languages anyway) to display the dropdown on the right as this will give the user the best visibility of the text.

![image](https://cloud.githubusercontent.com/assets/447579/3840680/524d33ee-1e21-11e4-9943-1ab5496823c1.png)

Also - the enoughRoomOnRight variable is now a function, so no need (i think) to set its value in multiple places.

I've had to do a recalculation for the container.outerWidth() in enoughRoomOnLeft as for dynamically widened dropdowns the width variable gets reset to the width of the dropdown, not the original control.