Skip to content

Instantly share code, notes, and snippets.

@fastdivision
Created October 19, 2012 18:23
Show Gist options
  • Save fastdivision/3919803 to your computer and use it in GitHub Desktop.
Save fastdivision/3919803 to your computer and use it in GitHub Desktop.
TweetScroller Snippets
-webkit-mask-image: -webkit-gradient(linear, left 80%, left bottom, from(black), to(rgba(0, 0, 0, 0)));
-webkit-mask-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(0, 0, 0, 0)), color-stop(15%, black), color-stop(85%, black), color-stop(100%, rgba(0, 0, 0, 0)));
defaults =
tweet: '.tweet'
template: '#tweet-template'
username: 'divshot'
count: 50
height: 600
speed: 30 # ms, 30-80 ms recommended, slower = better performance
autoplay: false # CPU intensive
getTweets: ->
$.getJSON "https://api.twitter.com/1/favorites.json?count=#{@options.count}&screen_name=#{@options.username}&callback=?", (data) =>
$(@element).append('<div class="tweetscroller"></div>')
@board = $(@element).find('.tweetscroller')
$.each data, (i, tweet) =>
tweet.created_at = new Date(Date.parse(tweet.created_at))
tweet.created_at = moment(tweet.created_at).format('D MMM YY')
source = $(@options.template).html()
template = Handlebars.compile(source)
@board.append(template(tweet))
@board.masonry
itemSelector: @options.tweet
@_initialTweetCount = @board.find(@options.tweet).length
@scrollTweets()
scrollRefresh: (e) ->
_this = this
if @board.parent()[0].scrollHeight - @board.parent().scrollTop() <= @board.parent().height()
@board.find(@options.tweet).each (i) ->
tweet = $(this).clone()
_this.board.append(tweet).masonry('appended', tweet, true)
if i <= _this.board.find('.tweet').length - _this._initialTweetCount
$(this).remove()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment