You are here

function slick_build_breakpoint_attributes in Slick Carousel 7.2

Provides re-usable breakpoint data-attributes.

1 call to slick_build_breakpoint_attributes()
theme_slick_image in templates/slick.theme.inc
Returns HTML for a slick_image.

File

templates/slick.theme.inc, line 512
Hooks and preprocess functions for the Slick module.

Code

function slick_build_breakpoint_attributes(array &$attributes = array(), $settings = array()) {

  // Blazy can lazyload a single image, Slick not, yet, here comes the trouble.
  if (!empty($settings['blazy'])) {
    $settings['lazy_attribute'] = 'src';
    $settings['lazy_class'] = 'b-lazy';
  }
  $lazy_class = empty($settings['lazy_class']) ? 'lazy' : $settings['lazy_class'];
  $lazy_attribute = empty($settings['lazy_attribute']) ? 'lazy' : $settings['lazy_attribute'];

  // Defines attributes, builtin, or supported lazyload such as Slick.
  $attributes['class'][] = $lazy_class;
  $attributes['data-' . $lazy_attribute] = $settings['image_url'];

  // @todo Blazy integration.
  if (!empty($settings['breakpoints'])) {
    if (!empty($settings['background'])) {
      foreach ($settings['breakpoints'] as $key => $breakpoint) {
        if (!empty($breakpoint['url'])) {
          $attributes['data-src-' . $key] = $breakpoint['url'];
        }
      }
    }
    elseif (!empty($settings['srcset'])) {
      $attributes['srcset'] = '';
      $attributes['data-srcset'] = $settings['srcset'];
      $attributes['sizes'] = '100w';
      if (!empty($settings['sizes'])) {
        $attributes['sizes'] = trim($settings['sizes']);
        unset($attributes['width']);
        unset($attributes['height']);
      }
    }
  }
}