Skip to content

Instantly share code, notes, and snippets.

@jiggliemon
Created September 21, 2011 08:16
Show Gist options
  • Save jiggliemon/1231540 to your computer and use it in GitHub Desktop.
Save jiggliemon/1231540 to your computer and use it in GitHub Desktop.
sml.adapter.jquery.Facebook.share = function(options) {
options = options || {};
/*
* All this ugliness went down because facebook
* dropped their 'attachment' property in their SDK
*/
var attachment = options.attachment = options.attachment || {};
var share = {
caption:"{{ facebook_page_name }}",
method: options.method || 'feed',
action_links: options.action_links,
target_id: options.target_id,
actor_id: options.actor_id,
auto_publish: options.auto_publish,
user_message_prompt: options.user_message_prompt
};
if(attachment.name)
share.name = options.name || attachment.name;
if(attachment.description)
share.description = options.description || attachment.description;
if(attachment.href)
share.link = options.link || attachment.href
if(attachment.media && attachment.media.length > 0){
var media = attachment.media[0];
if(media.type === 'image' && media.src)
share.picture = media.src;
}
if(options.picture)
share.picture = options.picture
FB.ui(share, function(response) {
if (response && response.post_id) {
options.success && options.success( response.post_id );
} else {
options.error && options.error();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment