Facebook Connect,jQuery UI和jQuery.noConflict() [英] Facebook Connect, jQuery UI, and jQuery.noConflict()

查看:152
本文介绍了Facebook Connect,jQuery UI和jQuery.noConflict()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



不幸的是,Facebook客户端API使用$令牌,这意味着我必须调用jQuery.noConflict()



双重不幸的是,我发现有一些疯狂的原因和作为Rick Strahl指出,jQuery UI不尊重noConlict() 。实际上,如果你看源代码,那就有$ s。



我真的想要能够使用jQuery UI - 具体来说,dialog()组件和draggable也是非常好的 - 但我甚至moreso,我不想手动编辑 - 测试和维护 - 我的自己的jQuery UI的任何部分的副本。



这是一系列牦牛我不得不刮胡乱,这让我在我的智慧结束。有什么建议么?帮助!

您引用的帖子很旧,过时。 jQuery UI的1.0版本在几个文件中出现此问题,并在报告后立即修复。所有的jQuery UI都包含在一个封闭中,它以jQuery的形式传递为$,因此可以使用$内部,而$用于外部的其他东西。



http://docs.jquery.com/Using_jQuery_with_Other_Libraries#Referencing_Magic_-_Shortcuts_for_jQuery


使用以下技术,它允许您使用块$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
$ b

 (function($){
/ *一些代码使用$ * /
})(jQuery)


注意:如果使用这种技术,您仍然可以通过窗口$ eg,窗口$('some_element_id')。引用 $ 之外的任何函数都将调用Prototype,即使从你的闭包内调用。



是为什么你会在jQuery UI文件中看到$,但放心,任何最新版本的jQuery UI(1.5+)都完全支持jQuery.noConflict()


I'm trying to build a page on my personal website that both used jQuery and implements Facebook Connect.

Unfortunately, the Facebook client API uses the $ token, which means I have to call jQuery.noConflict()

Double-unfortunately, I've found out that for some crazy reason and as Rick Strahl points out, jQuery UI doesn't respect noConlict(). At all. In fact, if you look at the source code, there are $s all over it.

I really want to be able to use jQuery UI - specifically, the dialog() component, and draggable would be really nice as well - but I even moreso, I don't want to have to hand-edit - and test, and maintain - my own copy of any part of jQuery UI.

This is the most recent in a series of yaks I've had to shave which has me at my wits' end. Any suggestions? Help!

解决方案

The post you've referenced is quite old and out of date. The 1.0 release of jQuery UI had this issue in a couple of files and was fixed as soon as it was reported. All of jQuery UI is wrapped in a closure that passes in jQuery as $ and therefore can use $ internally while $ is used for something else externally.

From http://docs.jquery.com/Using_jQuery_with_Other_Libraries#Referencing_Magic_-_Shortcuts_for_jQuery

Use the following technique, which allows you to use $ inside of a block of code without permanently overwriting $:

(function($) {
  /* some code that uses $ */
})(jQuery)

Note: If you use this technique, you can still use Prototype via window.$ e.g., window.$('some_element_id'). Any function outside of your closure that references $ will invoke Prototype, even if called from inside your closure.

This is why you'll see $ inside the jQuery UI files, but rest assured, any recent version of jQuery UI (1.5+) is completely supported with jQuery.noConflict()

这篇关于Facebook Connect,jQuery UI和jQuery.noConflict()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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