You are here

class ScrollToElementCommand in Paragraphs Features 2.x

Same name and namespace in other branches
  1. 8 src/Ajax/ScrollToElementCommand.php \Drupal\paragraphs_features\Ajax\ScrollToElementCommand

Provides an AJAX command for scrolling an element into the view.

This command is implemented in Drupal.AjaxCommands.prototype.scrollToElement.

Hierarchy

Expanded class hierarchy of ScrollToElementCommand

1 file declares its use of ScrollToElementCommand
ParagraphsFeatures.php in src/ParagraphsFeatures.php

File

src/Ajax/ScrollToElementCommand.php, line 12

Namespace

Drupal\paragraphs_features\Ajax
View source
class ScrollToElementCommand implements CommandInterface {

  /**
   * A CSS selector string.
   *
   * @var string
   */
  protected $elementSelector;

  /**
   * A CSS selector string.
   *
   * @var string
   */
  protected $parentSelector;

  /**
   * Constructs a ScrollToElementCommand object.
   *
   * @param string $elementSelector
   *   The data-drupal-selector for the paragraphs element.
   * @param string $parentSelector
   *   The data-drupal-selector for the paragraphs field.
   */
  public function __construct(string $elementSelector, string $parentSelector) {
    $this->elementSelector = $elementSelector;
    $this->parentSelector = $parentSelector;
  }

  /**
   * {@inheritdoc}
   */
  public function render() {
    return [
      'command' => 'scrollToElement',
      'drupalElementSelector' => $this->elementSelector,
      'drupalParentSelector' => $this->parentSelector,
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ScrollToElementCommand::$elementSelector protected property A CSS selector string.
ScrollToElementCommand::$parentSelector protected property A CSS selector string.
ScrollToElementCommand::render public function Return an array to be run through json_encode and sent to the client. Overrides CommandInterface::render
ScrollToElementCommand::__construct public function Constructs a ScrollToElementCommand object.