You are here

jcarousel.module in jCarousel 8.4

Provides integration with 3rd party modules and the jCarousel library.

File

jcarousel.module
View source
<?php

/**
 * @file
 * Provides integration with 3rd party modules and the jCarousel library.
 */
use Drupal\Core\Asset;
use Drupal\Core\Template\Attribute;
use Drupal\jcarousel;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Url;

/**
 * Implements hook_help().
 */
function jcarousel_help($route_name, RouteMatchInterface $route_match) {
  $output = '';
  switch ($route_name) {
    case 'help.page.jcarousel':
      $renderer = \Drupal::service('renderer');
      $build = [];
      $build[] = [
        '#type' => 'html_tag',
        '#tag' => 'p',
        '#value' => t('The jCarousel module provides the ability to create carousel-style lists such as those included on this page. The jCarousel module includes integrations with other Drupal modules, but may also be used manually within your own theme or custom modules. It does not include any site-wide settings page or options, each carousel is separately configured.'),
      ];
      $build['views'] = _jcarousel_help_views();
      $build[] = [
        '#type' => 'html_tag',
        '#tag' => 'h2',
        '#value' => t('Custom implementations'),
      ];
      $build[] = [
        '#type' => 'html_tag',
        '#tag' => 'p',
        '#value' => t("The following are demonstrations of jCarousel module when used directly by another module or your theme. <strong>Most users do not need to manually code carousels</strong> (building carousels using Views is the most common approach), but these demonstrations provide good examples of jCarousel's abilities."),
      ];
      $build['simple'] = _jcarousel_help_simple();
      $build['vertical'] = _jcarousel_help_vertical();
      $build['skins'] = _jcarousel_help_skins();
      $build['events'] = _jcarousel_help_events();
      $build['backward'] = _jcarousel_help_backward_compatibility();
      $output .= $renderer
        ->render($build);
      break;
  }
  return $output;
}

/**
 * Returns demo images.
 *
 * @return array
 *   An array of image URLs.
 */
function _jcarousel_help_image_list() {
  return [
    'http://sorgalla.com/jcarousel/examples/_shared/img/img1.jpg',
    'http://sorgalla.com/jcarousel/examples/_shared/img/img2.jpg',
    'http://sorgalla.com/jcarousel/examples/_shared/img/img3.jpg',
    'http://sorgalla.com/jcarousel/examples/_shared/img/img4.jpg',
    'http://sorgalla.com/jcarousel/examples/_shared/img/img5.jpg',
    'http://sorgalla.com/jcarousel/examples/_shared/img/img6.jpg',
  ];
}
function _jcarousel_help_simple() {
  $build = [];
  $details = [
    '#type' => 'details',
    '#title' => t('View sample code'),
    '#description' => t('Following PHP code must be run to add the jCarousel library and CSS to the page.'),
  ];
  $build[] = [
    '#type' => 'html_tag',
    '#tag' => 'h3',
    '#value' => t('Horizontal carousel'),
  ];
  $build[] = [
    '#type' => 'html_tag',
    '#tag' => 'p',
    '#value' => t('This example uses Drupal 8 render API with no jcarousel options to create the default horizontal carousel.'),
  ];
  $images = _jcarousel_help_image_list();
  $build['jcourusel'] = _jcarousel_help_render_gen($images);
  $build['jcourusel_sample'] = $details;
  $code = "<?php\n      \$output = '';\n      \$renderer = \\Drupal::service('renderer');\n       \$images = [\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img1.jpg',\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img2.jpg',\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img3.jpg',\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img4.jpg',\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img5.jpg',\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img6.jpg',\n      ];\n      \$items_list = [];\n      foreach (\$images as \$image) {\n        \$items_list[] = [\n          '#theme' => 'image',\n          '#uri' => \$image,\n          '#width' => '150px',\n          '#height' => '100px',\n          '#alt' => t('Image alt'),\n        ];\n      }\n      \$jcourusel = [\n        '#theme' => 'jcarousel',\n        '#items' => \$items_list,\n      ];\n      \$output .= \$renderer->render(\$jcourusel);\n?>";
  $build['jcourusel_sample']['sample'] = [
    '#type' => 'inline_template',
    '#template' => "{{ php_code|raw}}",
    '#context' => [
      'php_code' => highlight_string($code, TRUE),
    ],
  ];
  return $build;
}
function _jcarousel_help_vertical() {
  $build = [];
  $details = [
    '#type' => 'details',
    '#title' => t('View sample code'),
    '#description' => t('Following PHP code must be run to add the jCarousel library and CSS to the page.'),
  ];
  $build[] = [
    '#type' => 'html_tag',
    '#tag' => 'h3',
    '#value' => t('Vertical carousel'),
  ];
  $build[] = [
    '#type' => 'html_tag',
    '#tag' => 'p',
    '#value' => t('jCarousel can accept a variety of <a href=":url">configuration options</a> via #options arguments in render array. In this example, we created a vertical carousel.', [
      ':url' => 'http://sorgalla.com/projects/jcarousel/#Configuration',
    ]),
  ];
  $images = _jcarousel_help_image_list();
  $options = [
    'vertical' => TRUE,
    'auto' => 2,
    'autoPause' => TRUE,
    'wrap' => 'circular',
    'events' => [
      'jcarousel' => [
        'jcarousel:create' => 'jcarousel.createCarousel',
      ],
    ],
  ];
  $build['jcourusel'] = _jcarousel_help_render_gen($images, $options);
  $build['jcourusel_sample'] = $details;
  $code = "<?php\n      \$output = '';\n      \$renderer = \\Drupal::service('renderer');\n       \$images = [\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img1.jpg',\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img2.jpg',\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img3.jpg',\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img4.jpg',\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img5.jpg',\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img6.jpg',\n      ];\n      \$items_list = [];\n      foreach (\$images as \$image) {\n        \$items_list[] = [\n          '#theme' => 'image',\n          '#uri' => \$image,\n          '#width' => '150px',\n          '#height' => '100px',\n          '#alt' => t('Image alt'),\n        ];\n      }\n      \$options = [\n        'vertical' => TRUE,\n        'auto' => 2,\n        'autoPause' => TRUE,\n        'wrap' => 'circular',\n        'events' => [\n          'jcarousel' => [\n            'jcarousel:create' => 'jcarousel.createCarousel',\n          ],\n        ],\n      ];\n      \$jcourusel = [\n        '#theme' => 'jcarousel',\n        '#options' => \$options,\n        '#items' => \$items_list,\n      ];\n      \$output .= \$renderer->render(\$jcourusel);\n?>";
  $build['jcourusel_sample']['sample'] = [
    '#type' => 'inline_template',
    '#template' => '{{ php_code|raw }}',
    '#context' => [
      'php_code' => highlight_string($code, TRUE),
    ],
  ];
  return $build;
}
function _jcarousel_help_skins() {
  $build = [];
  $details = [
    '#type' => 'details',
    '#title' => t('View sample code'),
    '#description' => t('Following PHP code must be run to add the jCarousel library and CSS to the page.'),
  ];
  $build[] = [
    '#type' => 'html_tag',
    '#tag' => 'h3',
    '#value' => t('Different skins'),
  ];
  $build[] = [
    '#type' => 'html_tag',
    '#tag' => 'p',
    '#value' => t('The "skin" of a carousel can be changed by setting the <code>$options[\'skin\']</code> property. This skin must match one of the skins either provided by a module or matching a skin included in your theme\'s style.css file. Skins are simply a class given to the HTML list with the name "jcarousel-skin-[skin-name]". A custom skin path may be specified in <code>$options[\'skin path\']</code>, or you can use one of these module-based skins:'),
  ];
  $skins = \Drupal::service('jcarousel.skins.manager')
    ->getDefinitions();
  $build['skin_list'] = [
    '#theme' => 'item_list',
    '#items' => array_keys($skins),
  ];
  $build[] = [
    '#type' => 'html_tag',
    '#tag' => 'p',
    '#value' => t("Note that with skins you will often need to override certain\n    CSS styles in your theme's style.css file. Certain properties (like the\n    height and width of individual items and the carousel itself) must be\n    manually specified directly in CSS. You can create own skin in module or\n    theme by adding mymodule_or_theme_name.jcarousel_skins.yml file with folowing content\n    <code><pre>\n    myskin:\n      label: 'My Skin'\n      file: assets/vendor/jcarousel/skins/myskin/jcarousel-myskin.css\n      weight: 1</pre></code>"),
  ];
  $images = _jcarousel_help_image_list();
  $options = [
    'skin' => 'tango',
  ];
  $build['jcourusel'] = _jcarousel_help_render_gen($images, $options);
  $build['jcourusel_sample'] = $details;
  $code = "<?php\n      \$output = '';\n      \$renderer = \\Drupal::service('renderer');\n       \$images = [\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img1.jpg',\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img2.jpg',\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img3.jpg',\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img4.jpg',\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img5.jpg',\n        'http://sorgalla.com/jcarousel/examples/_shared/img/img6.jpg',\n      ];\n      \$items_list = [];\n      foreach (\$images as \$image) {\n        \$items_list[] = [\n          '#theme' => 'image',\n          '#uri' => \$image,\n          '#width' => '150px',\n          '#height' => '100px',\n          '#alt' => t('Image alt'),\n        ];\n      }\n      \$options = [\n        'skin' => 'tango',\n      ];\n      \$jcourusel = [\n        '#theme' => 'jcarousel',\n        '#options' => \$options,\n        '#items' => \$items_list,\n      ];\n      \$output .= \$renderer->render(\$jcourusel);\n?>";
  $build['jcourusel_sample']['sample'] = [
    '#type' => 'inline_template',
    '#template' => '{{ php_code|raw }}',
    '#context' => [
      'php_code' => highlight_string($code, TRUE),
    ],
  ];
  return $build;
}
function _jcarousel_help_events() {
  $build = [];
  $build[] = [
    '#type' => 'html_tag',
    '#tag' => 'h3',
    '#value' => t('Events handle'),
  ];
  $build[] = [
    '#type' => 'html_tag',
    '#tag' => 'p',
    '#value' => t('You can attach jCarousel and jCarousel plugins events handlers via settings
      using \'events\' property. Property structure are following: <code> <pre>
      $options = [
        \'events\' => [
          \'jcarousel\' => [
            \'jcarousel:create\' => \'jcarousel.createCarousel\',
          ],
        ],
      ];</pre> </code>'),
  ];
  return $build;
}

/**
 * Views integration hook_help() helper.
 */
function _jcarousel_help_views() {
  $module_handler = \Drupal::moduleHandler();
  $build = [];
  $build[] = [
    '#type' => 'html_tag',
    '#tag' => 'h2',
    '#value' => t('Views integration'),
  ];
  $views_description_start = t('Most configuration options for the jCarousel module are provided through <a href=":views">Views module</a>.', [
    ':views' => $module_handler
      ->moduleExists('views') ? Url::fromRoute('help.page', [
      'name' => 'views',
    ])
      ->toString() : '#',
  ]);
  $views_description_start_details = '';
  if ($module_handler
    ->moduleExists('views_ui')) {
    $views_description_start_details = t('You may configure a new view through the <a href=":views-url">Views module interface</a>. After adding a new view, change its "Display style" to "jCarousel" and configure the remaining options there. When using the jCarousel display style with Views, you can construct any of the examples on this page as well as dynamically loaded carousels through AJAX requests.', [
      ':views-url' => url::fromRoute('entity.view.collection')
        ->toString(),
    ]);
    $views_description_start_details .= '' . t('For AJAX enabled views please use special jCarousel pager that supports page preload currectly.');
  }
  elseif ($module_handler
    ->moduleExists('views')) {
    $views_description_start_details = t('This site not have Views (or the Views UI module) installed currently. You may be able to turn on this module under your site\'s <a href="!modules-url">module page</a>, or you may have to <a href=":module">download Views module</a> and install it.', [
      ':modules-url' => Url::fromRoute('system.modules_list')
        ->toString(),
    ]);
  }
  $build[] = [
    '#type' => 'html_tag',
    '#tag' => 'p',
    '#value' => $views_description_start . ' ' . $views_description_start_details,
  ];
  return $build;
}

/**
 * Backward compatibility hook_help() helper.
 */
function _jcarousel_help_backward_compatibility() {
  $build = [];
  $backward_details = [
    '#type' => 'details',
    '#title' => t('View sample code'),
    '#description' => t('The following HTML may be printed out to the page through a node, block, or in a custom template. Then the following PHP code must be run to add the jCarousel library and CSS to the page.'),
  ];
  $build[] = [
    '#type' => 'html_tag',
    '#tag' => 'h3',
    '#value' => t('Backward compatibility'),
  ];
  $global_usage = t('For backward compatibility in opposite to Drupal 7 implementation using jcarousel_add() you should enable jCarousel globally via <a href=":config-url">module page configuration page </a> and configure jcarousel via <a href=":attributes-url">data atributes</a>.', [
    ':config-url' => url::fromRoute('jcarousel.config')
      ->toString(),
    ':attributes-url' => 'https://github.com/jsor/jcarousel/blob/master/examples/data-attributes/index.html',
  ]);
  $global_usage .= ' ' . t('Function jcarousel_add() marked as @depricated. Please use Drupal 8 render API element theme jcarousel instead and configuration via data attributes.');
  $build[] = [
    '#type' => 'html_tag',
    '#tag' => 'p',
    '#value' => $global_usage,
  ];
  $images = _jcarousel_help_image_list();
  $build['data_attrs_jcourusel'] = _jcarousel_help_render_gen($images);
  $build['data_attrs_jcourusel_sample'] = $backward_details;
  $code_html = '
        <div class="jcarousel-wrapper">
          <div class="jcarousel" data-jcarousel="true" data-wrap="circular">
            <ul>
              <li><img src="http://sorgalla.com/jcarousel/examples/_shared/img/img1.jpg"></li>
              <li><img src="http://sorgalla.com/jcarousel/examples/_shared/img/img2.jpg"></li>
              <li><img src="http://sorgalla.com/jcarousel/examples/_shared/img/img3.jpg"></li>
              <li><img src="http://sorgalla.com/jcarousel/examples/_shared/img/img4.jpg"></li>
              <li><img src="http://sorgalla.com/jcarousel/examples/_shared/img/img5.jpg"></li>
              <li><img src="http://sorgalla.com/jcarousel/examples/_shared/img/img6.jpg"></li>
            </ul>
          </div>
          <a data-jcarousel-control="true" data-target="-=1" class="jcarousel-control-prev" href="#"></a>
          <a data-jcarousel-control="true" data-target="+=1" class="jcarousel-control-next" href="#"></a>
        </div>';
  $build['data_attrs_jcourusel_sample']['sample'] = [
    '#type' => 'inline_template',
    '#template' => "<code><pre>{{ list_html|escape }} </pre></code>",
    '#context' => [
      'list_html' => $code_html,
    ],
  ];
  return $build;
}

/**
 * Builds carousel from image URLs.
 *
 * @param array $images
 *   Array of image URLs.
 * @param array $options
 *   The carousel options.
 *
 * @return array
 *   Renderable array of carousel.
 */
function _jcarousel_help_render_gen($images, $options = []) {
  $item_lists = [];
  foreach ($images as $image) {
    $item_lists[] = [
      '#theme' => 'image',
      '#uri' => $image,
      '#width' => '150px',
      '#height' => '100px',
      '#alt' => t('Image alt'),
    ];
  }
  return [
    '#theme' => 'jcarousel',
    '#items' => $item_lists,
    '#options' => $options,
  ];
}

/**
 * Implements hook_theme().
 */
function jcarousel_theme() {
  return [
    'jcarousel' => [
      'variables' => [
        'items' => [],
        'options' => [],
        'identifier' => NULL,
      ],
    ],
  ];
}

/**
 * Adds all the necessary CSS and JS necessary for building a carousel.
 *
 * @param array $options
 *   (optional) A list of settings to be passed to jCarousel.
 *
 * @return array
 *   An array of JS and CSS files, suitable for inclusion as an #attached array.
 *
 * @deprecated Please use render arrays with element theme 'jcarousel' instead.
 * @see jcarousel_theme()
 */
function jcarousel_add($options = []) {

  // Add the jCarousel library and any global settings.
  $attachments['library'][] = 'jcarousel/jcarousel';
  $options += [
    'skin' => 'default',
  ];

  // Allow other modules to modify these settings.
  \Drupal::moduleHandler()
    ->alter('jcarousel_options', $options);
  $attachments['library'][] = 'jcarousel/skin.' . $options['skin'];
  return $attachments;
}

/**
 * Implements hook_library_info_alter().
 *
 * Add skins as libraries.
 */
function jcarousel_library_info_alter(&$libraries, $extension) {
  if ($extension == 'jcarousel') {
    $skins = \Drupal::service('jcarousel.skins.manager')
      ->getDefinitions();
    foreach ($skins as $key => $data) {
      $libraries["skin.{$key}"] = [
        'version' => 'VERSION',
        'css' => [
          'theme' => [
            $data['file'] => [],
          ],
        ],
      ];
    }
  }
}

/**
 * Preprocess function for jcarousel.html.twig.
 */
function template_preprocess_jcarousel(&$variables) {

  // Set default options.
  $variables['options'] += [
    'skin' => 'default',
    'scroll' => 1,
    'vertical' => 0,
    'navigation' => 'after',
    'visible' => 4,
  ];
  $options = $variables['options'];

  // Add the jCarousel library and any global settings.
  $variables['#attached']['library'][] = 'jcarousel/jcarousel';

  // Allow other modules to modify these settings.
  \Drupal::moduleHandler()
    ->alter('jcarousel_options', $options, $class_name);
  if (!empty($options['skin'])) {
    $variables['#attached']['library'][] = 'jcarousel/skin.' . $options['skin'];
  }
  $variables['options'] = $options;
  unset($variables['attributes']);
  $variables += _jcarousel_generate_attributes($variables['items'], $variables['options']);
}

/*
 * Preprocess function for views-view-jcarousel.html.twig.
 */
function template_preprocess_views_view_jcarousel(&$variables) {

  /** @var \Drupal\views\ViewExecutable $view */
  $view =& $variables['view'];
  $variables['options'] = $view->style_plugin->options;
  $position = array_search('jcarousel/jcarousel', $view->element['#attached']['library']);
  $library = array_splice($view->element['#attached']['library'], $position, 1);
  $view->element['#attached']['library'] = array_merge($view->element['#attached']['library'], $library);
  $variables['options']['preload_page'] = 0;

  // Build the list of classes for the carousel.
  // $variables['options'] = $view->getStyle()->options;
  // If using AJAX, adjust the view's positioning based on the current page.
  if ($view
    ->ajaxEnabled() && $view
    ->usePager()) {
    if ($view->pager
      ->getPluginId() == 'jcarousel_pager') {
      if ($view->pager->total_items == PHP_INT_MAX / 2) {

        // Attach preload.
        $variables['options']['preload_page'] = $view
          ->getCurrentPage() + 1;
      }
      $variables['options']['ajax'] = TRUE;
      if (empty($variables['options']['ajax_path'])) {
        $variables['options']['ajax_path'] = 'jcarousel/views/ajax';
      }
    }
  }
  unset($variables['attributes']);
  $variables += _jcarousel_generate_attributes($variables['rows'], $variables['options']);
  $variables['items'] = $variables['rows'];
}

/**
 * Helper to build attributes array for carousel items.
 *
 * @param array $items
 *   The carousel items.
 * @param array $options
 *   The options for carousel.
 *
 * @return array
 *   An array of attributes.
 */
function _jcarousel_generate_attributes($items, $options) {
  $attributes = [];
  $attributes['attributes'] = new Attribute();
  $attributes['attributes_wrapper'] = new Attribute();
  $attributes['attributes_previous'] = new Attribute();
  $attributes['attributes_next'] = new Attribute();
  $attributes['attributes_content'] = new Attribute();

  // Build the list of classes for the carousel.
  $attributes['attributes']
    ->addClass('jcarousel');
  $attributes['attributes']
    ->setAttribute('data-jcarousel', 'true');

  // Scroll all visible elements at a time if scroll = 'auto'
  $scroll = !empty($options['scroll']) ? $options['scroll'] : $options['visible'];
  if ($options['auto'] > 0) {
    $attributes['attributes']
      ->setAttribute('data-autoscroll-interval', $options['auto'] * 1000);
    $attributes['attributes']
      ->setAttribute('data-autoscroll-autostart', 'true');
    $attributes['attributes']
      ->setAttribute('data-autoscroll-target', '+=' . $scroll);
    if ($options['autoPause'] && empty($options['events']['jcarousel']['jcarousel:createend'])) {
      $options['events']['jcarousel']['jcarousel:createend'] = 'jcarousel.autoPauseCallback';
    }
  }
  if ($options['responsive'] && empty($options['events']['jcarousel']['jcarousel:reload'])) {
    $options['vertical'] = FALSE;
    unset($options['visible']);
    $options['events']['jcarousel']['jcarousel:reload'] = 'jcarousel.reloadCallback';
  }
  if (!empty($options['events']['jcarousel'])) {
    $attributes['attributes']
      ->setAttribute('data-events', Json::encode($options['events']['jcarousel']));
  }
  if (isset($options['wrap'])) {
    $attributes['attributes']
      ->setAttribute('data-wrap', $options['wrap']);
  }
  if (isset($options['ajax']) && $options['ajax']) {
    $attributes['attributes']
      ->setAttribute('data-ajax', 'true');
    $attributes['attributes']
      ->setAttribute('data-ajax-path', $options['ajax_path']);
    if ($options['preload_page'] != 0) {
      $attributes['attributes']
        ->setAttribute('data-preload-page', $options['preload_page']);
    }
  }
  if (isset($options['vertical']) && $options['vertical']) {
    $attributes['attributes']
      ->setAttribute('data-vertical', 'true');
  }
  $orientation = !empty($options['vertical']) && $options['vertical'] ? 'vertical' : 'horizontal';
  $attributes['attributes_wrapper']
    ->addClass('jcarousel-wrapper');
  if (!empty($options['visible'])) {
    $attributes['attributes_wrapper']
      ->addClass('jcarousel-visible-' . $options['visible']);
  }
  if (!empty($options['skin'])) {
    $attributes['attributes_wrapper']
      ->addClass('jcarousel-skin-' . $options['skin']);
  }
  $attributes['attributes_content']
    ->addClass('jcarousel-container-' . $orientation);
  $attributes['attributes_previous']
    ->setAttribute('data-jcarousel-control', 'true');
  if (!empty($options['events']['jcarouselcontrol'])) {
    $attributes['attributes_previous']
      ->setAttribute('data-events', Json::encode($options['events']['jcarouselcontrol']));
  }
  $attributes['attributes_previous']
    ->setAttribute('data-target', '-=' . $scroll);
  $attributes['attributes_previous']
    ->addClass('jcarousel-control-prev');
  $attributes['attributes_next']
    ->setAttribute('data-jcarousel-control', 'true');
  if (!empty($options['events']['jcarouselcontrol'])) {
    $attributes['attributes_next']
      ->setAttribute('data-events', Json::encode($options['events']['jcarouselcontrol']));
  }
  $attributes['attributes_next']
    ->setAttribute('data-target', '+=' . $scroll);
  $attributes['attributes_next']
    ->addClass('jcarousel-control-next');
  $attributes['attributes_wrapper']
    ->addClass('jcarousel-' . $orientation);

  // Give each item a class to identify where in the carousel it belongs.
  foreach ($items as $id => $row) {
    $row_attribute = new Attribute();
    $attributes['attributes_row'][$id] = $row_attribute;
  }
  return $attributes;
}

/**
 * Implements hook_page_attachments().
 */
function jcarousel_page_attachments(&$page) {
  if (!\Drupal::config('jcarousel.settings')
    ->get('global_load')) {
    return;
  }
  $options = [
    'skin' => 'default',
    'scroll' => 1,
    'vertical' => 0,
    'navigation' => 'after',
  ];

  // Add the jCarousel library and any global settings.
  $page['#attached']['library'][] = 'jcarousel/jcarousel';

  // Allow other modules to modify these settings.
  \Drupal::moduleHandler()
    ->alter('jcarousel_options', $options, $class_name);
  $skins = \Drupal::service('jcarousel.skins.manager')
    ->getDefinitions();
  foreach ($skins as $id => $skin) {
    $variables['#attached']['library'][] = 'jcarousel/skin.' . $id;
  }
}

Functions

Namesort descending Description
jcarousel_add Deprecated Adds all the necessary CSS and JS necessary for building a carousel.
jcarousel_help Implements hook_help().
jcarousel_library_info_alter Implements hook_library_info_alter().
jcarousel_page_attachments Implements hook_page_attachments().
jcarousel_theme Implements hook_theme().
template_preprocess_jcarousel Preprocess function for jcarousel.html.twig.
template_preprocess_views_view_jcarousel
_jcarousel_generate_attributes Helper to build attributes array for carousel items.
_jcarousel_help_backward_compatibility Backward compatibility hook_help() helper.
_jcarousel_help_events
_jcarousel_help_image_list Returns demo images.
_jcarousel_help_render_gen Builds carousel from image URLs.
_jcarousel_help_simple
_jcarousel_help_skins
_jcarousel_help_vertical
_jcarousel_help_views Views integration hook_help() helper.