Giter Site home page Giter Site logo

Comments (14)

pomartel avatar pomartel commented on July 17, 2024 1

Wouldn't it also be helpful to have a before-change event like there is in pjax? This way I could put the FB tags in a variable and reinject them when the page:change event is triggered. Not yet sure this is the best way to proceed it would add some flexibility.

from turbolinks-classic.

ZiaMM avatar ZiaMM commented on July 17, 2024 1

I've tried all these and more (fb and twitter). They do nothing until I reload the page - then they show up. How to make them fire without a page-reload?

from turbolinks-classic.

Tashows avatar Tashows commented on July 17, 2024 1

For anyone using the new turbolinks gem see this issue

from turbolinks-classic.

dhh avatar dhh commented on July 17, 2024

There's a page:change event being thrown when turbo links changes the page. You can use that to refire any hooks you might need.

On Sep 27, 2012, at 8:55 AM, Pierre Olivier Martel [email protected] wrote:

This is not really a Turbolinks issue but a problem I guess many will run into using the Facebook JS SDK. The SDK is initiliazed inside the HTML body like this: https://developers.facebook.com/docs/reference/javascript/

When the SDK initializes, it creates a fb-root iframe tag to communicate with the FB API. When Turbolinks reloads the page, the fb-root tag vanishes and there doesn't seem to be a way trigger the re-initilialization of the Facebook sdk.

I'm trying to figure out the best way to handle this. Can an element of the body remain in between two requests? How can inline javascript be executed? (Let me know I should repost to Stack Overflow instead)


Reply to this email directly or view it on GitHub.

from turbolinks-classic.

dhh avatar dhh commented on July 17, 2024

Yeah, I could see something like that. We've thought about page:changing and page:changed.

On Sep 27, 2012, at 9:25 AM, Pierre Olivier Martel wrote:

Wouldn't it also be helpful to have a before-change event like there is in pjax? This way I could put the FB tags in a variable and reinject them when the page:change event is triggered. Not yet sure this is the best way to proceed it would add some flexibility.


Reply to this email directly or view it on GitHub.

David Heinemeier Hansson

from turbolinks-classic.

houen avatar houen commented on July 17, 2024

This page has a good solution that I am using: http://www.blackfishweb.com/blog/asynchronously-loading-twitter-google-facebook-and-linkedin-buttons-and-widgets-ajax-bonus

from turbolinks-classic.

houen avatar houen commented on July 17, 2024

Might as well post it as well:

if (typeof (FB) != 'undefined') {
    FB.init({ status: true, cookie: true, xfbml: true });
}
else {
    $.getScript("http://connect.facebook.net/en_US/all.js#xfbml=1", function () {
        FB.init({ status: true, cookie: true, xfbml: true });
    });
}

from turbolinks-classic.

eugenemiretsky avatar eugenemiretsky commented on July 17, 2024

So basically you have to reload the FB SDK on every page load? One of the reasons why i wanted to use turbolinks was to save the time it takes to initialize it.

from turbolinks-classic.

reed avatar reed commented on July 17, 2024

@eugenemiretsky does this work for you?

reednj77.github.com/turbolinks-compatibility/facebook.html

from turbolinks-classic.

rceee avatar rceee commented on July 17, 2024

@reednj77 Hey, that link didn't work, but I'd really like to see what you've got.

from turbolinks-classic.

reed avatar reed commented on July 17, 2024

Sorry, I messed up the markup. Try this:

reed.github.com/turbolinks-compatibility/facebook.html

from turbolinks-classic.

rceee avatar rceee commented on July 17, 2024

Thanks, I appreciate it!

from turbolinks-classic.

evie404 avatar evie404 commented on July 17, 2024

should replace the link to:

http://reed.github.com/turbolinks-compatibility/facebook.html

from turbolinks-classic.

besi avatar besi commented on July 17, 2024

I was able to resolve the issue like so:

Add the jquery-turbolinks gem to your Gemfile:

# See http://stackoverflow.com/a/18834209/784318
gem 'jquery-turbolinks'

Now all jQuery document reaady callbacks will be called in case of a turbo-link click event.

# /application/_facebook_init.html.slim
coffee:
   # This line below is crucial because otherwise this code won't be reached in case of a turbo-link click
  $ ->
    ((d, s, id) ->
      js = undefined
      fjs = d.getElementsByTagName(s)[0]
      if d.getElementById(id)
        return
      js = d.createElement(s)
      js.id = id
      js.src = '//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=[SOME_APP_ID]&version=v2.0'
      fjs.parentNode.insertBefore js, fjs
      return) document, 'script', 'facebook-jssdk'

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.