Skip to content

Instantly share code, notes, and snippets.

@p1nox
Last active June 26, 2017 15:40
Show Gist options
  • Save p1nox/4985857 to your computer and use it in GitHub Desktop.
Save p1nox/4985857 to your computer and use it in GitHub Desktop.
Simple Facebook feed dialog facade using facebook-jssdk ( JavaScript or CoffeeScript )
<script type="text/javascript">
// Facebook API loading
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
(function() {
// Global declaration and initialization of DBAsync
var FBAsync;
FBAsync = {
initFBAsync: function() {
return FB.init({
appId: YOUR_FACEBOOK_KEY,
status: true,
cookie: true,
xfbml: true
});
},
openFeedDialog: function(title, link, caption, description, image) {
if (title == null) title = "";
if (link == null) link = "";
if (caption == null) caption = "";
if (description == null) description = "";
if (image == null) image = "";
return FB.getLoginStatus(function(response) {
var scope;
scope = 'popup';
if (response.authResponse) scope = 'dialog';
return FB.ui({
method: 'feed',
name: title,
link: link,
picture: image,
caption: caption,
description: description,
display: scope
});
});
}
};
window.FBAsync = FBAsync;
window.fbAsyncInit = window.FBAsync.initFBAsync;
// Now you can open the feed dialog you whatever you want
FBAsync.openFeedDialog();
}).call(this);
# Global declaration and initialization of DBAsync
FBAsync =
initFBAsync: ->
FB.init
appId : YOUR_FACEBOOK_KEY
status : true
cookie : true
xfbml : true
openFeedDialog: ( title = "", link = "", caption = "", description = "", image = "") ->
FB.getLoginStatus (response) ->
scope = 'popup'
scope = 'dialog' if response.authResponse
FB.ui
method: 'feed'
name: title
link: link
picture: image
caption: caption
description: description
display: scope
window.FBAsync = FBAsync
window.fbAsyncInit = window.FBAsync.initFBAsync
# Now you can open the feed dialog you whatever you want
FBAsync.openFeedDialog()
@harshamv
Copy link

how to add this to work on a click of a button?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment