Added overflow check.

Hi, I'm not actually sure if this is really needed for everyone, but I needed to check if the popup menu was going   outside the window, so I implemented this quick feature (disabled by default).

Inside example.html there's an implementation of this.