phpjquerydrupal-6

Drupal 6: replace jquery version on single page


I'm in quite a pickle with a Jquery version bind. I need to have version 1.4.1 or higher on one specific page, to achieve a particular effect, and I don't see a way to override the Drupal default verion of 1.2.6. for just the one page. The highest Drupal 6 can seem to handle is v1.3.2, which the JQ Update module swaps in sitewide.

So is there any way to override the JQ head tag for a particular page?


Solution

  • Here it is in a new module. This is copied and modified from the jquery update module.:

    /**
     * Implementation of hook_theme_registry_alter().
     *
     * Make my page preprocess function run *after* everything else's.
     */
    function my_module_theme_registry_alter(&$theme_registry) {
      if (isset($theme_registry['page'])) {
        // If jquery_update's preprocess function is there already, remove it.
        if ($key = array_search('jquery_update_preprocess_page', $theme_registry['page']['preprocess functions'])) {
          unset($theme_registry['page']['preprocess functions'][$key]);
        }
        // Now tack it on at the end so it runs after everything else.
        $theme_registry['page']['preprocess functions'][] = 'my_module_preprocess_page';
      } 
    }
    
    
    /**
     * Implementation of moduleName_preprocess_hook().
     *
     * Replace Drupal core's jquery.js with the new one from my module.
     */
    function my_module_preprocess_page(&$variables) {
      // Only do this for a specific page.
    $alias_array = explode('/', drupal_get_path_alias($_GET['q']));
    if($alias_array[0] == 'special_page') {
      // get the scripts from head.
        $scripts = drupal_add_js();
    
        $myreplacement = drupal_get_path('module', 'my_module').'/jquery-1.4.1.min.js';
    
        $new_jquery = array($myreplacement => $scripts['core']['misc/jquery.js']);
        $scripts['core'] = array_merge($new_jquery, $scripts['core']);
        unset($scripts['core']['misc/jquery.js']);
    
            $variables['scripts'] = drupal_get_js('header', $scripts);
        }
    
    }
    
    ?>