drupal jQuery 1.4 на определенных страницах - PullRequest
4 голосов
/ 06 июня 2010

Я ищу способ заставить drupal использовать 1.4 на определенных страницах.

Это то же самое, что и старый вопрос: drupal jQuery 1.4 на определенных страницах

Мне нужно время, чтобы найти ответ, который я пометил правильно.Но так как я новичок в модуле dev в целом, я не смог понять его на основе ответа.

Код этого ответа выглядел так:

/**
 * 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_update1.3.2 быть не установленным для типов узлов «блог» и «видео».Кто-нибудь может мне помочь?

Спасибо.

1 Ответ

2 голосов
/ 07 июня 2010

В функции MYMODULE_preprocess_page переменная $ scripts содержит массив с информацией обо всем JavaScript, который будет добавлен на страницу.

Если вы хотите удалить JS-файл со страницы, вы должны удалить его запись из массива $ scripts (а затем обновить $ variable ['scripts']). Вот что делает функция unset.

Если jQuery, который вы пытаетесь удалить, поставляется с Drupal, вы можете удалить его с помощью:

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

В противном случае вам потребуется print_r переменная $ scripts, чтобы найти запись, которую нужно удалить.

...