Created
June 2, 2011 18:53
-
-
Save pamelafox/1005032 to your computer and use it in GitHub Desktop.
Facebook API + jQuery Autosuggest
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
<!doctype html> | |
<head> | |
<link rel="stylesheet" href="/css/style.css"> | |
<body> | |
<input class="friend-search"></input> | |
<div id="fb-root"></div> | |
<script>window.jQuery || document.write("<script src='/js/libs/jquery-1.5.1.min.js'>\x3C/script>")</script> | |
<script src="/js/jquery.autosuggest.js"></script> | |
<script> | |
window.fbAsyncInit = function() { | |
FB.init({appId: '174062109319467', status: true, cookie: true, xfbml: true}); | |
FB.api('/me/friends', function(response) { | |
var suggestItems = []; | |
for (var i = 0; i < response.data.length; i++) { | |
suggestItems.push({'value': response.data[i].id, | |
'name': response.data[i].name}); | |
} | |
$('.friend-search').each(function() { | |
$(this).autoSuggest(suggestItems, { | |
selectedItemProp: 'name', | |
searchObjProps: 'name', | |
neverSubmit: true, | |
startText: 'Search friends or enter email', | |
}); | |
}); | |
}); | |
}; | |
(function() { | |
var e = document.createElement('script'); | |
e.type = 'text/javascript'; | |
e.src = document.location.protocol + | |
'//connect.facebook.net/en_US/all.js'; | |
e.async = true; | |
document.getElementById('fb-root').appendChild(e); | |
}()); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment