Commit 099c8978 authored by xjm's avatar xjm

Issue #3086375 by zrpnr, lauriii, nod_: Deprecate domready and remove usages in core

parent c0e8fed3
......@@ -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
......
......@@ -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')) {
......
......@@ -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);
......@@ -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
......@@ -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');
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment