rails/turbolinks — pull request #162 by reednj77 (2013-01-11 22:12:47+00:00)
Title: Abort XHR on popstate / Maintain history when aborting XHR

I was working on a fix for #155 yesterday, but @davydotcom beat me to the punch this morning. He took almost the exact approach as I was, but his commit didn't handle a couple side effects:

1. If you clicked a link and then clicked the back button before the request finished, the page would still change to the requested page once the request finally finished. Adding `xhr?.abort()` to `fetchHistory()` fixes this.

2. If you clicked a link and then clicked another link before the first one loaded, the first one will abort and the second requested page will load. This is what we just fixed, but if the next thing you do is click the back button, nothing will happen. Calling `rememberCurrentUrl()` on xhr abort ensures the proper behavior when navigating the history.

3. I also refactored a little bit by moving all the `xhr = null` statements into the `onloadend` callback.