You are here

class WebformScrollTopCommand in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Ajax/WebformScrollTopCommand.php \Drupal\webform\Ajax\WebformScrollTopCommand

Provides an Ajax command for scrolling to the top of an element.

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

Hierarchy

Expanded class hierarchy of WebformScrollTopCommand

1 file declares its use of WebformScrollTopCommand
WebformAjaxFormTrait.php in src/Form/WebformAjaxFormTrait.php

File

src/Ajax/WebformScrollTopCommand.php, line 12

Namespace

Drupal\webform\Ajax
View source
class WebformScrollTopCommand implements CommandInterface {

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

  /**
   * Scroll to target.
   *
   * @var string
   */
  protected $target;

  /**
   * Constructs a WebformScrollTopCommand object.
   *
   * @param string $selector
   *   A CSS selector.
   * @param string $target
   *   Scroll to target which can be 'form' or 'page'. Defaults to 'form'.
   */
  public function __construct($selector, $target = 'form') {
    $this->selector = $selector;
    $this->target = $target;
  }

  /**
   * {@inheritdoc}
   */
  public function render() {
    return [
      'command' => 'webformScrollTop',
      'selector' => $this->selector,
      'target' => $this->target,
    ];
  }

}

Members

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