Giter Site home page Giter Site logo

Comments (6)

ryw avatar ryw commented on August 16, 2024

Hi @optikfluffel Can you supply sample code? Are you binding a javascript event to the button? Does the button work if you load that page directly, or is the button only broken after getting to the page after a click from a different page?

To help, need to know more precisely what you mean by "Turbolinks stops working".

from turbolinks-classic.

optikfluffel avatar optikfluffel commented on August 16, 2024

Ok sorry, by "Turbolinks stops working" I mean it does whole page reloads after I follow the steps from twitter.com to add a button and add this to my template:

<a href="https://twitter.com/optikfluffel" class="twitter-follow-button" data-show-count="false" data-lang="en">
  Follow @user
</a>
<script>
  ! function (d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (!d.getElementById(id)) {
      js = d.createElement(s);
      js.id = id;
      js.src = "//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js, fjs);
    }
  }(document, "script", "twitter-wjs");
</script>

from turbolinks-classic.

ryw avatar ryw commented on August 16, 2024

So when you click the newly added button the page reloads?

A few ideas...

  1. I think you'd want that button to be opted out of Turbolinks. See https://github.com/rails/turbolinks#opting-out-of-turbolinks.

  2. I don't know exactly what the obfuscated widgets.js Javascript is doing but it does call preventDefault seven times. From the Turbolinks README:

Also, Turbolinks is installed as the last click handler for links. So if you install another handler that calls event.preventDefault(), Turbolinks will not run. This ensures that you can safely use Turbolinks with stuff like data-method, data-remote, or data-confirm from Rails.

from turbolinks-classic.

optikfluffel avatar optikfluffel commented on August 16, 2024

No not the link itself is the problem. If I only inlcude the widget.js it starts reloading everything.

from turbolinks-classic.

reed avatar reed commented on August 16, 2024

Here are two ways you can handle this:

  1. Convert the JS snippet that Twitter provides into a named function, move it into one of your application JS files, and bind it to both the document ready and page:load events. Take a look at #131 for more details on the general premise.
  2. Cut out the middle man. Just put this in the body:
<script src="//platform.twitter.com/widgets.js"></script>

Note that the execution of external script tags within the body was just recently pulled into turbolinks (#88), so the only way you can use the second method is to either wait for the next version (0.5.3) or point your gemfile to the github repo.

from turbolinks-classic.

optikfluffel avatar optikfluffel commented on August 16, 2024

ah OK, Thanks :)

from turbolinks-classic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.