The Code
You can see the full code for this example on the GitHub repo for this blog. Most of the code is supporting Javascript — I'm using CoffeeScript for the app code, jQuery to do DOM Manipulation, JSONP (via $.getJSON) to retreive the tweets from Twitter's API, handlebars.js to format the tweets, and twiter_text.js to autolink usernames, links and hashtags.
The interesting bits are in twitter_timeline.coffee:
In particular, the didScroll
method should be interesting. As we
scroll, we're checking to see if we should permalink the page. When we call
permalink
, we use the History API replaceState
method to change the URL.
On the first page load the TwitterTimeline
constructor is called
and I parse out any max_id
in the URL to fetch tweets later than that point in time.
This makes the page "sticky" when you exit the page and come back to it via the back button.