Mercurial > hg > cmmr2012-drupal-site
annotate core/misc/drupalSettingsLoader.es6.js @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | a9cd425dd02b |
rev | line source |
---|---|
Chris@0 | 1 /** |
Chris@0 | 2 * @file |
Chris@0 | 3 * Parse inline JSON and initialize the drupalSettings global object. |
Chris@0 | 4 */ |
Chris@0 | 5 |
Chris@0 | 6 (function () { |
Chris@0 | 7 // Use direct child elements to harden against XSS exploits when CSP is on. |
Chris@0 | 8 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"]'); |
Chris@0 | 9 |
Chris@0 | 10 /** |
Chris@0 | 11 * Variable generated by Drupal with all the configuration created from PHP. |
Chris@0 | 12 * |
Chris@0 | 13 * @global |
Chris@0 | 14 * |
Chris@0 | 15 * @type {object} |
Chris@0 | 16 */ |
Chris@0 | 17 window.drupalSettings = {}; |
Chris@0 | 18 |
Chris@0 | 19 if (settingsElement !== null) { |
Chris@0 | 20 window.drupalSettings = JSON.parse(settingsElement.textContent); |
Chris@0 | 21 } |
Chris@0 | 22 }()); |