0

I need to use the jQuery 2.0 in my drupal 7 site, so i have unset two drupal jQuery files and added the latest version of jQuery using this code in my template.php file so it will not affect the views or other core parts(uses Seven theme):

function mytheme_js_alter(&$js){
    unset($js['misc/jquery.js']);
    unset($js['misc/jquery.once.js']);
    drupal_add_js('http://code.jquery.com/jquery-2.0.0.min.js');
}

Everything goes fine but just found that it breaks the tagging auto-complete feature, to solve this problem i wish to remove the jQuery 2.0 and add the jquery.js and jquery.once.js file again only when the page is a form that has a ID news_node_form so i made some change with no luck:

function mytheme_js_alter(&$js){
    unset($js['misc/jquery.js']);
    unset($js['misc/jquery.once.js']);
    drupal_add_js('http://code.jquery.com/jquery-2.0.0.min.js');

    function mytheme_form_news_node_form_alter(&$form, &$form_state, $form_id){
        drupal_add_js('http://127.0.0.1/drupal7/misc/jquery.js?v=1.4.4');
        drupal_add_js('http://127.0.0.1/drupal7/misc/jquery.once.js?v=1.2');
        unset('http://code.jquery.com/jquery-2.0.0.min.js');
    }

}

Any idea how to solve this problem?

  • Have you checked how jQuery Update module is doing it, to have separate jQuery for admin pages? I think it can be considered a pretty good example. – Mołot Jan 2 '14 at 14:24
  • You have a function in a function. It won't run. – Letharion Jan 2 '14 at 14:47
1

You cannot use an updated/upgraded version of jQuery 'just like that' with Drupal. Believe me, it might look everything is working fine, but eventually its gonna break.

As Suggested by Motot, you can use https://drupal.org/project/jquery_update module to use an updated version of jQuery. But I don't think the even the dev version of jquery_update module supports 2.0

What you can do is, use jQuery's no-conflict feature. Here is a detailed documentation on using different JS libraries along side jQuery https://drupal.org/node/1058168 (You want to use jQuery 1.x & 2.0)

And yes, there is a module for that as well - https://drupal.org/project/jqmulti

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.