Skip to content

Instantly share code, notes, and snippets.

@franzenzenhofer
Created March 25, 2015 12:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franzenzenhofer/871d36a52da35a965d49 to your computer and use it in GitHub Desktop.
Save franzenzenhofer/871d36a52da35a965d49 to your computer and use it in GitHub Desktop.
_DEBUG_ = false
dlog = (m) -> console.log(m) if _DEBUG_
getFacebook = (u, cb) ->
jQuery.getJSON(
'http://api.facebook.com/restserver.php',
{
format:'json'
method:'links.getStats'
urls: u
},
(d) ->
cb({
increment: d[0].total_count
facebook: d[0].total_count
})
)
getTwitter = (u, cb) ->
jQuery.getJSON(
'http://urls.api.twitter.com/1/urls/count.json?callback=?',
{
url: u
},
(d) ->
cb({
increment: d.count
twitter: d.count
})
)
#https://api.pinterest.com/v1/urls/count.json?callback=
getPinterest = (u, cb) ->
jQuery.getJSON(
'https://api.pinterest.com/v1/urls/count.json?callback=?',
{
url: u
},
(d) ->
cb({
increment: d.count
pinterest: d.count
})
)
#https://www.linkedin.com/countserv/count/share?url=http://www.codedevelopr.com&callback=a
getLinkedin = (u, cb) ->
jQuery.getJSON(
'https://www.linkedin.com/countserv/count/share?callback=?',
{
url: u
},
(d) ->
cb({
increment: d.count
linkedin: d.count
})
)
$.fn.socialProof = (u = window.top.location.href, elem, s="", custom_cb = dlog) ->
if elem and $(elem).length > 0
cb = (d) ->
count = parseInt("0"+$(elem).text(), 10)
new_count = (count+parseInt(d.increment, 10))
if new_count? and new_count isnt 0 and !isNaN(new_count)
$(elem).each((index) ->
$(@).html($.trim(new_count+" "+s))
)
if custom_cb?
custom_cb(d)
else
cb = custom_cb
if cb?
getFacebook(u, cb)
getTwitter(u, cb)
getPinterest(u, cb)
getLinkedin(u, cb)
return @
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment