Popup: Correctly enhance popup and its contents before opening

This is a better fix than the one provided in the original PR for this, because
it avoids the use of .enhanceWithin(), and it moves the image width/height
retrieval to popupbeforeposition, which is correct, because during creation the
popup is truncated to 1px x 1px.

Closes gh-7290
Fixes gh-7336