Created
June 30, 2012 12:13
-
-
Save lepture/3023582 to your computer and use it in GitHub Desktop.
social - with seajs
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
define(function(require, exports, module) { | |
function GitHub(user) { | |
this.user = user; | |
} | |
GitHub.prototype.showRepos = function(options) { | |
options = options || {}; | |
var limit = options.limit || 10; | |
var target = options.target || document.getElementById('github-repos'); | |
if (target && target.length) target = target[0]; | |
var html = ''; | |
var url = 'https://api.github.com/users/' + this.user; | |
url += '/repos?sort=updated&callback=define'; | |
require.async(url, function(repos) { | |
repos = repos.data.slice(0, limit); | |
if (options.callback) { | |
options.callback(repos); | |
} else { | |
for(var i = 0; i < repos.length; i++) { | |
var repo = repos[i]; | |
html += '<li><a href="' + repo.html_url + '">' + repo.name; | |
html += '</a><p>' + repo.description + '</p></li>'; | |
} | |
target.innerHTML = html; | |
} | |
}); | |
} | |
var github = function(user) { | |
return new GitHub(user); | |
} | |
module.exports = github; | |
}); |
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
define(function(require, exports, module) { | |
function Twitter(user) { | |
this.user = user; | |
} | |
Twitter.prototype.showTweets = function(options) { | |
options = options || {}; | |
var limit = options.limit || 10; | |
var target = options.target || document.getElementById('tweets'); | |
if (target && target.length) target = target[0]; | |
var html = ''; | |
var url = 'https://api.twitter.com/1/statuses/user_timeline/'; | |
url += this.user + '.json?count=' + limit + '&callback=define'; | |
require.async(url, function(tweets) { | |
if (options.callback) { | |
options.callback(tweets); | |
} else { | |
for(var i = 0; i < tweets.length; i++) { | |
var tweet = tweets[i]; | |
html += '<li><p>' + tweet.text + '</p></li>'; | |
} | |
target.innerHTML = html; | |
} | |
}); | |
} | |
var twitter = function(user) { | |
return new Twitter(user); | |
} | |
module.exports = twitter; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment