cferdinandi/smooth-scroll — pull request #18 by robertpateii (2013-12-31 23:35:39+00:00)
Title: Fix back button when using the data-url feature

Hello again!

As we discussed on #17, here's the fix for the back button. Thanks for taking time with this!

*Pseudo code:*

1. Page loads. Chrome/Safari fire **onpopstate** event, Firefox doesn't.
1. User clicks a smooth scroll link, is scrolled to it, and the URL is updated.
1. User clicks back.
* Browser removes the URL fragment that was added.
* Browser fires **onpopstate** with a default event.
* My code sees the event is the default event and sends the user to the top.

*Other notes:*

I updated your **history.pushState** so it creates events with unique info.

As before, clicking multiple smooth scroll links will update the URL fragment each time. Clicking back between them changes the URL and position to the previous fragment. So **onpopstate* isn't needed in this case, even though it still fires.

## Test cases ##

**Test A:**

1. load the page
1. click a smooth scroll link
1. click back

*Page position should be at the top of the page.*

**Test B:**

1. load page
1. click smooth scroll link
1. go to a different page or website
1. click back

*Page position should be the same as when you left the smooth scroll page.*

**Test C:**

1. load page
1. scroll down manually to a smooth scroll link and click it
1. click back

*Page position should be at the top of the page. (Some may prefer that the position return to where you clicked the link. I understand, but that's hard and this behavior is still better than the back button doing nothing.)*

**Test D:**

1. load page with a url fragment, i.e. #bazinga

*Page should load with the #bazinga element at the top.*