Skip to content

Instantly share code, notes, and snippets.

@chrisyour
Created January 10, 2014 07:29
Show Gist options
  • Save chrisyour/8348202 to your computer and use it in GitHub Desktop.
Save chrisyour/8348202 to your computer and use it in GitHub Desktop.
CoffeeScript to load Twitter's twitter-wjs JavaScript. Tip: Any link that goes to an intent URL (like http://twitter.com/intent/tweet) acts like a Twitter button with all the Widget-wjs functionality with events, so you can customize the look of your button without having to use the Twitter generated iFrame buttons.
# Load Twitter Widgets
window.twttr = ((d, s, id) ->
js = undefined
fjs = d.getElementsByTagName(s)[0]
unless d.getElementById(id)
js = d.createElement(s)
js.id = id
js.src = "//platform.twitter.com/widgets.js"
fjs.parentNode.insertBefore js, fjs
window.twttr || t = { _e: [], ready: (f)-> t._e.push(f) }
) document, "script", "twitter-wjs"
# Twitter Ready
twttr.ready((twttr)->
# Twitter Events
# Event: Tweet
twttr.events.bind 'tweet', (event) ->
alert "Twitter tweet just happened!"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment