drupal jQuery 1.4在特定页面上 [英] drupal jQuery 1.4 on specific pages
问题描述
我正在寻找一种方法来强制drupal在特定页面上使用1.4。
与旧问题相同: drupal jQuery 1.4在特定页面上
该答案的代码如下所示:
/ **
*执行hook_theme_registry_alter()。
*基于jquery_update模块。
*
*使此页面预处理函数运行* last *,
*,以便主题不能调用drupal_get_js()。
* /
函数MYMODULE_theme_registry_alter(& $ theme_registry){
if(isset($ theme_registry ['page'])){
//查看我们的预处理函数是否加载如果这样删除它。
if($ key = array_search('MYMODULE_preprocess_page',
$ theme_registry ['page'] ['preprocess functions'])){
unset($ theme_registry ['page'] ['预处理函数'] [$ key]);
}
//现在将其添加到数组的末尾,以便最后运行。
$ theme_registry ['page'] ['preprocess functions'] [] ='MYMODULE_preprocess_page';
}
}
/ **
*实现moduleName_preprocess_hook()。
*根据jquery_update模块的功能。 *
*删除JS和CSS的路径。
* /
函数MYMODULE_preprocess_page(& $ variables,$ arg ='my_page',$ delta = 0){
//我需要一个命中奇迹。可以改变使用函数参数
//来增加它的灵活性。
if(arg($ delta)== $ arg){
$ scripts = drupal_add_js();
$ css = drupal_add_css();
//只对那些有JavaScript的页面执行此操作。
if(!empty($ variables ['scripts'])){
$ path = drupal_get_path('module','admin_menu');
unset($ scripts ['module'] [$ path。'/admin_menu.js']);
$ variables ['scripts'] = drupal_get_js('header',$ scripts);
}
// CSS的类似过程,但有2个Css实例变量。
// $ variables ['css']和$ variables ['styles']都被使用。
if(!empty($ variables ['css'])){
$ path = drupal_get_path('module','admin_menu');
unset($ css ['all'] ['module'] [$ path。'/admin_menu.css']);
unset($ css ['all'] ['module'] [$ path。'/admin_menu.color.css']);
$ variables ['styles'] = drupal_get_css($ css);
}
}
}
我需要jquery_update 1.3。 2要在博客和视频的节点类型上取消设置。有人可以帮我吗?
谢谢。
$ code> MYMODULE_preprocess_page 函数,$ scripts变量包含一个数组,其中包含有关将添加到页面的所有JavaScript的信息。
如果要从页面中删除JS文件,则应从$ scripts数组中删除其条目(然后更新$ variables ['scripts'])。这就是 unset
函数正在做的。
如果你想要删除的jQuery是发送的与Drupal,您可以删除它:
unset($ scripts ['core'] ['misc / jquery.js' ]);
否则,您必须 print_r
$ scripts var为了找到您需要删除的条目。
I'm looking for a way to force drupal to use 1.4 on specific pages.
This is the same as this old question: drupal jQuery 1.4 on specific pages
It look me a while to try the answer which I marked correct. But because I'm new to module dev overall I couldn't figure it out based on the answer.
The code from that answer looked like this:
/**
* Implementation of hook_theme_registry_alter().
* Based on the jquery_update module.
*
* Make this page preprocess function runs *last*,
* so that a theme can't call drupal_get_js().
*/
function MYMODULE_theme_registry_alter(&$theme_registry) {
if (isset($theme_registry['page'])) {
// See if our preprocess function is loaded, if so remove it.
if ($key = array_search('MYMODULE_preprocess_page',
$theme_registry['page']['preprocess functions'])) {
unset($theme_registry['page']['preprocess functions'][$key]);
}
// Now add it on at the end of the array so that it runs last.
$theme_registry['page']['preprocess functions'][] = 'MYMODULE_preprocess_page';
}
}
/**
* Implementation of moduleName_preprocess_hook().
* Based on the jquery_update module functions. *
* Strips out JS and CSS for a path.
*/
function MYMODULE_preprocess_page(&$variables, $arg = 'my_page', $delta=0) {
// I needed a one hit wonder. Can be altered to use function arguments
// to increase it's flexibility.
if(arg($delta) == $arg) {
$scripts = drupal_add_js();
$css = drupal_add_css();
// Only do this for pages that have JavaScript on them.
if (!empty($variables['scripts'])) {
$path = drupal_get_path('module', 'admin_menu');
unset($scripts['module'][$path . '/admin_menu.js']);
$variables['scripts'] = drupal_get_js('header', $scripts);
}
// Similar process for CSS but there are 2 Css realted variables.
// $variables['css'] and $variables['styles'] are both used.
if (!empty($variables['css'])) {
$path = drupal_get_path('module', 'admin_menu');
unset($css['all']['module'][$path . '/admin_menu.css']);
unset($css['all']['module'][$path . '/admin_menu.color.css']);
$variables['styles'] = drupal_get_css($css);
}
}
}
I need the jquery_update 1.3.2 to be unset on the node-types of 'blog' and 'video'. Can someone help me out?
Thank you.
In the MYMODULE_preprocess_page
function, the $scripts variable contains an array with the information about all JavaScript that will be added to the page.
If you want to remove a JS file from the page, you should remove its entry from the $scripts array (and then update $variables['scripts']). That's what the unset
function is doing .
If the jQuery you're trying to remove is the one that's shipped with Drupal, you can remove it with:
unset($scripts['core']['misc/jquery.js']);
Otherwise, you'll have to print_r
the $scripts var in order to find the entry you need to remove.
这篇关于drupal jQuery 1.4在特定页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!