Comments (9)
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.
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.
Are you sure you still need to do that if we solve #62?
from turbolinks-classic.
Sorry, #61.
from turbolinks-classic.
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.
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.
@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.
@pomartel where do you put this coffee script and what do you have in your view?
from turbolinks-classic.
@kwantopia More information on the topic here : http://reed.github.io/turbolinks-compatibility/facebook.html
from turbolinks-classic.
Related Issues (20)
- Page does not always scroll to the top when DOM loads too fast
- SVG anchors not working with turbolinks
- Turbolinks.visit, partial replacement & relative urls (& IE11)
- Not correctly inferring protocol with SSL, unless force_ssl is set HOT 2
- Redirect and reload full page HOT 1
- JavaScript part of turbolinks on npm HOT 11
- Enable Turbolinks on a-tags after adding content over AJAX HOT 1
- File type blacklist instead of whitelist
- Scroll position of data-turbolinks-permanent elements lost on navigation. HOT 3
- Webpage without title, after turbolink has title of undefined HOT 1
- Problems with JS HOT 1
- Rails 5 deprecations
- Would you please tell me how to add your library or whether it's necessary to add this library?
- Sorry for duplicate
- Progress bar causing capybara tests to fail
- Documentation does not explain how to install current turbolinks-classic version HOT 1
- temporary inside permanent
- Clicking browser back button from an error page to a non-error page, retains the styles of the error page
- Turbolinks.enableProgressBar() returns undefined
- How to binding "page:load" cache-preview
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from turbolinks-classic.