css - 添加到页面的 Drupal 7 额外类

标签 css drupal drupal-7

Drupal 7 额外的类添加到页面

在 Drupal 7 中,有时 View 可以在此处添加类 contextual-links-region。 因此,它使上下文链接显示在所有 View 中,而不仅仅是您将鼠标悬停在其上的 View 。

这里在哪里/如何添加类? 如何从#page 中删除此类?

最佳答案

我不建议你这样做,但如果你仍然想要它, View 模块使用 JavaScript 添加类“contextual-links-region”。

来自 View 模块:

/**
 * Implements MODULE_preprocess_HOOK().
 */
function views_preprocess_html(&$variables) {
  // If the page contains a view as its main content, contextual links may have
  // been attached to the page as a whole; for example, by views_page_alter().
  // This allows them to be associated with the page and rendered by default
  // next to the page title (which we want). However, it also causes the
  // Contextual Links module to treat the wrapper for the entire page (i.e.,
  // the <body> tag) as the HTML element that these contextual links are
  // associated with. This we don't want; for better visual highlighting, we
  // prefer a smaller region to be chosen. The region we prefer differs from
  // theme to theme and depends on the details of the theme's markup in
  // page.tpl.php, so we can only find it using JavaScript. We therefore remove
  // the "contextual-links-region" class from the <body> tag here and add
  // JavaScript that will insert it back in the correct place.
  if (!empty($variables['page']['#views_contextual_links_info'])) {
    $key = array_search('contextual-links-region', $variables['classes_array']);
    if ($key !== FALSE) {
      unset($variables['classes_array'][$key]);
      // Add the JavaScript, with a group and weight such that it will run
      // before modules/contextual/contextual.js.
      drupal_add_js(drupal_get_path('module', 'views') . '/js/views-contextual.js', array('group' => JS_LIBRARY, 'weight' => -1));
    }
  }
}

你可以通过实现hook_js_alter()来移除一个JS文件

关于css - 添加到页面的 Drupal 7 额外类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23436799/

相关文章:

drupal - 有人知道 Drupal 7 的多面搜索解决方案吗?

bash - 在 Fish Shell 中设置导出

php - 如何在 Drupal 7 表单中添加图像字段

javascript - 使用 Zurb Foundation 和 Symfony2

jQueryUI : Sliding two divs at the same time

javascript - 检查元素在屏幕上是否可见 JavaScript/jQuery/iScroll

php - 推送通知 Drupal 模块 - 删除设备(Web 服务)

drupal - 为什么我不能将字段移动到 Drupal 表单中的字段集中 - 无法获取当前值

php - 创建表查询给我 "table does not exists"错误

jquery - 为什么我不能在加载页面后更改事件类