diff --git a/core/misc/ajax.es6.js b/core/misc/ajax.es6.js index d8fe6e8783..421c0edd70 100644 --- a/core/misc/ajax.es6.js +++ b/core/misc/ajax.es6.js @@ -990,19 +990,15 @@ * The response from the Ajax request. */ Drupal.theme.ajaxWrapperNewContent = ($newContent, ajax, response) => { - let typeEffect = response.effect || ajax.effect; - if ($newContent.length > 1 && typeEffect !== 'none') { - let countEffectElements = $newContent.length; - // Exclude all nodes not participating in the animation effect. - for (let i = 0; i < $newContent.length; i++) { - if ( - ($newContent[i].nodeName === '#comment') || - ($newContent[i].nodeName === '#text' && /^(\s|\n|\r)*$/.test($newContent[i].textContent)) - ) { - countEffectElements--; - } - } - if (countEffectElements > 1) { + const typeEffect = response.effect || ajax.effect; + if (typeEffect !== 'none') { + // Exclude all nodes that do not interfere with animation effect. + const $filteredContent = $newContent.filter(function(i) { + let isHtmlComment = $newContent[i].nodeName !== '#comment'; + let isWhitespaceText = $newContent[i].nodeName === '#text' && /^(\s|\n|\r)*$/.test($newContent[i].textContent); + return !(isHtmlComment || isWhitespaceText); + }); + if ($filteredContent.length > 1) { $newContent = Drupal.theme('ajaxWrapperMultipleRootElements', $newContent); } } diff --git a/core/misc/ajax.js b/core/misc/ajax.js index d614a61d0a..fb2ee0f680 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -480,15 +480,13 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr Drupal.theme.ajaxWrapperNewContent = function ($newContent, ajax, response) { var typeEffect = response.effect || ajax.effect; - if ($newContent.length > 1 && typeEffect !== 'none') { - var countEffectElements = $newContent.length; - - for (var i = 0; i < $newContent.length; i++) { - if ($newContent[i].nodeName === '#comment' || $newContent[i].nodeName === '#text' && /^(\s|\n|\r)*$/.test($newContent[i].textContent)) { - countEffectElements--; - } - } - if (countEffectElements > 1) { + if (typeEffect !== 'none') { + var $filteredContent = $newContent.filter(function (i) { + var isHtmlComment = $newContent[i].nodeName !== '#comment'; + var isWhitespaceText = $newContent[i].nodeName === '#text' && /^(\s|\n|\r)*$/.test($newContent[i].textContent); + return !(isHtmlComment || isWhitespaceText); + }); + if ($filteredContent.length > 1) { $newContent = Drupal.theme('ajaxWrapperMultipleRootElements', $newContent); } } diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php index 7a63551c36..b1dd8ca823 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php @@ -4,7 +4,6 @@ use Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver; use Drupal\FunctionalJavascriptTests\JavascriptTestBase; -use Drupal\FunctionalJavascriptTests\JSWebAssert; /** * Tests AJAX responses.