Created
April 1, 2014 23:45
-
-
Save jonathanconway/9925286 to your computer and use it in GitHub Desktop.
Reload (or initialize) addThis social share buttons. Useful when implementing addThis in a SPA (Single Page Application).
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
// Reload (or initialize) addThis social share buttons. | |
// IMPORTANT: make sure you put in a correct pubid on line 7. | |
window.addthis_reload = function () { | |
if (!window.addthis) { | |
// Load addThis, if it hasn't already been loaded. | |
window['addthis_config'] = { 'data_track_addressbar' : false }; | |
$('body').append('<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid={YOUR PUBID HERE}"></script>'); | |
} else { | |
// Already loaded? Then re-attach it to the newly rendered set of social icons. | |
// And reset share url/title, so they don't carry-over from the previous page. | |
window['addthis_share'].url = window.location.href; | |
window['addthis_share'].title = window.document.title; | |
window.addthis.toolbox('.addthis_toolbox'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace the Jquery append with Vanilla JS if you are not using Jquery