Skip to content

Instantly share code, notes, and snippets.

@sTiLL-iLL
Last active December 21, 2015 13:48
Show Gist options
  • Save sTiLL-iLL/6314713 to your computer and use it in GitHub Desktop.
Save sTiLL-iLL/6314713 to your computer and use it in GitHub Desktop.
/*
* Options:
* - before (string): HTML code before the tweet.
* - after (string): HTML code after the tweet.
* - tweets (numeric): number of tweets to display.
*
* Example:
*
* <script type="text/javascript" charset="utf-8">
* $(document).ready(function() {
* $('#tweets').tweets({
* tweets:114,
* username: "developer1"
* });
* });
* </script>
*
*/
(function ($) {
$.fn.tweets = function (ops) {
$.ajaxSetup({ cache: true });
var dfs = {
tweets: 5,
before: "<li>",
after: "</li>"
};
var oNd = $.extend(dfs, ops);
return this.each(function () {
var obj = $(this);
$.getJSON('http://api.twitter.com/1/statuses/user_timeline.json?callback=?&screen_name=' +
oNd.username + '&count=' + oNd.tweets,
function (data) {
$.each(data, function (i, t) {
if (t.text !== undefined) {
$(obj).append(oNd.before + t.text + oNd.after);
}
});
}
);
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment