A few JS fixes

* missing $ (needed for offset()) 
* accounts for scrolling to an id that doesn't exist
* run the same logic when the definition is on the current page as when it is not
* updates the history links in the versions tab as the user changes the toc