You are here

public function ThunderJavascriptTestBase::scrollElementInView in Thunder 8.5

Same name and namespace in other branches
  1. 8.2 tests/src/FunctionalJavascript/ThunderJavascriptTestBase.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderJavascriptTestBase::scrollElementInView()
  2. 8.3 tests/src/FunctionalJavascript/ThunderJavascriptTestBase.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderJavascriptTestBase::scrollElementInView()
  3. 8.4 tests/src/FunctionalJavascript/ThunderJavascriptTestBase.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderJavascriptTestBase::scrollElementInView()
  4. 6.2.x tests/src/FunctionalJavascript/ThunderJavascriptTestBase.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderJavascriptTestBase::scrollElementInView()
  5. 6.0.x tests/src/FunctionalJavascript/ThunderJavascriptTestBase.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderJavascriptTestBase::scrollElementInView()
  6. 6.1.x tests/src/FunctionalJavascript/ThunderJavascriptTestBase.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderJavascriptTestBase::scrollElementInView()

Scroll element with defined css selector in middle of browser view.

Parameters

string $cssSelector: CSS Selector for element that should be centralized.

11 calls to ThunderJavascriptTestBase::scrollElementInView()
AccessUnpublishedTest::testAccessUnpublished in tests/src/FunctionalJavascript/Integration/AccessUnpublishedTest.php
Testing integration of "access_unpublished" module.
EntityReferenceActionsTest::testMediaEditInArticle in tests/src/FunctionalJavascript/Integration/EntityReferenceActionsTest.php
Test editing of media items in an embedded gallery.
MediaGalleryModifyTest::testOrderChange in tests/src/FunctionalJavascript/MediaGalleryModifyTest.php
Test order change for Gallery.
MetaInformationTest::setMetaTagConfigurationForUrl in tests/src/FunctionalJavascript/MetaInformationTest.php
Set meta tag configuration for administration url.
NestedTableDragTest::addLinkField in tests/src/FunctionalJavascript/Integration/NestedTableDragTest.php
Adding link field instance.

... See full list

File

tests/src/FunctionalJavascript/ThunderJavascriptTestBase.php, line 177

Class

ThunderJavascriptTestBase
Base class for Thunder Javascript functional tests.

Namespace

Drupal\Tests\thunder\FunctionalJavascript

Code

public function scrollElementInView($cssSelector) {
  $this
    ->getSession()
    ->executeScript('
        var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
        var element = jQuery(\'' . addcslashes($cssSelector, '\'') . '\');
        var scrollTop = element.offset().top - (viewPortHeight/2);
        var scrollableParent = jQuery.isFunction(element.scrollParent) ? element.scrollParent() : [];
        if (scrollableParent.length > 0 && scrollableParent[0] !== document && scrollableParent[0] !== document.body) { scrollableParent[0].scrollTop = scrollableParent[0].scrollTop + scrollTop - scrollableParent.offset().top } else { window.scroll(0, scrollTop); };
      ');
}