Any way to implement feature which will load different jQuery version on specified pages?

I.e. this page: http://demos.openspending.org/openspendingjs/app/spend-browser/
doesn't work under IE6 with jQuery v1.3.2, but works with v1.5.2

Currently I've hack:

Index: trunk/public_html/sites/all/modules/jquery_update/jquery_update.module
===================================================================
--- a/trunk/public_html/sites/all/modules/jquery_update/jquery_update.module
+++ b/trunk/public_html/sites/all/modules/jquery_update/jquery_update.module
@@ -166,4 +166,11 @@
 function jquery_update_jquery_path() {
   $jquery_file = array('none' => 'jquery.js', 'min' => 'jquery.min.js');
+  
+  // HACK to load jquery 1.5.2 ONLY on the openspending page
+  // END: HACK
+  if ($_SERVER['REQUEST_URI'] == '/openspending') {
+    $jquery_file = array('none' => 'jquery.js', 'min' => 'jquery.min.1.5.2.js');
+  }
+  
   return JQUERY_UPDATE_REPLACE_PATH .'/'. $jquery_file[variable_get('jquery_update_compression_type', 'min')];
 }

See jQuery bug: http://bugs.jquery.com/ticket/6498
And discussion: http://forum.jquery.com/topic/object-doesn-t-support-this-property-or-me...

Comments

kenorb’s picture

kenorb’s picture

Workaround at beginning of the .module file:


/**
 * Replace jQuery files on specified paths (fix for IE 6&7 - jQuery bug: bugs.jquery.com/ticket/6498)
 */
if (array_search($_GET['q'], array('openspending')) !== FALSE) {
  define('JQUERY_UPDATE_REPLACE_PATH', 'sites/all/libraries/jquery/1.5.2');
}

Unfortunately I can't override the path, because it's hardcoded as constant. So I have to load this code before jquery_update loads.
Maybe we should use variable instead of constant?

blainelang’s picture

Thanks for the hack idea as this worked for me. Panels 6.3 IPE did not work with an updated version of jQuery (works fine with the default 1.3.2 version) and yet I needed version 1.4.4+ for another site feature.

It would be nice to be able to include/exclude site paths to to be used for the update/replace similar to how the wysiwyg editors and other modules work.

sgriffin’s picture

[code]
function jquery_update_jquery_path() {
if (arg(0) != 'admin' && arg(1) != 'add' && arg(2) != 'edit') {
$jquery_file = array('none' => 'jquery.js', 'min' => 'jquery-1.6.2.min.js');
// $jquery_file = array('none' => 'jquery.js', 'min' => 'jquery.min.js');
}
else {
$jquery_file = array('none' => 'jquery.js', 'min' => 'jquery.min.js');
}
return JQUERY_UPDATE_REPLACE_PATH .'/'. $jquery_file[variable_get('jquery_update_compression_type', 'min')];
}

[/code]

etc works pretty well too.
There are few things besides the admin area that require old jq.
The only problem found so far is was a minor one with lightbox.

jthomasbailey’s picture

#4 messes up Panels' ajax when you try to add/edit panel panes so I added a line:

function jquery_update_jquery_path() {
if (arg(0) != 'admin' && arg(1) != 'add' && arg(2) != 'edit') {
$jquery_file = array('none' => 'jquery.js', 'min' => 'jquery-1.6.2.min.js');
// $jquery_file = array('none' => 'jquery.js', 'min' => 'jquery.min.js');
}
else if (arg(0) != 'panels' ) {
$jquery_file = array('none' => 'jquery.js', 'min' => 'jquery-1.6.2.min.js');
}
else {
$jquery_file = array('none' => 'jquery.js', 'min' => 'jquery.min.js');
}
return JQUERY_UPDATE_REPLACE_PATH .'/'. $jquery_file[variable_get('jquery_update_compression_type', 'min')];
}

Might be a better way to do it but it works.

sgriffin’s picture

I think it would be great to support non drupal versions directly in the module. The current d6 jquery version is WAY out of date. There are just a few exceptions where drupal jquery is vital except for administration.

jthomasbailey’s picture

Sorry, the last one was no good, this works though:

Line 61 of jquery_update.module:

<?php
/**
 * Return the path to the jQuery file.
 */
function jquery_update_jquery_path() {
if ((arg(0) != 'admin' && arg(1) != 'add' && arg(2) != 'edit') && (arg(0) != 'panels')) {
$jquery_file = array('none' => 'jquery.js', 'min' => 'jquery-1.6.2.min.js');
// $jquery_file = array('none' => 'jquery.js', 'min' => 'jquery.min.js');
}
else {
$jquery_file = array('none' => 'jquery.js', 'min' => 'jquery.min.js');
}
return JQUERY_UPDATE_REPLACE_PATH .'/'. $jquery_file[variable_get('jquery_update_compression_type', 'min')];
}

?>

jthomasbailey’s picture

Update, gotta add a 'ctools' exception:

function jquery_update_jquery_path() {
if ((arg(0) != 'admin' && arg(1) != 'add' && arg(2) != 'edit') && (arg(0) != 'panels') && (arg(0) != 'ctools')) {
$jquery_file = array('none' => 'jquery.js', 'min' => 'jquery-1.6.2.min.js');
// $jquery_file = array('none' => 'jquery.js', 'min' => 'jquery.min.js');
}
else {
$jquery_file = array('none' => 'jquery.js', 'min' => 'jquery.min.js');
}
return JQUERY_UPDATE_REPLACE_PATH .'/'. $jquery_file[variable_get('jquery_update_compression_type', 'min')];
}
XerraX’s picture

You saved my day. Thanks

sgriffin’s picture

another exception for arg(0) == 'batch'

hansrossel’s picture

Related: some other methods to load newer versions of jquery: http://drupal.org/node/1058168

drupalmoff’s picture

Issue summary: View changes

To get it working I had to do the following (Drupal 7):

/**
 * Implements hook_module_implements_alter().
 */
function your_module_module_implements_alter(&$implementations, $hook){
  if( $hook == 'library_alter' ){
    $group = $implementations ['your_module'];
    unset($implementations ['your_module']);
    $implementations ['your_module'] = $group;
  }
}

/**
 * Implements hook_library_alter().
 */
function your_module_library_alter(&$javascript, $module) {
  if( $module === 'system' && current_path() == 'path/to/page' ) {
    // Make sure we inject either the minified or uncompressed version as desired.
    $min = variable_get('jquery_update_compression_type', 'min') == 'none' ? '' : '.min';
    $cdn = variable_get('jquery_update_jquery_cdn', 'none');
    $path = drupal_get_path('module', 'jquery_update');

    $version = '1.7';

    jquery_update_jquery_replace($javascript, $cdn, $path, $min, $version);
  }
}
ak55’s picture

Thank you drupalmoff for the snippet.
It works perfectly.

markhalliwell’s picture

Status: Active » Closed (outdated)

Drupal 6 reached EOL (end-of-life) on February 24, 2016.