Skip to content

Instantly share code, notes, and snippets.

@sadiqmmm
Forked from Joseph-N/addthis.js
Created September 8, 2017 13:32
Show Gist options
  • Save sadiqmmm/5515a93a160e0a1fae693752b9396dcd to your computer and use it in GitHub Desktop.
Save sadiqmmm/5515a93a160e0a1fae693752b9396dcd to your computer and use it in GitHub Desktop.
How to configure AddThis to work with Turbolinks - Rails 4
// turbolinks addthis
var initAdthis;
initAdthis = function(){
// Remove all global properties set by addthis, otherwise it won't reinitialize
for (var i in window) {
if (/^addthis/.test(i) || /^_at/.test(i)) {
delete window[i];
}
}
window.addthis_share = null;
// Finally, load addthis
$.getScript("http://s7.addthis.com/js/300/addthis_widget.js#pubid=YOUR-PUBLISHER-ID");
}
// Trigger the function on both jquery's ready event and turbolinks page:change event
$(document).on('ready page:change', function() {
initAdthis();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment