Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SharedCount = Object.create(HTMLSpanElement.prototype)
PROVIDERS =
facebook:
url: (url) -> "http://graph.facebook.com/#{url}"
counter_field: 'share.share_count'
twitter:
url: (url) -> "http://opensharecount.com/count.json?url=#{url}"
counter_field: 'count'
SharedCount.createdCallback = ->
provider = PROVIDERS[@getAttribute('provider')]
url = provider.url(@getAttribute('url'))
$.ajax
url: url
cache: false
dataType: 'json'
success: (json) =>
keys = provider.counter_field.split('.')
value = json
for key in keys
value = value[key] if value
@textContent = value || 0
document.registerElement 'shared-count',
prototype: SharedCount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.