Created
November 17, 2015 16:13
-
-
Save mrdoinel/489b1637404d40b7049b to your computer and use it in GitHub Desktop.
Get all shares for the current page using addthis shares.json endpoint
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
A17.Behaviors.sharing_counter = function() { | |
var url = document.querySelector("link[rel='canonical']").href; | |
if(url) { | |
var script = document.createElement('script'); | |
script.src = '//api-public.addthis.com/url/shares.json?url=' + url + '&callback=A17%2EHelpers%2Eupdate_counters'; | |
document.getElementsByTagName('head')[0].appendChild(script); | |
} | |
}; | |
A17.Helpers.update_counters = function(data) { | |
if(data) { | |
shares = data.shares; | |
if(shares > 0) { | |
var counters = document.querySelectorAll('[data-sharing-counter]'); | |
if(counters) { | |
[].forEach.call(counters, function(counter) { | |
counter.innerText = shares + " Shares"; | |
}); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment