You are here

function lazy_page_attachments in Lazy-load 8

Same name and namespace in other branches
  1. 8.3 lazy.module \lazy_page_attachments()
  2. 8.2 lazy.module \lazy_page_attachments()

Implements hook_page_attachments().

File

./lazy.module, line 83
Module file for Lazy-load.

Code

function lazy_page_attachments(array &$attachments) {
  $config = lazy_is_enabled();
  if ($config) {
    $options = [
      'errorClass' => $config['errorClass'],
      'loadInvisible' => (bool) $config['loadInvisible'],
      'offset' => (int) $config['offset'],
      'saveViewportOffsetDelay' => (int) $config['saveViewportOffsetDelay'],
      'selector' => '.' . $config['selector'],
      'skipClass' => $config['skipClass'],
      'src' => $config['src'],
      'successClass' => $config['successClass'],
      'validateDelay' => $config['validateDelay'],
      'placeholderSrc' => $config['placeholderSrc'],
    ];
    $attachments['#attached']['library'][] = 'lazy/lazy';
    $attachments['#attached']['drupalSettings']['lazy'] = $options;
  }
}