Commit 23578e8f authored by Robert Knight's avatar Robert Knight

Merge pull request #2633 from hypothesis/csp-friendly-settings

Make settings loader CSP-compatible
parents f00cd272 3a89d3ac
...@@ -7,18 +7,20 @@ var angular = require('angular'); ...@@ -7,18 +7,20 @@ var angular = require('angular');
* @name settings * @name settings
* *
* @description * @description
* The 'settings' factory exposes shared application settings, read from the * The 'settings' factory exposes shared application settings, read from a
* global variable 'hypothesis.settings' in the app page. * script tag with type "application/json" and id "hypothesis-settings" in the
* app page.
*/ */
// @ngInject // @ngInject
function settings($window) { function settings($document) {
var data = {}; var settingsElement = $document[0].querySelector(
'script[type="application/json"]#hypothesis-settings');
if ($window.hypothesis && $window.hypothesis.settings) { if (settingsElement) {
angular.copy($window.hypothesis.settings, data); return angular.fromJson(settingsElement.textContent);
} }
return data; return {};
} }
module.exports = settings; module.exports = settings;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment