Drupal 7在自定义主题中覆盖jquery js文件 [英] Drupal 7 override jquery js file in custom theme

查看:126
本文介绍了Drupal 7在自定义主题中覆盖jquery js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以重写/覆盖自定义模板脚本变量中使用的默认Drupal 7.26 jquery?



我的意思是其中一个js文件:



< script type =text / javascriptsrc =http://drupal.dev/misc/jquery.js?v=1.4.4> ;< / script>



由自定义主题提供的



我在 sites / all / MYTPL / template.php 中尝试过,但不起作用:



$ scripts ['misc / jquery.js'] ['data'] = $ base_theme。 '/js/packages/jquery-2.1.0.min.js';



我想知道有人管理它,而不使用任何模块,如 jQuery Update



=== UPDATED === / p>

实际上,我通过接受的答案帮助解决了一些基于@cojomojo的答案的修改:

 函数THEMEname_js_alter(& $ javascript){
//交换jQuery以使用库的更新版本。
$ javascript ['misc / jquery.js'] ['data'] = drupal_get_path('theme','THEMEname')。 /js/packages/jquery-2.1.0.min.js’;
}


解决方案

template.php 文件,在 hook_js_alter

  function [YOUR_THEME] _js_alter(& $ js)
{
$ jqKey =my-new-jquery; //新建jquery文件条目的键
$ js [$ jqKey] = $ js ['misc / jquery.js']; //复制默认的jquery设置,所以你不必重新键入它们。
$ js [$ jqKey] ['data'] =https://code.jquery.com/jquery-2.1.0.min.js; //新的jquery文件的路径。
$ js [$ jqKey] ['version'] ='2.1.0'; //你的jquery版本。

unset($ js ['misc / jquery.js']); //删除drupal的默认jquery文件。
}


Is it possible to rewrite/override a default Drupal 7.26 jquery used in custom template scripts variable ?

I mean one of the js files:

<script type="text/javascript" src="http://drupal.dev/misc/jquery.js?v=1.4.4"></script>

by one which comes by custom theme ?

I tried this in sites/all/MYTPL/template.php but it doesn't work:

$scripts['misc/jquery.js']['data'] = $base_theme . '/js/packages/jquery-2.1.0.min.js';

I would like to know if someone managed it without using any modules such as jQuery Update ?

=== UPDATED ===

Actually I solved it by help of accepted answer with some modifications based on @cojomojo 's answer:

function THEMEname_js_alter(&$javascript) {
    // Swap out jQuery to use an updated version of the library.
    $javascript['misc/jquery.js']['data'] = drupal_get_path('theme', 'THEMEname') . '/js/packages/jquery-2.1.0.min.js';
}

解决方案

Use this code inside your theme's template.php file, in hook_js_alter.

function [YOUR_THEME]_js_alter(&$js)
{
    $jqKey = "my-new-jquery"; // a key for new jquery file entry
    $js[$jqKey] = $js['misc/jquery.js']; // copy the default jquery settings, so you don't have to re-type them.
    $js[$jqKey]['data'] = "https://code.jquery.com/jquery-2.1.0.min.js"; // the path for new jquery file.
    $js[$jqKey]['version'] = '2.1.0'; // your jquery version.

    unset($js['misc/jquery.js']); // delete drupal's default jquery file.
}

这篇关于Drupal 7在自定义主题中覆盖jquery js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆