Commit 7d201fb0 authored by Eduardo Sanz García's avatar Eduardo Sanz García Committed by Eduardo

Add option to ignore other configuration

If `ignoreOtherConfiguration` is used JSON configurations should be
ignored.

Part of https://github.com/hypothesis/viahtml/pull/192
parent 2b18c185
import { parseJsonConfig } from '../../boot/parse-json-config'; import { parseJsonConfig } from '../../boot/parse-json-config';
import { toBoolean } from '../../shared/type-coercions';
import configFuncSettingsFrom from './config-func-settings-from'; import configFuncSettingsFrom from './config-func-settings-from';
import isBrowserExtension from './is-browser-extension'; import isBrowserExtension from './is-browser-extension';
...@@ -20,9 +21,18 @@ import isBrowserExtension from './is-browser-extension'; ...@@ -20,9 +21,18 @@ import isBrowserExtension from './is-browser-extension';
* @return {SettingsGetters} * @return {SettingsGetters}
*/ */
export default function settingsFrom(window_) { export default function settingsFrom(window_) {
const jsonConfigs = parseJsonConfig(window_.document); // Prioritize the `window.hypothesisConfig` function over the JSON format
// Via uses `window.hypothesisConfig` and makes it non-configurable and non-writable.
// In addition, Via sets the `ignoreOtherConfiguration` option to prevent configuration merging.
const configFuncSettings = configFuncSettingsFrom(window_); const configFuncSettings = configFuncSettingsFrom(window_);
let jsonConfigs;
if (toBoolean(configFuncSettings.ignoreOtherConfiguration)) {
jsonConfigs = {};
} else {
jsonConfigs = parseJsonConfig(window_.document);
}
/** /**
* Return the href of the first annotator link in the given * Return the href of the first annotator link in the given
* document with this `rel` attribute. * document with this `rel` attribute.
......
...@@ -580,9 +580,18 @@ describe('annotator/config/settingsFrom', () => { ...@@ -580,9 +580,18 @@ describe('annotator/config/settingsFrom', () => {
specify: 'it returns setting values from window.hypothesisConfig()', specify: 'it returns setting values from window.hypothesisConfig()',
isBrowserExtension: false, isBrowserExtension: false,
configFuncSettings: { foo: 'configFuncValue' }, configFuncSettings: { foo: 'configFuncValue' },
jsonSettings: {}, jsonSettings: { foo: 'ignored' }, // hypothesisConfig() overrides js-hypothesis-config
expected: 'configFuncValue', expected: 'configFuncValue',
}, },
{
when: 'the client is embedded in a web page',
specify:
'it ignores settings from js-hypothesis-config if `ignoreOtherConfiguration` is present',
isBrowserExtension: false,
configFuncSettings: { ignoreOtherConfiguration: '1' },
jsonSettings: { foo: 'ignored' },
expected: null,
},
{ {
when: 'the client is embedded in a web page', when: 'the client is embedded in a web page',
specify: 'it returns setting values from js-hypothesis-config objects', specify: 'it returns setting values from js-hypothesis-config objects',
......
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