fix #675 Dialog disappears after resize

When the viewport was resized significantly, so that `dialogOldPosition.left` > `newViewport.width`, the Dialog disappeared and never appeared again.

The problem was introduced by e6405a1b79c707f2b4090875ea2e2673f29d5c71 by the check if reference position is in viewport before displaying the popup. The check has been moved to the other place in the code.

---

#639 dealt with a very similar issue but it seems it broke some liquid layout behaviors by adding excessive scrollbars in IE8. The fix from #639 can be reverted as the fix proposed here makes it unnecessary.