Skip to content

Instantly share code, notes, and snippets.

Last active Apr 25, 2018
What would you like to do?
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
// Trigger the function on both jquery's ready event and turbolinks page:change event
$(document).on('ready page:change', function() {
Copy link

senott commented Oct 2, 2015

Thanks, man!

Copy link

ChrisEstanol commented Feb 18, 2016

Thanks for the workaround.

Copy link

trantorLiu commented Jan 21, 2017

It works. But when page loads, some error occur:

Uncaught ReferenceError: _atr is not defined
    at addthis_widget.js?_=1484985323526:2
Uncaught ReferenceError: addthis is not defined
    at _handleScroll (addthis_widget.js?_=1484985323526:2)

Copy link

nhinze commented Mar 23, 2017

I'm having the same problem. First I changed:

$(document).on('ready page:change', function() {


$(document).on('page:change', function() {

otherwise initAdthis is called twice on first page load.

However, the _atr is not defined error multiplies as I browse through the website. I think AddThis adds an event that needs to be removed before page:change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment