Skip to content

Instantly share code, notes, and snippets.

@alexdunae
Last active August 29, 2015 14:12
Show Gist options
  • Save alexdunae/8e59342f11178d610c76 to your computer and use it in GitHub Desktop.
Save alexdunae/8e59342f11178d610c76 to your computer and use it in GitHub Desktop.
fb-share
initFacebook: ->
facebookLoaded = false
openShareDialog = (url) ->
FB.ui {method: 'feed', link: url}
window.fbAsyncInit = ->
facebookLoaded = true
FB.init({
appId : 'XXXXXXXXXXXXXXX',
status : false,
xfbml : false
})
openShareDialog()
$('a.facebook-share[href]').on 'click', (e) ->
link = $(this)
url = link.attr('href')
if !facebookLoaded
$.getScript '//connect.facebook.net/en_US/all.js'
else
openShareDialog(url)
e.preventDefault()
false
initTwitterIntents: ->
return if (window.__twitterIntentHandler)
$('a.twitter-intent[href]').on 'click', (e) ->
# from https://dev.twitter.com/docs/intents (Limited Dependencies)
windowOptions = 'scrollbars=yes,resizable=yes,toolbar=no,location=yes'
width = 550
height = 420
winHeight = screen.height
winWidth = screen.width
left = Math.round((winWidth / 2) - (width / 2))
top = 0
if (winHeight > height)
top = Math.round((winHeight / 2) - (height / 2))
window.open this.href, 'intent', windowOptions +
',width=' + width +
',height=' + height +
',left=' + left +
',top=' + top
e.returnValue = false
e.preventDefault && e.preventDefault()
false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment