Commit c747a677 authored by Hannah Stepanek's avatar Hannah Stepanek

Add #annotations:group:GROUP_ID fragment parser

parent 30d967f5
......@@ -102,6 +102,28 @@ function settingsFrom(window_) {
return jsonConfigs.annotations || annotationsFromURL();
}
/**
* Return the `#annotations:group:*` ID from the given URL's fragment.
*
* If the URL contains a `#annotations:group:<GROUP_ID>` fragment then return
* the group ID extracted from the fragment. Otherwise return `null`.
*
* @return {string|null} - The extracted ID, or null.
*/
function group() {
function groupFromURL() {
const groupFragmentMatch = window_.location.href.match(
/#annotations:group:([A-Za-z0-9_-]+)$/
);
if (groupFragmentMatch) {
return groupFragmentMatch[1];
}
return null;
}
return jsonConfigs.group || groupFromURL();
}
function showHighlights() {
let showHighlights_ = hostPageSetting('showHighlights');
......@@ -179,6 +201,9 @@ function settingsFrom(window_) {
get clientUrl() {
return clientUrl();
},
get group() {
return group();
},
get showHighlights() {
return showHighlights();
},
......
......@@ -289,6 +289,29 @@ describe('annotator.config.settingsFrom', function() {
});
});
[
{
description:
"returns an object with the group ID when there's a valid #annotations:group:<ID> fragment",
url: 'http://localhost:3000#annotations:group:alphanum3ric_-only',
returns: 'alphanum3ric_-only',
},
{
description: "returns null when there's a non-alphanumeric group ID",
url: 'http://localhost:3000#annotations:group:not%20alphanumeric',
returns: null,
},
{
description: "return null when there's an empty group ID",
url: 'http://localhost:3000#annotations:group:',
returns: null,
},
].forEach(test => {
it(test.description, () => {
assert.deepEqual(settingsFrom(fakeWindow(test.url)).group, test.returns);
});
});
describe('#query', function() {
context(
'when the host page has a js-hypothesis-config with a query setting',
......
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