Fixes height issue with popup

Popups were extending to the whole height of the page. This fixes that
by checking the height when the popups are layered behind the content
and then truncating it if it extends beyond the page height.