You are here

function qtip_views_views_pre_render in qTip (Stylish jQuery Tooltips) 7.2

Implements hook_views_pre_render().

File

modules/qtip_views/qtip_views.module, line 158

Code

function qtip_views_views_pre_render(&$view) {

  // Handle rendering label tooltips
  if ($tooltips = qtip_views_fetch_label_tooltips($view)) {

    // Theme tooltip and add our label class before rendering.
    $themed = array();
    foreach ($tooltips as $field => $tooltip) {
      $instance_name = $view->display_handler
        ->get_option('qtip_instance');
      if (!empty($view->field[$field]) && empty($view->field[$field]->options['exclude']) && isset($tooltip['show']) && $tooltip['show']) {
        $field_css = drupal_clean_css_identifier($field);
        $themed[$field_css] = theme('qtip_views_label_tooltip', array(
          'view' => $view,
          'field' => $field,
          'tooltip' => $tooltip['tooltip'],
          'instance' => $instance_name,
        ));
        $label_class =& $view->field[$field]->options['element_label_class'];
        if ($label_class) {
          $label_class .= ' ';
        }
        $label_class .= 'qtip-views-field-' . $field_css . '-label';
      }
    }

    // Bail early if nothing to do.
    if (!empty($themed)) {
      $instance = qtip_load($instance_name);
      $instance = qtip_clean_settings($instance, TRUE);
      drupal_add_js(drupal_get_path('module', 'qtip_views') . '/js/qtip_views.js');
      drupal_add_js(array(
        'qtipViewsLabelTooltip' => array(
          $view->name => array(
            $view->current_display => array(
              'tooltips' => $themed,
              'instance' => $instance,
            ),
          ),
        ),
      ), 'setting');
    }
  }

  // Handle rendering element tooltips
  if ($tooltips = qtip_views_fetch_element_tooltips($view)) {

    // Theme tooltip and add our element class before rendering.
    $themed = array();
    foreach ($tooltips as $field => $tooltip) {
      if (!empty($view->field[$field]) && empty($view->field[$field]->options['exclude'])) {
        $field_css = drupal_clean_css_identifier($field);
        $label_class =& $view->field[$field]->options['element_class'];
        if ($label_class) {
          $label_class .= ' ';
        }
        $label_class .= 'qtip-views-field-' . $field_css;
      }
    }
  }
}