Make jQuery compatible with other libraries

kkaefer - August 25, 2007 - 11:31
Project:Drupal
Version:7.x-dev
Component:javascript
Category:bug report
Priority:normal
Assigned:Unassigned
Status:duplicate
Description

Currently, we rely on jQuery being mapped to $, however, we should not force users to use jQuery. Therefore, we should add a noConflict call and convert all instances of $ to jQuery.

#1

Gábor Hojtsy - August 25, 2007 - 12:30

This seems to be a very big change so late in the release cycle IMHO. It is quite disturbing for the current modules using jQuery.

#2

kkaefer - August 25, 2007 - 12:51
Status:active» needs review

How many 6.x modules with js files are ported for 6 already? Besides, it is very easy to make a JS file compatible with jQuery.noConflict(): You just have to wrap the entire file in a inline function call and pass it jQuery as parameter to map it to $. See the attached patch for further information.

AttachmentSize
jquery-noconflict.patch 33.75 KB

#3

momendo - August 25, 2007 - 14:34

I can see the benefit of other Javascript libraries like Prototype and Mootools benefiting. Since other libraries use $$ or $ object, this moves Drupal's jQuery out of the way. But if the user already has jQuery scripts for their existing sites, their JS code will break due to the missing $ mapping. They'll have to remap it globally. Also, just because remapping to jQuery doesn't guarantee it will fix OTHER JS libraries that make use of $/$$. This is a silly but plausible question, what if I choose to use Prototype and Mootools and jQuery at the same time?

#4

dvessel - August 26, 2007 - 03:28

Looks like 1.1.4 provides just this and more.

http://jquery.com/blog/2007/08/24/jquery-114-faster-more-tests-ready-for...

I'd roll a patch myself but I can't invest the time.

#5

nevets - August 26, 2007 - 04:13

I personally disagree with this request. My understanding was that a choice was made to pick a javascript library as the standard one used by Drupal and jQuery was picked. Having a consistent library makes it easier to had javascript/ajax functionality often with little code. As things now stand jQuery is the standard library used by Drupal making it easy to use other jQuery scripts for use on ones site. This seems like a step backwards to me.

#6

profix898 - August 26, 2007 - 08:52

I'd love to keep the simple/short $, but I also see the benefits of this patch. (subscribing)

#7

dvessel - August 28, 2007 - 04:20

Another issue created here:

http://drupal.org/node/170224

Uses jQuery 1.1.4 and basically solves this same issue.

#8

nedjo - September 5, 2007 - 00:46
Status:needs review» duplicate

The issue dvessel pointed to was committed, so apparently this is now fixed.

#9

kkaefer - September 5, 2007 - 18:22
Status:duplicate» needs review

It does not sole the issue at all. jQuery 1.1.4 just has better support for supporting other libraries. We still need to wrap Drupal’s JS files in a separate namespace where we map $ to jQuery.

#10

dvessel - September 5, 2007 - 18:46

Yup, the issue title was changed. Ended up just drop in 1.1.4.

#11

nedjo - September 5, 2007 - 20:05

Thanks for reopening this, apologies, I should have read the other issue more carefully.

I'm not sure if this counts as something to apply post-freeze. Is it bug, or a feature request?

In any case it is indeed a useful patch and simple and painless change for us as contrib module maintainers.

#12

Gábor Hojtsy - September 6, 2007 - 11:36
Version:6.x-dev» 7.x-dev

We are not making such API changes this late in the cycle IMHO. Postponed.

#13

catch - February 14, 2008 - 10:04
Status:needs review» duplicate

Duplicate: http://drupal.org/node/125030

 
 

Drupal is a registered trademark of Dries Buytaert.