how to make add this work with turbilinks rails 4

故事扮演 提交于 2019-12-08 08:49:09

问题


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


回答1:


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>


来源:https://stackoverflow.com/questions/20864788/how-to-make-add-this-work-with-turbilinks-rails-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!