summaryrefslogtreecommitdiffstatshomepage
path: root/core/misc/drupalSettingsLoader.js
diff options
context:
space:
mode:
authorAlex Pott <alex.a.pott@googlemail.com>2015-07-13 12:39:16 +0100
committerAlex Pott <alex.a.pott@googlemail.com>2015-07-13 12:39:16 +0100
commit94615a137b1a4d83d0329a53563d5e7bd2265644 (patch)
tree84fc4e832f3ba5c7571c98a7715722dceb5c4b6a /core/misc/drupalSettingsLoader.js
parent9024fa617c57a2a5fcd2e1026770a19da477a29f (diff)
downloaddrupal-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/drupalSettingsLoader.js')
-rw-r--r--core/misc/drupalSettingsLoader.js24
1 files changed, 24 insertions, 0 deletions
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);
+ }
+})();