Adapt right/left positioning according to the direction of the input element

This fixes Bugzilla issue
https://bugzilla.wikimedia.org/show_bug.cgi?id=45585

The fix was mostly done by @mooeypoo, with a bit of mentoring from me.