You are here

public static function ScrollRevealModifier::modification in Modifiers Pack 8

File

modules/modifiers_scroll_reveal/src/Plugin/modifiers/ScrollRevealModifier.php, line 22

Class

ScrollRevealModifier
Provides a Modifier to reveal elements on scroll.

Namespace

Drupal\modifiers_scroll_reveal\Plugin\modifiers

Code

public static function modification($selector, array $config) {
  if (!empty($config['sr_delay'])) {
    $args['delay'] = (int) $config['sr_delay'];
  }
  if (!empty($config['sr_distance'])) {
    $args['distance'] = $config['sr_distance'];
  }
  if (!empty($config['sr_duration'])) {
    $args['duration'] = (int) $config['sr_duration'];
  }
  if (!empty($config['sr_mobile'])) {
    $args['mobile'] = (bool) $config['sr_mobile'];
  }
  if (!empty($config['sr_opacity'])) {
    $args['opacity'] = (double) $config['sr_opacity'];
  }
  if (!empty($config['sr_origin'])) {
    $args['origin'] = $config['sr_origin'];
  }
  if (!empty($config['sr_scale'])) {
    $args['scale'] = (double) $config['sr_scale'];
  }
  if (!empty($config['sr_seq_interval'])) {
    $args['interval'] = (int) $config['sr_seq_interval'];
  }
  if (!empty($config['sr_seq_selector'])) {
    $args['selector'] = $config['sr_seq_selector'];
  }
  if (!empty($args)) {
    $media = parent::getMediaQuery($config);
    $libraries = [
      'modifiers_scroll_reveal/apply',
    ];
    $settings = [
      'namespace' => 'ScrollRevealModifier',
      'callback' => 'apply',
      'selector' => $selector,
      'media' => $media,
      'args' => $args,
    ];
    return new Modification([], $libraries, $settings, []);
  }
  return NULL;
}