Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Sharethis implementation and Turbolinks' incompatibility #79

Open
bcunha42 opened this issue May 19, 2017 · 3 comments
Open

New Sharethis implementation and Turbolinks' incompatibility #79

bcunha42 opened this issue May 19, 2017 · 3 comments

Comments

@bcunha42
Copy link

The official implementation of Sharethis, described in URL below, is deprecated.
http://reed.github.io/turbolinks-compatibility/sharethis.html

The new one is something like this:
<script type="text/javascript" src="//platform-api.sharethis.com/js/sharethis.js#property=[YOUR-PROPERTY-CODE]&product=sticky-share-buttons"></script>

How can I set this new one compatible with turbolinks?

@amenon
Copy link

amenon commented Oct 15, 2017

The new sharethis implementation does not have an official JS API. I was able to reinitialize the share buttons on new pages, by calling the library's init method after turbolinks loads the page:

    document.addEventListener("turbolinks:load", function () {
        // Note: This is undocumented API for the sharethis widget. Reload the widget when we
        // visit a new page after a turbolinks load event.
        if (__sharethis__ && __sharethis__.config) {
            __sharethis__.init(__sharethis__.config);
        }
    })

@mubbashar
Copy link

thanks for the code

@ycrepeau
Copy link

ycrepeau commented Feb 13, 2018

Well, the butons show up and that great BUT...

The current url is not properly updated. If I click Twitter (or any other) button, the Twitter page will open but the embeded URL is the one stored when the code has loaded (usually the home page) not the current page location.

UPDATE:

Just update the sharethis.href BEFORE calling sharethis.init

So:

   document.addEventListener("turbolinks:load", function () {
        // Note: This is undocumented API for the sharethis widget. Reload the widget when we
        // visit a new page after a turbolinks load event.
        if (__sharethis__ && __sharethis__.config) {
           __sharethis__.href = document.location.href 
           __sharethis__.init(__sharethis__.config);
        }
    })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants