Skip to content

Instantly share code, notes, and snippets.

@LucienLee
Created January 26, 2013 05:41
Show Gist options
  • Save LucienLee/4640423 to your computer and use it in GitHub Desktop.
Save LucienLee/4640423 to your computer and use it in GitHub Desktop.
function appendFb( data, userID ){
var frag = document.createDocumentFragment();
var times = 0;
for (var i = 0, max = 40; i < max ; i++) {
var friend = data[i];
$.ajax({
url: 'https://graph.facebook.com/fql?q=SELECT friend_count FROM user WHERE uid='+ friend.id,
error: function( error ){
var markup = document.createElement('li');
// markup.innerHTML = '<img src="http://graph.facebook.com/' + friend.id + '/picture"> ' + friend.name + '<br>';
var a = document.createElement('a');
a.href = '/set/'+userID+'/'+friend.id+'/'+friend.name+'/'+FB.getAccessToken();
var count_friend = JSON.parse(error.responseText).data[0].friend_count;
console.log(count_friend);
a.innerHTML='<img src="http://graph.facebook.com/' + friend.id + '/picture?width=100&height=100"><h3>' + friend.name+ '</h3><p>'+ count_friend +'</p>';
markup.appendChild(a);
frag.appendChild(markup);
console.log("after frag append");
times++;
console.log(times);
insertdom( frag, times );
}
})
}
function insertdom(frag, times){
if (times == 20) {
document.getElementById('user-friends').appendChild( frag );
$('#user-friends').listview('refresh');
$.mobile.loading( 'hide' );
}
else
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment