Last active
June 26, 2017 15:40
-
-
Save p1nox/4985857 to your computer and use it in GitHub Desktop.
Simple Facebook feed dialog facade using facebook-jssdk ( JavaScript or CoffeeScript )
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
<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> |
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
(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); |
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
# 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to add this to work on a click of a button?