diff --git a/composer.json b/composer.json index 8adf5e8d4d7fbff370de2db6e2addff2df8e6df2..0468fb882bbf6913f610462163afe88fbaa67c04 100644 --- a/composer.json +++ b/composer.json @@ -181,7 +181,7 @@ "drupal/views_bootstrap": "3.1", "drupal/views_bulk_operations": "^3.0", "drupal/views_fieldsets": "3.3", - "drupal/views_infinite_scroll": "1.5", + "drupal/views_infinite_scroll": "^1.5", "drupal/views_slideshow": "4.4", "drupal/webform": "5.2", "drupal/webform_views": "5.0-alpha2", diff --git a/composer.lock b/composer.lock index 0eb0f60724fd8ae78a039a2df2e136161f0efbbb..10bd4605f09e5070ea5dc3b0b003a5e365b9d187 100644 --- a/composer.lock +++ b/composer.lock @@ -8185,17 +8185,17 @@ }, { "name": "drupal/views_infinite_scroll", - "version": "1.5.0", + "version": "1.6.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/views_infinite_scroll.git", - "reference": "8.x-1.5" + "reference": "8.x-1.6" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/views_infinite_scroll-8.x-1.5.zip", - "reference": "8.x-1.5", - "shasum": "fa19d65a9f6421fe64463b8b64169c6f13d423c3" + "url": "https://ftp.drupal.org/files/projects/views_infinite_scroll-8.x-1.6.zip", + "reference": "8.x-1.6", + "shasum": "614a2b01d57e2a75255883294bfd6b9246c85efd" }, "require": { "drupal/core": "*" @@ -8206,8 +8206,8 @@ "dev-1.x": "1.x-dev" }, "drupal": { - "version": "8.x-1.5", - "datestamp": "1503109444", + "version": "8.x-1.6", + "datestamp": "1561996386", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" @@ -8219,6 +8219,10 @@ "GPL-2.0-or-later" ], "authors": [ + { + "name": "Bobík", + "homepage": "https://www.drupal.org/user/123612" + }, { "name": "Remon", "homepage": "https://www.drupal.org/user/143827" @@ -8231,7 +8235,7 @@ "description": "A pager which allows an infinite scroll effect for views.", "homepage": "https://www.drupal.org/project/views_infinite_scroll", "support": { - "source": "http://cgit.drupalcode.org/views_infinite_scroll" + "source": "https://git.drupalcode.org/project/views_infinite_scroll" } }, { diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 900a3170a89c93be49b0c26093f93e9bf84b9852..fdf4eedc43492671529eb840ca0acd5e2500d6b2 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -8446,18 +8446,18 @@ }, { "name": "drupal/views_infinite_scroll", - "version": "1.5.0", - "version_normalized": "1.5.0.0", + "version": "1.6.0", + "version_normalized": "1.6.0.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/views_infinite_scroll.git", - "reference": "8.x-1.5" + "reference": "8.x-1.6" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/views_infinite_scroll-8.x-1.5.zip", - "reference": "8.x-1.5", - "shasum": "fa19d65a9f6421fe64463b8b64169c6f13d423c3" + "url": "https://ftp.drupal.org/files/projects/views_infinite_scroll-8.x-1.6.zip", + "reference": "8.x-1.6", + "shasum": "614a2b01d57e2a75255883294bfd6b9246c85efd" }, "require": { "drupal/core": "*" @@ -8468,8 +8468,8 @@ "dev-1.x": "1.x-dev" }, "drupal": { - "version": "8.x-1.5", - "datestamp": "1503109444", + "version": "8.x-1.6", + "datestamp": "1561996386", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" @@ -8482,6 +8482,10 @@ "GPL-2.0-or-later" ], "authors": [ + { + "name": "Bobík", + "homepage": "https://www.drupal.org/user/123612" + }, { "name": "Remon", "homepage": "https://www.drupal.org/user/143827" @@ -8494,7 +8498,7 @@ "description": "A pager which allows an infinite scroll effect for views.", "homepage": "https://www.drupal.org/project/views_infinite_scroll", "support": { - "source": "http://cgit.drupalcode.org/views_infinite_scroll" + "source": "https://git.drupalcode.org/project/views_infinite_scroll" } }, { diff --git a/web/modules/views_infinite_scroll/README.txt b/web/modules/views_infinite_scroll/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..3c3737aba10aff0f782145594c470d2d1f99dd59 --- /dev/null +++ b/web/modules/views_infinite_scroll/README.txt @@ -0,0 +1,55 @@ +CONTENTS OF THIS FILE +-------------------- + +* Introduction +* Requirements +* Installation +* Configuration +* Maintainers + + +INTRODUCTION +------------ + +The Views Infinite Scroll module provides a pager, which allows an infinite scroll effect for views. It can work on any view: block, page, etc. + +* For a full description of the module visit https://www.drupal.org/project/views_infinite_scroll + +* To submit bug reports and feature suggestions, or to track changes visit https://www.drupal.org/project/issues/views_infinite_scroll + + +REQUIREMENTS +------------ + +This module requires no modules outside of Drupal core. + + +INSTALLATION +------------ + +* Install the Views Infinite Scroll module as you would normally install a contributed Drupal module. Visit https://www.drupal.org/node/1897420 for further information. + + +CONFIGURATION +------------- + +1. Navigate to Administration > Extend and enable the Views Infinite Scroll module. +2. Navigate to Administration > Structure > Views and click + Add view to create a new view, when done creating the new view, click Save and edit. +3. In the "Page Settings" fieldset, enable "Use a page" by checking the appropriate box. Select "Save and edit". +4. In the "Pager" fieldset, click on the link after "Use pager", which defaults to Mini. +5. Select "Infinite Scroll". Apply the changes. +6. In the field set "Infinite Scroll Options" edit the button text. +7. Check the "Automatically Load Content" box if the functionality of automatically loading subsequent pages as the user scrolls is desired. +8. Select and amount of Items to display. Apply changes. +9. Save the view. + + +MAINTAINERS +----------- + +* Sam Becker (Sam152) - https://www.drupal.org/u/sam152 +* Remon Georgy (Remon) - https://www.drupal.org/u/remon + +Supporting organization: + +* PreviousNext - https://www.drupal.org/previousnext diff --git a/web/modules/views_infinite_scroll/js/infinite-scroll.js b/web/modules/views_infinite_scroll/js/infinite-scroll.js index f42b19529b492fdb90d498433c77065d944c93a6..942a59522635db18b519c1877ad065c041e3f25a 100644 --- a/web/modules/views_infinite_scroll/js/infinite-scroll.js +++ b/web/modules/views_infinite_scroll/js/infinite-scroll.js @@ -41,7 +41,7 @@ $existingPager.removeOnce('infinite-scroll'); var $newRows = $newView.find(contentWrapperSelector).children(); - var $newPager = $newView.find('.js-pager__items'); + var $newPager = $newView.find(pagerSelector); // Add the new rows to existing view. view.$view.find(contentWrapperSelector).append($newRows); diff --git a/web/modules/views_infinite_scroll/src/Plugin/views/pager/InfiniteScroll.php b/web/modules/views_infinite_scroll/src/Plugin/views/pager/InfiniteScroll.php index e3e294370c12e17a2d843baaf78943a41312c797..fa8f99b41ed79b33d2a4b5d47c09489eae6bb316 100644 --- a/web/modules/views_infinite_scroll/src/Plugin/views/pager/InfiniteScroll.php +++ b/web/modules/views_infinite_scroll/src/Plugin/views/pager/InfiniteScroll.php @@ -23,6 +23,16 @@ class InfiniteScroll extends SqlBase { * {@inheritdoc} */ public function render($input) { + // Replace tokens in the button text. + $text = $this->options['views_infinite_scroll']['button_text']; + if (!empty($text) && strpos($text, '@') !== FALSE) { + $replacements = [ + '@next_page_count' => $this->getNumberItemsLeft(), + '@total' => (int) $this->getTotalItems(), + ]; + $this->options['views_infinite_scroll']['button_text'] = strtr($text, $replacements); + } + return [ '#theme' => $this->themeFunctions(), '#options' => $this->options['views_infinite_scroll'], @@ -80,6 +90,14 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { '#type' => 'textfield', '#title' => $this->t('Button Text'), '#default_value' => $options['button_text'], + '#description' => [ + '#theme' => 'item_list', + '#items' => [ + '@next_page_count -- the next page record count', + '@total -- the total amount of results returned from the view', + ], + '#prefix' => $this->t('The following tokens are supported:'), + ], ], 'automatically_load_content' => [ '#type' => 'checkbox', @@ -90,4 +108,25 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { ]; } + /** + * Returns the number of items in the next page. + * + * @return int + * The number of items in the next page. + */ + protected function getNumberItemsLeft() { + $items_per_page = (int) $this->view->getItemsPerPage(); + $total = (int) $this->getTotalItems(); + $current_page = (int) $this->getCurrentPage() + 1; + + // Default to the pager amount. + $next_page_count = $items_per_page; + // Calculate the remaining items if we are at the 2nd to last page. + if ($current_page >= ceil($total / $items_per_page) - 1) { + $next_page_count = $total - ($current_page * $items_per_page); + return $next_page_count; + } + return $next_page_count; + } + } diff --git a/web/modules/views_infinite_scroll/tests/src/FunctionalJavascript/InfiniteScrollTest.php b/web/modules/views_infinite_scroll/tests/src/FunctionalJavascript/InfiniteScrollTest.php index 3ffa73bc0daa09789aa2ef0146f5b6418e39cf32..1a0f43df429145d83d6a4f08b5b4a6b14011d5e0 100644 --- a/web/modules/views_infinite_scroll/tests/src/FunctionalJavascript/InfiniteScrollTest.php +++ b/web/modules/views_infinite_scroll/tests/src/FunctionalJavascript/InfiniteScrollTest.php @@ -2,9 +2,9 @@ namespace Drupal\Tests\views_infinite_scroll\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\JavascriptTestBase; -use Drupal\simpletest\ContentTypeCreationTrait; -use Drupal\simpletest\NodeCreationTrait; +use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\Tests\node\Traits\ContentTypeCreationTrait; +use Drupal\Tests\node\Traits\NodeCreationTrait; use Drupal\views\Entity\View; /** @@ -12,7 +12,7 @@ * * @group views_infinite_scroll */ -class InfiniteScrollTest extends JavascriptTestBase { +class InfiniteScrollTest extends WebDriverTestBase { use NodeCreationTrait; use ContentTypeCreationTrait; @@ -20,18 +20,13 @@ class InfiniteScrollTest extends JavascriptTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'views', 'views_ui', 'views_infinite_scroll', 'node', ]; - /** - * How long to wait for AJAX requests to complete. - */ - const ajaxWaitDelay = 500; - /** * {@inheritdoc} */ @@ -40,7 +35,8 @@ protected function setUp() { $this->createContentType([ 'type' => 'page', ]); - foreach (range(0, 10) as $i) { + // Create 11 nodes. + for ($i = 1; $i <= 11; $i++) { $this->createNode([ 'status' => TRUE, 'type' => 'page', @@ -60,7 +56,7 @@ public function testInfiniteScroll() { $this->drupalGet('click-to-load'); $this->assertTotalNodes(3); $this->getSession()->getPage()->clickLink('Load More'); - $this->getSession()->wait(static::ajaxWaitDelay); + $this->assertSession()->waitForElement('css', '.node--type-page:nth-child(4)'); $this->assertTotalNodes(6); // Test the view automatically loading. @@ -72,8 +68,18 @@ public function testInfiniteScroll() { $this->drupalGet('automatic-load'); $this->assertTotalNodes(3); $this->scrollTo(500); - $this->getSession()->wait(static::ajaxWaitDelay); + $this->assertSession()->waitForElement('css', '.node--type-page:nth-child(4)'); $this->assertTotalNodes(6); + + // Test @next_page_count and @total token. + $this->createView('next-page-count', [ + 'button_text' => 'Load @next_page_count more of @total', + 'automatically_load_content' => FALSE, + ], 6); + $this->drupalGet('next-page-count'); + $this->getSession()->getPage()->clickLink('Load 5 more of 11'); + $this->assertSession()->waitForElement('css', '.node--type-page:nth-child(7)'); + $this->assertTotalNodes(11); } /** @@ -103,8 +109,10 @@ protected function scrollTo($pixels) { * The path for the view. * @param array $settings * The VIS settings. + * @param int $items_per_page + * The number of items per page to display. */ - protected function createView($path, $settings) { + protected function createView($path, $settings, $items_per_page = 3) { View::create([ 'label' => 'VIS Test', 'id' => $this->randomMachineName(), @@ -123,7 +131,7 @@ protected function createView($path, $settings) { 'pager' => [ 'type' => 'infinite_scroll', 'options' => [ - 'items_per_page' => 3, + 'items_per_page' => $items_per_page, 'offset' => 0, 'views_infinite_scroll' => $settings, ], diff --git a/web/modules/views_infinite_scroll/views_infinite_scroll.info.yml b/web/modules/views_infinite_scroll/views_infinite_scroll.info.yml index f75ea446432a5ea9d93993a899056eb604209bb4..649d613e15f93a9526c5338d9887d6e121410880 100644 --- a/web/modules/views_infinite_scroll/views_infinite_scroll.info.yml +++ b/web/modules/views_infinite_scroll/views_infinite_scroll.info.yml @@ -5,10 +5,10 @@ package: Views # core: 8.x dependencies: - - views + - drupal:views -# Information added by Drupal.org packaging script on 2017-08-19 -version: '8.x-1.5' +# Information added by Drupal.org packaging script on 2019-07-01 +version: '8.x-1.6' core: '8.x' project: 'views_infinite_scroll' -datestamp: 1503109450 +datestamp: 1561996387 diff --git a/web/modules/views_infinite_scroll/views_infinite_scroll.libraries.yml b/web/modules/views_infinite_scroll/views_infinite_scroll.libraries.yml index abe5b2993fc6e59ba5e3f88c824be9d961ebdfe8..249790b406f2a115c977af5b39c1db1993e6b941 100644 --- a/web/modules/views_infinite_scroll/views_infinite_scroll.libraries.yml +++ b/web/modules/views_infinite_scroll/views_infinite_scroll.libraries.yml @@ -4,5 +4,7 @@ views-infinite-scroll: js/infinite-scroll.js : {} dependencies: - core/jquery + - core/jquery.once - core/drupal - core/drupal.debounce + - views/views.ajax diff --git a/web/modules/views_infinite_scroll/views_infinite_scroll.module b/web/modules/views_infinite_scroll/views_infinite_scroll.module index 290e446935d60c6a0c32107586a94fda8c7bdb24..c16914e8bf6c2914aa02e61194390ff228289a5d 100644 --- a/web/modules/views_infinite_scroll/views_infinite_scroll.module +++ b/web/modules/views_infinite_scroll/views_infinite_scroll.module @@ -22,7 +22,7 @@ function views_infinite_scroll_preprocess_views_infinite_scroll_pager(&$vars) { $options = array( 'query' => pager_query_add_page($parameters, $element, $pager_page_array[$element] + 1), ); - $vars['items']['next']['href'] = Url::fromRoute('<current>', [], $options); + $vars['items']['next']['href'] = Url::fromRoute('<none>', [], $options); } $vars['#cache']['contexts'][] = 'url.query_args'; $vars['attributes'] = new Attribute([ @@ -40,12 +40,16 @@ function views_infinite_scroll_preprocess_views_view(&$vars) { if ($view->getDisplay()->isPagerEnabled() && !empty($vars['rows'])) { $pager = $view->getPager(); if ($pager && $pager instanceof InfiniteScroll) { - $vars['rows']['#theme_wrappers'] = ['container']; - $vars['rows']['#attributes'] = [ - 'data-drupal-views-infinite-scroll-content-wrapper' => TRUE, - 'class' => [ - 'views-infinite-scroll-content-wrapper', - 'clearfix', + if (!isset($vars['rows']['#theme_wrappers'])) { + $vars['rows']['#theme_wrappers'] = []; + } + $vars['rows']['#theme_wrappers']['container'] = [ + '#attributes' => [ + 'data-drupal-views-infinite-scroll-content-wrapper' => TRUE, + 'class' => [ + 'views-infinite-scroll-content-wrapper', + 'clearfix', + ], ], ]; }