Skip to content

Instantly share code, notes, and snippets.

@tehmaze
Created January 9, 2011 14:16
Show Gist options
  • Save tehmaze/771718 to your computer and use it in GitHub Desktop.
Save tehmaze/771718 to your computer and use it in GitHub Desktop.
MooTools Twitter ticker based on the JSONP protocol
/*
* 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