Question

I have been working on this for almost a day now and cant figure out how to make addthis work wtih turbolinks and rails 4. my add this code is

<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js"></script>
<script type="text/javascript">
    addthis.layers({
        'theme' : 'transparent',
        'share' : {
            'position' : 'left',
            'numPreferredServices' : 6
        },
        'follow' : {
            'services' : [
                {'service': 'facebook', 'id': 'blanckdigital'},
                {'service': 'twitter', 'id': 'blanckdigital'}
            ]
        },
        'whatsnext' : {},
        'recommended' : {}
    });
</script>
<!-- AddThis Smart Layers END -->

How can i make it compatible with turbolinks so that it appears on every page without doing a page reload or disabling turbolinks

Was it helpful?

Solution

i finally got it to work with this

<script type="text/javascript">$(document).ready(function() {
    var script = 'http://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-xxx';
    if (window.addthis){
        window.addthis = null;
        window._adr = null;
        window._atc = null;
        window._atd = null;
        window._ate = null;
        window._atr = null;
        window._atw = null;
    }
    $.getScript( script, function() {
        addthis.layers({
            'theme' : 'transparent',
            'share' : {
                'position' : 'left',
                'numPreferredServices' : 6
            },
            'follow' : {
                'services' : [
                    {'service': 'facebook', 'id': 'blanckdigital'},
                    {'service': 'twitter', 'id': 'blanckdigital'}
                ]
            },
            'whatsnext' : {},
            'recommended' : {}
        });
    });
});
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top