Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
c747a677
Commit
c747a677
authored
Mar 27, 2019
by
Hannah Stepanek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add #annotations:group:GROUP_ID fragment parser
parent
30d967f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
0 deletions
+48
-0
settings.js
src/annotator/config/settings.js
+25
-0
settings-test.js
src/annotator/config/test/settings-test.js
+23
-0
No files found.
src/annotator/config/settings.js
View file @
c747a677
...
...
@@ -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
();
},
...
...
src/annotator/config/test/settings-test.js
View file @
c747a677
...
...
@@ -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'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment