drupalSettingsLoader.js 698 B

12345678910111213141516171819202122232425
  1. /**
  2. * @file
  3. * Parse inline JSON and initialize the drupalSettings global object.
  4. */
  5. (function () {
  6. 'use strict';
  7. // Use direct child elements to harden against XSS exploits when CSP is on.
  8. var 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"]');
  9. /**
  10. * Variable generated by Drupal with all the configuration created from PHP.
  11. *
  12. * @global
  13. *
  14. * @type {object}
  15. */
  16. window.drupalSettings = {};
  17. if (settingsElement !== null) {
  18. window.drupalSettings = JSON.parse(settingsElement.textContent);
  19. }
  20. })();