Created
January 9, 2011 14:16
-
-
Save tehmaze/771718 to your computer and use it in GitHub Desktop.
MooTools Twitter ticker based on the JSONP protocol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This requires https://gist.github.com/771026 | |
*/ | |
var Ticker = new Class({ | |
Implements: [Options], | |
options: { | |
delay: 5000 | |
}, | |
item: -1, | |
initialize: function(term, element) { | |
this.element = $(element); | |
this.tweet = new Element('span'); | |
this.element.empty(); | |
this.element.adopt(this.tweet); | |
this.twitter = new Request.Twitter(term, { | |
onComplete: this.show.bindWithEvent(this) | |
}); | |
this.twitter.send(); | |
}, | |
show: function(data) { | |
this.tweets = data; | |
// Show first tweet | |
this.rotate(); | |
// Queue periodical ticker updates | |
this.rotate.periodical(this.options.delay, this); | |
}, | |
rotate: function() { | |
this.item += 1; | |
if (this.item > Object.getLength(this.tweets) - 1) this.item = 0; | |
var tweet = new Element('span', {html: this.tweets[this.item].text}).fade('hide'); | |
$(this.tweet).fade('out').get('tween').chain(function() { | |
this.tweet.dispose(); | |
this.tweet = $(tweet); | |
this.element.adopt(this.tweet); | |
this.tweet.fade('in'); | |
}.bind(this)); | |
} | |
}); | |
// Example | |
window.addEvent('domready', function() { | |
new Ticker('tehmaze', 'twitter'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment