drupalSettingsLoader.es6.js 682 B

12345678910111213141516171819202122
  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('head > script[type="application/json"][data-drupal-selector="drupal-settings-json"], body > script[type="application/json"][data-drupal-selector="drupal-settings-json"]');
  8. /**
  9. * Variable generated by Drupal with all the configuration created from PHP.
  10. *
  11. * @global
  12. *
  13. * @type {object}
  14. */
  15. window.drupalSettings = {};
  16. if (settingsElement !== null) {
  17. window.drupalSettings = JSON.parse(settingsElement.textContent);
  18. }
  19. }());