You are here

function template_process_flexslider_list_item in Flex Slider 7.2

Prepares variables for flexslider list item templates.

See also

flexslider-list-item.tpl.php.

File

theme/flexslider.theme.inc, line 139
Theming functions for the flexslider module.

Code

function template_process_flexslider_list_item(&$variables) {

  // Reset the list of attributes
  $variables['settings']['attributes'] = array();

  // Reference configuration variables
  $item =& $variables['item'];
  $settings =& $variables['settings'];
  $caption =& $variables['caption'];
  $attributes =& $variables['settings']['attributes'];

  // Generated thumbnail support
  if (isset($settings['optionset']->options['controlNav']) and $settings['optionset']->options['controlNav'] === "thumbnails") {

    // If the thumbnails are enabled in the option set, scan for the first img
    // tag and extract the src attribute to set as the thumbnail data
    $src = array();
    preg_match("/<img.+?src=[\"'](.+?)[\"'].+?>/", $item, $src);
    if (!empty($src[1])) {
      $attributes['data-thumb'] = $src[1];
    }

    // Let's also get the alt attribute to apply to thumbnails.
    // This only works in library version 2.6+.
    $alt = array();
    preg_match("/<img.+?alt=[\"'](.*?)[\"'].+?>/", $item, $alt);
    if (!empty($alt)) {
      $attributes['data-thumb-alt'] = $alt[1];
    }
  }
  if (isset($settings['optionset']->options['thumbCaptions']) and $settings['optionset']->options['thumbCaptions'] and !empty($caption)) {
    $attributes['data-thumbcaption'] = $caption;

    // Prevent captions from appearing in the slider as well
    if (isset($settings['optionset']->options['thumbCaptionsBoth']) and FALSE === $settings['optionset']->options['thumbCaptionsBoth']) {
      $caption = '';
    }
  }
  if (!empty($caption)) {
    $caption = '<div class="flex-caption">' . $caption . '</div>';
  }
}