Make popup be centered, not right

This popup always came up to the right because a <span> (used to calculate position) was only inserted at the end. This code also puts a <span> at the beginning of the selection, so we can find the center. (I think this was hard because, in order to put a span at the beginning, the selection needs to be collapsed and we thus loose the selection. But this pull req restores the selection.)

I think this only works in IE 9 and later, not sure though. Over the years I've gotten sloppy about testing earlier IEs, especially for javascript stuff...