Facebook Like Box社交插件不适用于Turbolinks [英] Facebook Like Box social plugin doesn't work with Turbolinks

查看:86
本文介绍了Facebook Like Box社交插件不适用于Turbolinks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Like Box社交插件( https://developers .facebook.com/docs/reference/plugins/like-box/),效果很好.

I'm using the Like Box social plugin (https://developers.facebook.com/docs/reference/plugins/like-box/) and it works great.

问题是我正在带有Turbolinks的Rails 4应用程序中使用它.每当我重新加载页面时,都会显示类似的框.如果我单击任何链接,则将加载下一页,并且不会显示赞"框.

Problem is that I'm using it within a Rails 4 application with Turbolinks. Whenever I reload a page, the like box shows up. If I click on any link, the next page loads and the Like Box doesn't show up.

我已经尝试过了,但是没有成功=/

I tried this already but didn't worked =/

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

关于如何解决此问题的任何想法?

Any ideas on how to solve this problem?

推荐答案

您在原始问题中发布的链接非常好.它要求我们创建三个功能:

The link you have posted in original question is quite nice. It asks us to create three functions:

1)saveFacebookRoot:这是必需的,以便以后可以恢复div#fb-root.这被称为page:fetch.当DoM仍在旧页面中时,将调用page:fetch.即:新页面没有替换旧页面

1) saveFacebookRoot: This is needed so that the div#fb-root can be restored at a later point. This is called upon page:fetch. page:fetch is called while the DoM is still of the old page. i.e: new page has not replaced the old page

2)restoreFacebookRoot:需要将div#fb-root附加回页面.在page:change上调用它.当新的DoM可用时,将调用page:change.

2) restoreFacebookRoot: This is needed to that the div#fb-root can be appended back to the page. It is called on page:change. page:change is called when the new DoM is available.

3)那里有小错字.我们需要在page:load

3) There is minor typo in there. We need to call this in page:load

FB.XFBML.parse() // Correct

而不是:

FB?.XFBML.parse() // InCorrect

请记住,第一次重新加载页面时,这三个页面中只有page:change被调用.

Remember that when the page is first reloaded, only the page:change is called out of these three.

这里的窍门是使用全局变量fb_rootfb_events_bound.这些必须在所有其他页面上都可以访问,但这就是为什么我们首先讨厌turbolinks的原因.

The trick here is the use of global variables fb_root and fb_events_bound. These must be accessible in all other pages, but this is the reason why we hate turbolinks in the first place.

参考文献: http://reed.github.io/turbolinks-compatibility/facebook. html

这篇关于Facebook Like Box社交插件不适用于Turbolinks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆