diff --git a/core/core.libraries.yml b/core/core.libraries.yml index 8ee5c7c61a5ed7171964ebdde40dd04d2b59deee..ecdeaa5164ae7bb3338c2fe547de31143e85d115 100644 --- a/core/core.libraries.yml +++ b/core/core.libraries.yml @@ -41,6 +41,7 @@ domready: gpl-compatible: true js: assets/vendor/domready/ready.min.js: { weight: -21, minified: true } + deprecated: The "%library_id%" asset library is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. See https://www.drupal.org/node/3086669 drupal: version: VERSION @@ -48,7 +49,6 @@ drupal: misc/drupal.js: { weight: -18 } misc/drupal.init.js: { weight: -17 } dependencies: - - core/domready - core/drupalSettings drupalSettings: suppressDeprecationErrors: true diff --git a/core/lib/Drupal/Core/Render/theme.api.php b/core/lib/Drupal/Core/Render/theme.api.php index af1392a12d782d8fea2a041e2b3381b6fe8fd22c..8cb8116b9cfa1c3c5ae0672038e920f5bd5604b3 100644 --- a/core/lib/Drupal/Core/Render/theme.api.php +++ b/core/lib/Drupal/Core/Render/theme.api.php @@ -1040,7 +1040,7 @@ function hook_css_alter(&$css, \Drupal\Core\Asset\AttachedAssetsInterface $asset */ function hook_page_attachments(array &$attachments) { // Unconditionally attach an asset to the page. - $attachments['#attached']['library'][] = 'core/domready'; + $attachments['#attached']['library'][] = 'core/drupalSettings'; // Conditionally attach an asset to the page. if (!\Drupal::currentUser()->hasPermission('may pet kittens')) { diff --git a/core/misc/drupal.init.es6.js b/core/misc/drupal.init.es6.js index d5050f12552b0a7937a774a7a5d466b7c43d0194..f8706db11a9b6be17125d73a15e375df70f862a0 100644 --- a/core/misc/drupal.init.es6.js +++ b/core/misc/drupal.init.es6.js @@ -8,10 +8,27 @@ document.documentElement.className += ' js'; // JavaScript should be made compatible with libraries other than jQuery by // wrapping it in an anonymous closure. +(function(Drupal, drupalSettings) { + /** + * Calls callback when document ready. + * + * @param {function} callback + * The function to be called on document ready. + */ + const domReady = callback => { + if (document.readyState !== 'loading') { + callback(); + } else { + const listener = () => { + callback(); + document.removeEventListener('DOMContentLoaded', listener); + }; + document.addEventListener('DOMContentLoaded', listener); + } + }; -(function(domready, Drupal, drupalSettings) { // Attach all behaviors. - domready(() => { + domReady(() => { Drupal.attachBehaviors(document, drupalSettings); }); -})(domready, Drupal, window.drupalSettings); +})(Drupal, window.drupalSettings); diff --git a/core/misc/drupal.init.js b/core/misc/drupal.init.js index 2a66f39793708d5c996c2963e3008c207cb9dc2a..bff94c092b9f22e33380d9608db32329af0a14ef 100644 --- a/core/misc/drupal.init.js +++ b/core/misc/drupal.init.js @@ -11,8 +11,20 @@ if (window.jQuery) { document.documentElement.className += ' js'; -(function (domready, Drupal, drupalSettings) { - domready(function () { +(function (Drupal, drupalSettings) { + var domReady = function domReady(callback) { + if (document.readyState !== 'loading') { + callback(); + } else { + var listener = function listener() { + callback(); + document.removeEventListener('DOMContentLoaded', listener); + }; + document.addEventListener('DOMContentLoaded', listener); + } + }; + + domReady(function () { Drupal.attachBehaviors(document, drupalSettings); }); -})(domready, Drupal, window.drupalSettings); \ No newline at end of file +})(Drupal, window.drupalSettings); \ No newline at end of file diff --git a/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php b/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php index 520063c0ef8369c7895fc6125c93df192ad8df99..370b548be5e860a920cd84432197be10be010e96 100644 --- a/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php +++ b/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php @@ -235,7 +235,7 @@ public function testHeaderHTML() { $query_string = $this->container->get('state')->get('system.css_js_query_string') ?: '0'; $this->assertNotIdentical(strpos($rendered_js, '<script src="' . file_url_transform_relative(file_create_url('core/modules/system/tests/modules/common_test/header.js')) . '?' . $query_string . '"></script>'), FALSE, 'The JS asset in common_test/js-header appears in the header.'); $this->assertNotIdentical(strpos($rendered_js, '<script src="' . file_url_transform_relative(file_create_url('core/misc/drupal.js'))), FALSE, 'The JS asset of the direct dependency (core/drupal) of common_test/js-header appears in the header.'); - $this->assertNotIdentical(strpos($rendered_js, '<script src="' . file_url_transform_relative(file_create_url('core/assets/vendor/domready/ready.min.js'))), FALSE, 'The JS asset of the indirect dependency (core/domready) of common_test/js-header appears in the header.'); + $this->assertNotIdentical(strpos($rendered_js, '<script src="' . file_url_transform_relative(file_create_url('core/misc/drupalSettingsLoader.js'))), FALSE, 'The JS asset of the indirect dependency (core/drupalSettings) of common_test/js-header appears in the header.'); } /** @@ -275,14 +275,13 @@ public function testBrowserConditionalComments() { */ public function testVersionQueryString() { $build['#attached']['library'][] = 'core/backbone'; - $build['#attached']['library'][] = 'core/domready'; $assets = AttachedAssets::createFromRenderArray($build); $js = $this->assetResolver->getJsAssets($assets, FALSE)[1]; $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); $rendered_js = $this->renderer->renderPlain($js_render_array); - $this->assertTrue(strpos($rendered_js, 'core/assets/vendor/backbone/backbone-min.js?v=1.2.3') > 0 && strpos($rendered_js, 'core/assets/vendor/domready/ready.min.js?v=1.0.8') > 0, 'JavaScript version identifiers correctly appended to URLs'); + $this->assertTrue(strpos($rendered_js, 'core/assets/vendor/backbone/backbone-min.js?v=1.2.3') > 0, 'JavaScript version identifiers correctly appended to URLs'); } /**