You are here

function template_preprocess_views_foundation_navigation in Views Foundation 7

Theme the Foundation Navigation.

File

theme/views_foundation.theme.inc, line 99
The theme system, which controls the output of views foundation plugins.

Code

function template_preprocess_views_foundation_navigation(&$variables) {
  $view = $variables['view'];
  $options = $variables['options'];
  $variables['fields'] = array();

  // Preprare fields for the output.
  foreach ($view->style_plugin->rendered_fields as $index => $row) {
    $variables['fields'][$index]['content'] = '';
    foreach ($row as $key => $value) {
      if ($options['nav_field'] == $key) {

        // New array for single row output.
        $variables['fields'][$index] = array(
          'is_active' => '',
          'link' => $value,
          'content' => '',
          'wrapper_prefix' => '',
          'wrapper_suffix' => '',
        );

        // Check if the link has "active" class.
        if (strpos($value, 'active') > 0) {
          $variables['fields'][$index]['is_active'] = 'active';
        }
        $class = 'flyout';

        // Add "right" class to submenu.
        if ($options['nav_count'] && $index >= $options['nav_count']) {
          $class .= ' right';
        }

        // Add "large" class to submenu (if selected in the options).
        if ($options['nav_large']) {
          $class .= ' large';
        }

        // Prepare submenu wrappers.
        if ($options['nav_link']) {
          $variables['fields'][$index]['wrapper_prefix'] = '<ul class="' . $class . '">';
          $variables['fields'][$index]['wrapper_suffix'] = '</ul>';
        }
        else {
          $variables['fields'][$index]['wrapper_prefix'] = '<div class="' . $class . '">';
          $variables['fields'][$index]['wrapper_suffix'] = '</div>';
        }
      }
      elseif ($options['nav_link']) {
        $variables['fields'][$index]['content'] .= '<li>' . $value . '</li>';
      }
    }
  }
  if (!$options['nav_link']) {
    foreach ($variables['rows'] as $index => $row) {
      $variables['fields'][$index]['content'] = $row;
    }
  }
  drupal_add_js(check_url(variable_get('views_foundation_js')) . '/jquery.foundation.navigation.js');
}