Drupal 6和7标头中未设置的Javascript [英] Drupal 6 & 7 unset Javascript from header

查看:67
本文介绍了Drupal 6和7标头中未设置的Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:我的问题适用于Drupal 6& 7,尽管我的代码示例是Drupal6。人们提供的答案对于两个版本的Drupal都很有用。

My question applies to Drupal 6 & 7, though my code example is Drupal 6. People have provided answers are useful for both versions of Drupal.

我目前在Drupal工作,为Drupal 6网站,并尝试通过template.php文件中的 preprocess_page 函数删除所有不必要的核心和模块JavaScript和CSS。 css文件已成功删除,但我似乎无法删除JavaScript。这就是我所拥有的。在此示例中,除ajax脚本之外的所有内容均已成功删除。

I'm currently working in Drupal creating a mobile theme for a Drupal 6 website and trying to remove all unnecessary core and module JavaScript and css through the preprocess_page function in my template.php file. The css files are successfully removed, but I can't seem to get the JavaScript to be removed. Here's what I've got. In this example, everything is successfully removed except for the the ajax scripts.

任何人都知道我在做什么错吗?

Any idea what I'm doing wrong?

<?php
function mytheme_preprocess_page(&$vars) {
    //////// remove unneccesary drupal head files for mobile version
    // CSS
    $css = drupal_add_css();
       // core
    unset($css['all']['module']['modules/user/user.css']);
    unset($css['all']['module']['modules/node/node.css']);
    unset($css['all']['module']['modules/system/defaults.css']);
    unset($css['all']['module']['modules/system/system.css']);
    unset($css['all']['module']['modules/system/system-menus.css']);
       // contributed -- automatically generate the path—— just easier this way
    $rm[] = drupal_get_path('module','filefield').'/filefield.css';
    $rm[] = drupal_get_path('module','flickr').'/flickr.css';
    $rm[] = drupal_get_path('module','logintoboggan').'/logintoboggan.css';
    $rm[] = drupal_get_path('module','logintoboggan').'/logintoboggan.css';
    $rm[] = drupal_get_path('module','fieldgroup').'/fieldgroup.css';
    $rm[] = drupal_get_path('module','views').'/css/views.css';
    $rm[] = drupal_get_path('module','content').'/theme/content-module.css';
       // remove the contribs from the array
    foreach ($rm as $key => $value) {
      unset($css['all']['module'][$value]);
    }
    // JAVASCRIPT
    $scripts = drupal_add_js();

    unset($scripts['module']['sites/all/modules/ajax/ajax.js']);
    unset($scripts['module']['sites/all/modules/ajax/jquery/jquery.a_form.packed.js']);

    // recreate the tempalate variables
    $vars['styles'] = drupal_get_css($css);
    $vars['scripts'] = drupal_get_js('header', $scripts);
}
?>

ETA:这是脚本在页眉中打印的方式:

ETA: Here is the way the scripts print out in the header:

<script type="text/javascript" src="/sites/all/modules/ajax/jquery/jquery.a_form.packed.js?P"></script>
<script type="text/javascript" src="/sites/all/modules/ajax/ajax.js?P"></script>


推荐答案

您可以在drupal 7中直接使用drupal标头。
您可以清理不需要的其他模块javascript

You can directly use the drupal header in drupal 7. you can clean the other module javascript you don't need

function module_preprocess_page(&$vars) {
  // clean unnecesary script from the page
  if (arg(0) != 'admin' || !(arg(1) == 'add' && arg(2) == 'edit') || arg(0) != 'panels' || arg(0) != 'ctools') {
    $javascript = &drupal_static('drupal_add_js', array());
    unset($javascript['misc/jquery.js']);
    unset($javascript['misc/jquery.once.js']);
    drupal_static('drupal_add_js', $javascript);
  }
}

这篇关于Drupal 6和7标头中未设置的Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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