Clean up the position function and move the menu into the screen if it goes away

This is supposed to fix this downstream bug:
https://bugzilla.wikimedia.org/show_bug.cgi?id=52154