簡體   English   中英

在特定頁面上的Drupal jQuery 1.4

[英]drupal jQuery 1.4 on specific pages

我正在尋找一種強制drupal在特定頁面上使用1.4的方法。

這與這個老問題相同: 特定頁面上的drupal jQuery 1.4

我似乎需要一段時間才能嘗試我標記為正確的答案。 但是,因為我是模塊開發人員的新手,所以我無法根據答案搞清楚。

該答案中的代碼如下所示:

/**
 * 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);
    }
  }
}

我需要在“博客”和“視頻”的節點類型上取消設置jquery_update 1.3.2。 有人可以幫我嗎?

謝謝。

MYMODULE_preprocess_page函數中,$ scripts變量包含一個數組,其中包含將添加到頁面的所有JavaScript的信息。

如果要從頁面中刪除JS文件,則應從$ scripts數組中刪除其條目(然后更新$ variables ['scripts'])。 這就是unset函數正在做的事情。

如果您要刪除的jQuery是Drupal隨附的jQuery,則可以使用以下方法刪除它:

unset($scripts['core']['misc/jquery.js']);

否則,您必須print_r $ scripts var才能找到需要刪除的條目。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM