Skip to content

Instantly share code, notes, and snippets.

@danjesus
Last active December 16, 2015 08:19
Show Gist options
  • Save danjesus/5404966 to your computer and use it in GitHub Desktop.
Save danjesus/5404966 to your computer and use it in GitHub Desktop.
Facebook share
/**
* Referências caso necessário
* http://copacocacola.terra.com.br/infografico/dribles/info-dribles/js/info.js
*/
var facebook = (function() {
var share =function(data, type) {
type = type ? type : 'feed';
FB.ui({
method: type,
message: data.message,
name: data.title,
picture: data.image,
description: data.content,
link: data.url,
actions: [{
name: data.title,
link: data.url
}],
user_message_prompt: data.title
},
function(response) {
// cat your reponse
});
},
getFriends = function() {
// get all friends
FB.api('me/friends', {fields: 'username, name, id, first_name'}, function(friends) {
var friends_list = friends.data;
var total = friends_list.length;
var html = "";
var fb_f = getPhoto;
// substituir por template handlebars
for(var i = 0; i < total; i++) {
html += "<a href='#' class='select-friend' data-id='"+
friends_list[i].id +"' data-pos='" + i + "'" +
"data-name='" + friends_list[i].first_name +
"' ><img src='" +
fb_f(friends_list[i].id) +
"' title='" + friends_list[i].name +
"'/> <br> " + friends_list[i].first_name +" <span class='select-friend-mask'> </span> </a>";
}
// codigo do scrollbar
$('.box-select-friends').html(html).mCustomScrollbar();
setTimeout(function() {
$('.box-select-friends').mCustomScrollbar("update");
}, 2000);
});
},
getPhoto = function(id, w, h) {
if (w && h) {
return 'https://graph.facebook.com/' + id + '/picture?width=' + w + '&height=' + h;
}
return 'https://graph.facebook.com/' + id + '/picture';
};
return {
share: share,
getFriends: getFriends,
getPhoto: getPhoto
};
})();
<script>
$(function() {
$('.share-button').on('click', function(e) {
e.preventDefault();
var $self = $(this),
data = {
title : $self.data('title'),
url : 'http://garoto.com.br/pascoagaroto',
content : $self.data('content')
image : 'image url'
};
facebook.share(data);
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment