There is a Javascript error using Admin and CiviCRM I can't track down.

Error: $.cookie is not a function
Source File: http://local.halldale.tiger-dev.co.uk/sites/all/modules/admin/includes/a...
Line: 140

Comments

yhahn’s picture

Status: Active » Postponed (maintainer needs more info)
Paul Lomax’s picture

It could well be something similar, jquery.js is included twice, once from civicrm and once from Drupal. The Drupal version is 1.2.6 and the Civi version is 1.3.2.

If you remove the Civi entry then a lot of Civi functions stop working.

jalneal’s picture

I'm getting the same problem on every single site I have set up lately. First time I got the message was on an Openpublish site installed with no other modules, which is suprising because I couldn't find the problem and nobody could recreate it that tried on the Openpublish project. I recently installed admin on two other Drupal installations. Both had CiviCRM, but I disabled all modules so it was just admin and the rubik theme (CiviCRM disabled).

With Admin enabled, all jquery broke (Rubik has vertical tabs built in on the modules page). With admin disabled, the vertical tabs work. On the garland theme, no change, admin still did not work when enabled. When admin is enabled, I get the same message in firebug as noted by Tigerfish Paul.

NOW, enabling Javascript cache solves the problem, with admin and the vertical tabs both working. I'm not proficient enough to figure out where the root of the problem lies, but if anyone could help, it would be much appreciated.

mcrittenden’s picture

Looks like this is the root of the problem: https://www.modsecurity.org/tracker/browse/CORERULES-29

mrfelton’s picture

I have this problem with CiviCRM installed, and I'm not using mod security

Paul Lomax’s picture

I haven't done any more research into this in a while, we just reverted to using Administration Menu. But I have a feeling if you install jQuery update 6.x-2.x it should fix the problem.

mrfelton’s picture

Installing jquery_update 6.x-2.x-dev did not fix the issue.

Paul Lomax’s picture

Okay took me a while to figure this one out. Basically CiviCRM wants to include it's own version of jQuery, but this conflicts with the standard drupal version's namespace and causes a lot of problems.

You can't stick with the stock jQuery because CiviCRM needs the latest one (1.3.2 I think) to work. To fix this I took the following steps.

- Install jQuery Update 6.x-2.x-dev (To bring Drupal up to 1.3.2 as standard)
- Now we need to remove jQuery from Civi cleanly
- Create a new CiviCRM custom templates folder (files/civicrm/custom_templates will do)
- Add this folder to the custom directories list in Civi settings (Global Settings > Directories)
- Copy following files including the path to this new folder:
civicrm/templates/CRM/common/drupal.tpl
civicrm/templates/CRM/common/jquery.tpl
civicrm/templates/CRM/common/jquery.files.tpl
- So it will be files/civicrm/custom_templates/CRM/common/drupal.tpl etc

Now edit these new files, remove the jQuery include line from jquery.files.tpl and jquery.tpl (it should be one line near the top).

Remove the jQuery.noConflict(true); from the bottom of drupal.tpl, or comment it out.

That's it, you may need to clear the session by switching on debug mode and adding &sessionReset=2 or &directoryCleanup=3 to the end of any civicrm path so it picks up the new files.

Agileware’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

The solution in #8 fixed it for me.

But then I ran into another problem - civicrm (I'm using 3.4) requires higher than jquery 1.3.2 so other things break. Specifically for me jsTree.

To fix that I am also using the version of jquery_update at #1067290-41: Fix jQuery 1.7 for Drupal 6

So far I have not had issues with this setup.

In response to the maintainer, this is not an admin module issue but a civicrm issue.
Civicrm is crapping all over drupal's jQuery, causing lots of drupal jQuery to fail.
It is really something that civicrm needs to fix on their end.

mrfelton’s picture

#8 works for me too. Also had to upgrade jquery to 1.5.2

Paul Lomax’s picture

Version: 6.x-2.0-alpha5 » 6.x-2.0

There is actually a slightly simpler fix for this, but it involves changing the civicrm.module file.

The issue is partially due to the way that Drupal includes its Javascript files, in order for the .noConflict() jQuery function to work properly the files need to be in the right order.

Something like:

jquery(drupal).js
.. Drupal JS files

jquery(civicrm).js
cj = $.noConflict();
.. lots of civicrm cj() jQuery calls that don't conflict.

What is happening is the Admin menu JS files are being called after the Civi jQuery file, so it is trying to use Civi's .noConflict() version rather than the core.

Quick fix is to move the CiviCRM js files into the theme $scope, which are always called after module files. By adding a 'theme' parameter to these drupal_add_js lines.

if ( strpos( $line, '.js' ) !== false ) {
  drupal_add_js( drupal_get_path('module', 'civicrm' ) . '/../' . $line, 'theme' );
} else if ( strpos( $line, '.css' ) !== false ) {
  drupal_add_css( drupal_get_path('module', 'civicrm' ) . '/../' . $line, 'theme' );
}

Also change line 75 to

drupal_add_js( 'var cj = $.noConflict(true);',

And in drupal.tpl remove the noConflict line all together.

I have this working properly on jQuery 1.3.2 (a stable Drupal version). CiviCRM version 3.4.1.

Vacilando’s picture

Subscribing.

Agileware’s picture

I have spent a lot of time on this trying to find the best solution (one where everything works :)) and:

* The solution in #11 doesn't work for me.
The reason is that I have jquery in my theme, which still runs after the files added using that method.
* I also tried numerous different things in terms of fiddling the order that all the javascript files get added to the $scripts variable of the page tpl, but I couldn't get rid of all conflicts.
* The solution I mentioned in #9 was causing problems with some other modules that rely on a specific version of jQuery (not 1.5.2).

So what I have done currently, which seems to be working (fingers crossed) is to use the solution mentioned in #9 (which combines jQuery 1.5.2 in drupal with the solution in #8) and then just do away with anything that doesn't play nice with jQuery 1.5.2.
Then I can either find an equivalent module that does work or drop the functionality, seeing as though civicrm functionality has priority on this site.

That is the best I have got for now and I have no more time to spend on this time sucking issue.

Also, this issue is not specific to the admin module so it might be better somewhere else, maybe even under the civicrm module (even though it isn't really a module and doesn't really use it's issue queue).
Although the issue queue for taht module has been disabled and issues can't be added to it.

This also badly needs to be addressed on the civicrm end.

shaesen’s picture

Solution in #11 is working fine here !

Thanks Paul !

brayo4’s picture

Solution in #11 is working fine here ! Off to find out why dashlets will not load ......

Thanks Paul & everyone !

scorchio’s picture

I will do some serious testing with Drupal 6 and CiviCRM 3.4.5 and try to prepare a documentation page for this one. Basically everyone trying to use CiviCRM will run into this issue.

scorchio’s picture

Could anyone give me more information on how to reproduce this error on a vanilla D6 site with Admin?

erindarri’s picture

I just came across this issue myself and reviewed all of the possible options that I could google. Finally, I installed the CiviCRM_Theme module, and everything was peachy. Is it possible it is that simple? If so, perhaps that should be added to the CiviCRM documentation.

ericdrogers’s picture

I am trying to apply this fix in CiviCRM 3.4.6, but the line numbers seem to have changed so the reference to Line #75 looks bad. What is the current line# in 3.4.6? Or what is the code to be replaced? Thanks.

Louis Delacretaz’s picture

Issue summary: View changes

Have implemented fix from #11 in civicrm 3.4.6 by adding these two lines of code at line 74
This replaces the reference to line 75 in comment #11

// add Common.js
drupal_add_js( drupal_get_path('module', 'civicrm' ) . '/../js/Common.js' );

// add the final assignment -- From drupal 3.4.1 and patched per https://drupal.org/node/691746
drupal_add_js( 'var cj = jQuery.noConflict(true); $ = cj;',
'inline' );

Civicrm menu, dashboard and various other functions are now working fine