drupalSettingsLoader.es6.js 690 B

123456789101112131415161718192021222324
  1. /**
  2. * @file
  3. * Parse inline JSON and initialize the drupalSettings global object.
  4. */
  5. (function() {
  6. // Use direct child elements to harden against XSS exploits when CSP is on.
  7. const settingsElement = document.querySelector(
  8. 'head > script[type="application/json"][data-drupal-selector="drupal-settings-json"], body > script[type="application/json"][data-drupal-selector="drupal-settings-json"]',
  9. );
  10. /**
  11. * Variable generated by Drupal with all the configuration created from PHP.
  12. *
  13. * @global
  14. *
  15. * @type {object}
  16. */
  17. window.drupalSettings = {};
  18. if (settingsElement !== null) {
  19. window.drupalSettings = JSON.parse(settingsElement.textContent);
  20. }
  21. })();