简体   繁体   English

应用程序范围内的jQuery脚本

[英]application-wide jquery script

I use some Facebook JS scripts for user authentification, etc. I want to place them in the properly unobtrusive way as application-wide scripts. 我使用一些Facebook JS脚本进行用户身份验证等。我想将它们作为适当的脚本放置在应用程序级脚本中。

Currently I have the script as a partial and call it from my application header: 当前,我将脚本作为部分脚本,并从我的应用程序标头中调用它:

<%# render 'layouts/facebook_app_scripts' %>

The script works but is extremely obtrusive. 该脚本可以运行,但是非常麻烦。 I want to make it unobtrusive. 我想使其不引人注目。 This is especially important since I tap into all sorts of APIs and it's getting messy. 这一点特别重要,因为我接触了各种API,而且变得一团糟。

You don't need to see it in its entirety (if you need to see the script to answer this question, I don't think you'll be any help as this is a general question not script-specific) 您不需要完整地查看它(如果您需要查看脚本来回答这个问题,我认为您不会有任何帮助,因为这是一个通用问题,而不是特定于脚本的)

You should know that it contains dynamically created links such as this one: 您应该知道它包含动态创建的链接,例如:

window.top.location = "<%= Facebook::SITE_URL.to_s %>/logout";

That means that putting this in a .js file in the assets/javascript folder isn't going to work, since .js files can't access rails-generated variables. 这意味着将其放在assets / javascript文件夹中的.js文件中是行不通的,因为.js文件无法访问rails生成的变量。

So how can I shift my javascript with dynamically-generated links from the rails view to an unobtrusive javascript file? 那么,如何将具有动态生成的链接的JavaScript从Rails视图转移到不引人注目的JavaScript文件?

看一下这个项目 ,将所有Facebook JS SDK都包含在内

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM