You are here

public function SlickManager::attach in Slick Carousel 8

Same name and namespace in other branches
  1. 8.2 src/SlickManager.php \Drupal\slick\SlickManager::attach()
  2. 7.3 src/SlickManager.php \Drupal\slick\SlickManager::attach()
1 call to SlickManager::attach()
SlickManager::preRenderSlickWrapper in src/SlickManager.php

File

src/SlickManager.php, line 119

Class

SlickManager
Implements BlazyManagerInterface, SlickManagerInterface.

Namespace

Drupal\slick

Code

public function attach($attach = []) {
  $attach['slick_css'] = isset($attach['slick_css']) ? $attach['slick_css'] : $this
    ->configLoad('slick_css', 'slick.settings');
  $attach['module_css'] = isset($attach['module_css']) ? $attach['module_css'] : $this
    ->configLoad('module_css', 'slick.settings');
  $load = parent::attach($attach);
  if (!empty($attach['lazy'])) {
    $load['library'][] = 'blazy/loading';
  }

  // Load optional easing library.
  $easing = 'libraries/easing/jquery.easing.min.js';
  if (function_exists('libraries_get_path')) {
    $library_path = libraries_get_path('easing') ?: libraries_get_path('jquery.easing');
    if ($library_path) {
      $easing = $library_path . '/jquery.easing.min.js';

      // Composer via bower-asset puts the library within `js` directory.
      if (!is_file($easing)) {
        $easing = $library_path . '/js/jquery.easing.min.js';
      }
    }
  }
  if (is_file($easing)) {
    $load['library'][] = 'slick/slick.easing';
  }
  $load['library'][] = 'slick/slick.load';
  $components = [
    'colorbox',
    'mousewheel',
  ];
  foreach ($components as $component) {
    if (!empty($attach[$component])) {
      $load['library'][] = 'slick/slick.' . $component;
    }
  }
  if (!empty($attach['skin'])) {
    $this
      ->attachSkin($load, $attach);
  }

  // Attach default JS settings to allow responsive displays have a lookup,
  // excluding wasted/trouble options, e.g.: PHP string vs JS object.
  $excludes = explode(' ', 'mobileFirst appendArrows appendDots asNavFor prevArrow nextArrow respondTo');
  $excludes = array_combine($excludes, $excludes);
  $load['drupalSettings']['slick'] = array_diff_key(Slick::defaultSettings(), $excludes);
  $this->moduleHandler
    ->alter('slick_attach_load_info', $load, $attach);
  return $load;
}