Giter Site home page Giter Site logo

Comments (9)

dhh avatar dhh commented on August 16, 2024

I'm not sure it makes sense since there's no fetching phase that takes any time. It's yanked immediately from cache.

What are you trying to use it for?

from turbolinks-classic.

pomartel avatar pomartel commented on August 16, 2024

It's regarding the load of Facebook JS SDK. The SDK creates an iframe that is used to communicate with Facebook. To keep that iframe in between requests, I have to do something like this :

fetchingPage = ->
  fb_root = $('#fb-root').detach()

pageChanged = ->
  $('#fb-root').replaceWith fb_root

The fetchingPage method would need to be called whenever a page change is triggered (from cache or from the server). This would make things more consistent I guess since page:change is always called no matter if it's fresh or from cache.

from turbolinks-classic.

dhh avatar dhh commented on August 16, 2024

Are you sure you still need to do that if we solve #62?

from turbolinks-classic.

dhh avatar dhh commented on August 16, 2024

Sorry, #61.

from turbolinks-classic.

pomartel avatar pomartel commented on August 16, 2024

Ok, I understand what's going on. I detach the fb-root div before the page is cached. When it is fetched for cache, that div doesn't exist anymore in the DOM so the replaceWith call doesn't work. I found a work-around that does not require page:fetch to be called when the page is cached. Thanks for your help!

from turbolinks-classic.

m4n avatar m4n commented on August 16, 2024

I found a work-around that does not require page:fetch to be called when the page is cached.

@pomartel I am experiencing the same problem with the fb-root div. Would you mind sharing your specific work-around with the rest of us?

from turbolinks-classic.

pomartel avatar pomartel commented on August 16, 2024

@m4n, here is essentially my solution. It's been working on my production site for over a month without any glitch. Don't hesitate to drop me a line if you have any question.

fb_root = null #variable use to transfer the state of the fb-root div tag between page requests

$ ->
  load_facebook_sdk()
  $(document)
    .on('page:fetch', fetching_page)
    .on('page:change', page_changed)

fetching_page = ->
  $("body").addClass("wait")
  fb_root = $('#fb-root').detach()

page_changed = ->
  if $('#fb-root').length > 0
    $('#fb-root').replaceWith fb_root
  else
    $('body').append fb_root
  $("body").removeClass("wait")
  facebook_sdk_loaded()

load_facebook_sdk = ->
  window.fbAsyncInit = initialize_facebook_sdk
  $.getScript(document.location.protocol + "//connect.facebook.net/#{$('#fb-root').data('locale')}/all.js")

initialize_facebook_sdk = ->
  FB.init
    appId      : $('#fb-root').data('app-id')
    channelUrl : $('#fb-root').data('channel-url')
    status     : true
    cookie     : true
    xfbml      : true
  FB.Canvas.setAutoGrow()
  facebook_sdk_loaded()

facebook_sdk_loaded = ->
  $(document).trigger("fb:initialized")
  @scroll_top(150)

from turbolinks-classic.

kwantopia avatar kwantopia commented on August 16, 2024

@pomartel where do you put this coffee script and what do you have in your view?

from turbolinks-classic.

pomartel avatar pomartel commented on August 16, 2024

@kwantopia More information on the topic here : http://reed.github.io/turbolinks-compatibility/facebook.html

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.