我遇到了Jquery版本绑定的难题。我需要在一个特定的页面上使用1.4.1或更高的版本来实现特定的效果,而且我不知道有什么方法可以覆盖Drupal默认的1.2.6版本。只有一页。Drupal 6似乎可以处理的最高版本是v1.3.2, JQ Update模块在站点范围内进行交换。
那么是否有任何方法可以覆盖特定页面的JQ头标记?
它在一个新模块中。这是从jquery update模块复制和修改的。
/**
* 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);
}
}
?>
drupal_add_js可以工作吗?将$data
替换为.js文件的路径
Michael D的回答非常好。我将补充,我使用它不是一个单一的页面,但在前面的所有网站,所以,我可以保留标准版本的后台Jquery。我没有任何冲突,我使用最新版本的Jquery。