Created
May 18, 2011 22:19
-
-
Save mwawrusch/979725 to your computer and use it in GitHub Desktop.
Coffeescript implementation of a twitter jquery plugin compiled version
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
/* DO NOT MODIFY. This file was compiled Wed, 18 May 2011 11:49:14 GMT from | |
* /Users/mwawrusch/Documents/triponadeal/app/scripts/jquery.recent-tweets.coffee | |
*/ | |
(function() { | |
var $; | |
$ = jQuery; | |
$.fn.extend({ | |
recentTweets: function(options) { | |
var opts, self; | |
self = $.fn.recentTweets; | |
opts = $.extend({}, self.default_options, options); | |
return this.each(function(i, el) { | |
self.init(el, opts); | |
if (opts.log) { | |
return self.log(el); | |
} | |
}); | |
} | |
}); | |
$.extend($.fn.recentTweets, { | |
default_options: { | |
userName: "martin_sunset", | |
numTweets: 10, | |
loaderText: "Loading tweets...", | |
tweetContentArea: ".recent_tweets", | |
animationSpeed: "slow", | |
cycleInterval: 10000, | |
log: false | |
}, | |
init: function(el, opts) { | |
var $content, url; | |
$content = $(el).find(opts.tweetContentArea); | |
$content.text(opts.loaderText); | |
url = "http://twitter.com/status/user_timeline/" + opts.userName + ".json?count=" + opts.numTweets + "&callback=?"; | |
return $.getJSON(url, function(data) { | |
var $text, counter, tweets; | |
tweets = []; | |
$.each(data, function(i, post) { | |
var txt; | |
txt = post.text; | |
txt = txt.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g, function(url) { | |
return url.link(url); | |
}); | |
txt = txt.replace(/[@]+[A-Za-z0-9-_]+/g, function(u) { | |
return u.link("http://twitter.com/" + (u.replace('@', ''))); | |
}); | |
txt = txt.replace(/[#]+[A-Za-z0-9-_]+/g, function(t) { | |
return t.link("http://search.twitter.com/search?q=" + (t.replace('#', '%23'))); | |
}); | |
return tweets.push("<span>" + txt + "</span>"); | |
}); | |
if (tweets.length === 0) { | |
return $content.text("No tweets available"); | |
} else { | |
counter = 0; | |
$text = $(tweets[counter]).hide(); | |
$content.html($text); | |
$text.fadeIn(opts.animationSpeed); | |
return setInterval((function() { | |
counter++; | |
if (counter >= tweets.length) { | |
counter = 0; | |
} | |
return $content.children().fadeOut(opts.animationSpeed, function() { | |
$content.empty(); | |
$text = $(tweets[counter]).hide(); | |
$content.html($text); | |
return $text.fadeIn(opts.animationSpeed); | |
}); | |
}), opts.cycleInterval); | |
} | |
}); | |
}, | |
log: function(msg) { | |
if ((typeof console !== "undefined" && console !== null) && (console.log != null)) { | |
return console.log(msg); | |
} | |
} | |
}); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment