diff options
author | Alex Pott <alex.a.pott@googlemail.com> | 2015-07-13 12:39:16 +0100 |
---|---|---|
committer | Alex Pott <alex.a.pott@googlemail.com> | 2015-07-13 12:39:16 +0100 |
commit | 94615a137b1a4d83d0329a53563d5e7bd2265644 (patch) | |
tree | 84fc4e832f3ba5c7571c98a7715722dceb5c4b6a /core/misc | |
parent | 9024fa617c57a2a5fcd2e1026770a19da477a29f (diff) | |
download | drupal-94615a137b1a4d83d0329a53563d5e7bd2265644.tar.gz drupal-94615a137b1a4d83d0329a53563d5e7bd2265644.zip |
Issue #2510104 by pwolanin, nod_, Fabianx, Wim Leers, droplet, Pere Orga: Convert drupalSettings from JavaScript to JSON, to allow for CSP in the future
Diffstat (limited to 'core/misc')
-rw-r--r-- | core/misc/drupal.js | 8 | ||||
-rw-r--r-- | core/misc/drupalSettingsLoader.js | 24 |
2 files changed, 24 insertions, 8 deletions
diff --git a/core/misc/drupal.js b/core/misc/drupal.js index 75f85bbacde..8ef8167b736 100644 --- a/core/misc/drupal.js +++ b/core/misc/drupal.js @@ -12,14 +12,6 @@ */ /** - * Variable generated by Drupal with all the configuration created from PHP. - * - * @global - * - * @var {object} drupalSettings - */ - -/** * Variable generated by Drupal that holds all translated strings from PHP. * * @global diff --git a/core/misc/drupalSettingsLoader.js b/core/misc/drupalSettingsLoader.js new file mode 100644 index 00000000000..ab3911dea88 --- /dev/null +++ b/core/misc/drupalSettingsLoader.js @@ -0,0 +1,24 @@ +/** + * @file + * Parse inline JSON and initialize the drupalSettings global object. + */ + +(function () { + + "use strict"; + + var settingsElement = document.querySelector('script[type="application/json"][data-drupal-selector="drupal-settings-json"]'); + + /** + * Variable generated by Drupal with all the configuration created from PHP. + * + * @global + * + * @type {object} + */ + window.drupalSettings = {}; + + if (settingsElement !== null) { + window.drupalSettings = JSON.parse(settingsElement.textContent); + } +})(); |