diff --git a/core/misc/ajax.es6.js b/core/misc/ajax.es6.js index 6bded620ca..79b75bd85d 100644 --- a/core/misc/ajax.es6.js +++ b/core/misc/ajax.es6.js @@ -1052,9 +1052,9 @@ responseDataNodes = $.parseHTML(trimmedData, true); } // Check every node for it's type to decide if wrapping is necessary. - const onlyElementNodes = responseDataNodes.every(function (element) { - return element.nodeType === Node.ELEMENT_NODE || element.nodeType === Node.COMMENT_NODE; - }); + const onlyElementNodes = responseDataNodes.every( + element => element.nodeType === Node.ELEMENT_NODE || element.nodeType === Node.COMMENT_NODE, + ); // When there are only element and/or comment nodes in the response, no // extra wrapping necessary. @@ -1084,6 +1084,9 @@ case 'empty': case 'remove': Drupal.detachBehaviors($wrapper.get(0), settings); + break; + default: + break; } // Add the new content to the page. @@ -1111,9 +1114,9 @@ // `#ajax['wrapper']` to be optional. if ($newContent.parents('html').length) { // Attach behaviors to all element nodes. - $newContent.each(function () { - if (this.nodeType === Node.ELEMENT_NODE) { - Drupal.attachBehaviors(this, settings); + $newContent.each((index, element) => { + if (element.nodeType === Node.ELEMENT_NODE) { + Drupal.attachBehaviors(element, settings); } }); } diff --git a/core/misc/ajax.js b/core/misc/ajax.js index 2177c7bc71..65659e0f53 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -514,6 +514,9 @@ case 'empty': case 'remove': Drupal.detachBehaviors($wrapper.get(0), settings); + break; + default: + break; } $wrapper[method]($newContent); @@ -532,9 +535,9 @@ } if ($newContent.parents('html').length) { - $newContent.each(function () { - if (this.nodeType === Node.ELEMENT_NODE) { - Drupal.attachBehaviors(this, settings); + $newContent.each(function (index, element) { + if (element.nodeType === Node.ELEMENT_NODE) { + Drupal.attachBehaviors(element, settings); } }); } diff --git a/core/modules/system/tests/modules/ajax_test/js/insert-ajax.es6.js b/core/modules/system/tests/modules/ajax_test/js/insert-ajax.es6.js index 94da75c135..5a3a49dcfb 100644 --- a/core/modules/system/tests/modules/ajax_test/js/insert-ajax.es6.js +++ b/core/modules/system/tests/modules/ajax_test/js/insert-ajax.es6.js @@ -4,38 +4,38 @@ * ajax-insert-inline links for testing ajax requests. */ -(function ($, window, Drupal, drupalSettings) { +(function ($, window, Drupal) { 'use strict'; Drupal.behaviors.insertTest = { - attach: function (context) { - $('.ajax-insert').once('ajax-insert').on('click', function (event) { + attach(context) { + $('.ajax-insert').once('ajax-insert').on('click', (event) => { event.preventDefault(); const ajaxSettings = { url: event.currentTarget.getAttribute('href'), wrapper: 'ajax-target', base: false, element: false, - method: event.currentTarget.getAttribute('data-method') + method: event.currentTarget.getAttribute('data-method'), }; const myAjaxObject = Drupal.ajax(ajaxSettings); myAjaxObject.execute(); }); - $('.ajax-insert-inline').once('ajax-insert').on('click', function (event) { + $('.ajax-insert-inline').once('ajax-insert').on('click', (event) => { event.preventDefault(); const ajaxSettings = { url: event.currentTarget.getAttribute('href'), wrapper: 'ajax-target-inline', base: false, element: false, - method: event.currentTarget.getAttribute('data-method') + method: event.currentTarget.getAttribute('data-method'), }; const myAjaxObject = Drupal.ajax(ajaxSettings); myAjaxObject.execute(); }); $(context).addClass('processed'); - } + }, }; -})(jQuery, window, Drupal, drupalSettings); +})(jQuery, window, Drupal); diff --git a/core/modules/system/tests/modules/ajax_test/js/insert-ajax.js b/core/modules/system/tests/modules/ajax_test/js/insert-ajax.js index 4f8dba29ab..66e1b7fa7d 100644 --- a/core/modules/system/tests/modules/ajax_test/js/insert-ajax.js +++ b/core/modules/system/tests/modules/ajax_test/js/insert-ajax.js @@ -5,7 +5,7 @@ * @preserve **/ -(function ($, window, Drupal, drupalSettings) { +(function ($, window, Drupal) { 'use strict'; Drupal.behaviors.insertTest = { @@ -39,4 +39,4 @@ $(context).addClass('processed'); } }; -})(jQuery, window, Drupal, drupalSettings); \ No newline at end of file +})(jQuery, window, Drupal); \ No newline at end of file