You are here

public function views_accordion_style_plugin::render in Views Accordion 7

Same name and namespace in other branches
  1. 6 views_accordion_style_plugin.inc \views_accordion_style_plugin::render()

Render the display in this style.

Overrides views_plugin_style::render

File

./views_accordion_style_plugin.inc, line 254
Provide an accordion style plugin for Views. This file is autoloaded by views.

Class

views_accordion_style_plugin
Implements views_plugin_style().

Code

public function render() {
  $output = parent::render();
  if ($this->options['disableifone'] == '1') {
    if (count($this->rendered_fields) < 2) {
      return $output;
    }
  }

  // Add the appropriate effect library if necessary.
  $effect = $this->options['animated'];
  if ($effect !== 'none' && $effect !== 'slide') {

    // For now we only use ui core effects library, which provides the easing
    // effects.This switch is left here in case we actualy need to load any
    // other libraries.
    switch ($effect) {
      default:
        $library = 'effects';
        break;
    }
    if (isset($library)) {
      drupal_add_library('system', 'effects');
    }
  }

  // Preparing the js variables and adding the js to our display
  // we do it here so we dont have it run once every group.
  $view_settings['collapsible'] = $this->options['collapsible'];
  if ($this->options['row-start-open'] == 'random') {
    $view_settings['rowstartopen'] = 'random';
  }
  else {
    $view_settings['rowstartopen'] = $this->options['row-start-open'] == 'none' ? FALSE : (int) $this->options['row-start-open'];
  }
  $view_settings['animated'] = $this->options['animated'] == 'none' ? FALSE : $this->options['animated'];
  $view_settings['duration'] = (int) $this->options['animation_time'];
  $view_settings['autoheight'] = $this->options['autoheight'];
  $view_settings['event'] = $this->options['event'];
  $view_settings['fillspace'] = $this->options['fillspace'];
  $view_settings['navigation'] = $this->options['navigation'];
  $view_settings['clearstyle'] = $this->options['clearstyle'];
  $view_settings['grouping'] = $this->options['grouping'] ? 1 : 0;
  $view_settings['display'] = $this->view->current_display;
  $view_settings['viewname'] = $this->view->name;
  $view_settings['usegroupheader'] = $view_settings['grouping'] ? $this->options['use-grouping-header'] : 0;
  $accordion_id = 'views-accordion-' . $this->view->name . '-' . $this->view->current_display;
  if ($view_settings['usegroupheader'] == 1) {
    $view_settings['header'] = 'h3.' . $accordion_id . '-header';
  }

  // Used to get the first field to be used as the accordion header.
  if ($view_settings['usegroupheader'] == 0) {
    $view_settings['header'] = '.views-accordion-header';
  }

  // Use new options format if jquery_update has installed a version >= 1.9.
  $view_settings['newoptions'] = $this->newoptions;
  drupal_add_js(array(
    'views_accordion' => array(
      $accordion_id => $view_settings,
    ),
  ), 'setting');
  return $output;
}