Fix Firefox middle-click popup blocker issue

I've tried to keep the changes as minimal as possible, basically we calculate the variables earlier and return from right- and middle-clicks / ctrl+clicks before we call `e.preventDefault()`.

@eviltrout said in meta this would need a significant amount of testing in various browsers before it can be incorporated into core, so maybe we can put this behind a site setting or make these changes via a plugin for a while to see if any issues crop up?