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
a4e57347
Commit
a4e57347
authored
Jun 08, 2017
by
Robert Knight
Committed by
GitHub
Jun 08, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #425 from hypothesis/simplify-reading-query-and-annotations
Simplify reading query and annotations
parents
2a99b84b
983d75cd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
35 deletions
+34
-35
index.js
src/annotator/config/index.js
+11
-18
index-test.js
src/annotator/config/test/index-test.js
+23
-17
No files found.
src/annotator/config/index.js
View file @
a4e57347
...
...
@@ -11,30 +11,23 @@ var sharedSettings = require('../../shared/settings');
function
configFrom
(
window_
)
{
var
config
=
{
app
:
settings
.
app
(
window_
.
document
),
// Extract the default annotation ID or query from the URL.
//
// The Chrome extension or proxy may already have provided this config via
// a tag injected into the DOM, which avoids the problem where the page's
// JS rewrites the URL before Hypothesis loads.
//
// In environments where the config has not been injected into the DOM,
// we try to retrieve it from the URL here.
query
:
settings
.
query
(
window_
.
location
.
href
),
annotations
:
settings
.
annotations
(
window_
.
location
.
href
),
};
var
chromeExt
=
'chrome-extension://'
;
var
mozExt
=
'moz-extension://'
;
var
edgeExt
=
'ms-browser-extension://'
;
// Extract the default annotation ID or query from the URL.
//
// The Chrome extension or proxy may already have provided this config
// via a tag injected into the DOM, which avoids the problem where the page's
// JS rewrites the URL before Hypothesis loads.
//
// In environments where the config has not been injected into the DOM,
// we try to retrieve it from the URL here.
var
query
=
settings
.
query
(
window_
.
location
.
href
);
if
(
query
)
{
config
.
query
=
query
;
}
else
{
var
annotations
=
settings
.
annotations
(
window_
.
location
.
href
);
if
(
annotations
)
{
config
.
annotations
=
annotations
;
}
}
// If the client is injected by the browser extension, ignore
// the rest of the host page config.
if
(
config
.
app
.
indexOf
(
chromeExt
)
===
0
||
...
...
src/annotator/config/test/index-test.js
View file @
a4e57347
...
...
@@ -30,8 +30,8 @@ describe('annotator.config', function() {
beforeEach
(
'reset fakeSettings'
,
function
()
{
fakeSettings
.
app
=
sinon
.
stub
().
returns
(
'IFRAME_URL'
);
fakeSettings
.
annotations
=
sinon
.
stub
();
fakeSettings
.
query
=
sinon
.
stub
();
fakeSettings
.
annotations
=
sinon
.
stub
()
.
returns
(
null
)
;
fakeSettings
.
query
=
sinon
.
stub
()
.
returns
(
null
)
;
fakeSettings
.
configFuncSettingsFrom
=
sinon
.
stub
().
returns
({});
});
...
...
@@ -178,8 +178,7 @@ describe('annotator.config', function() {
configFrom
(
fakeWindow
());
assert
.
calledOnce
(
fakeSettings
.
annotations
);
assert
.
calledWithExactly
(
fakeSettings
.
annotations
,
'LOCATION_HREF'
);
assert
.
calledWithExactly
(
fakeSettings
.
annotations
,
'LOCATION_HREF'
);
});
context
(
"when there's a direct-linked annotation ID"
,
function
()
{
...
...
@@ -193,24 +192,31 @@ describe('annotator.config', function() {
});
context
(
"when there's no direct-linked annotation ID"
,
function
()
{
it
(
"doesn't add any .annotations setting to the config"
,
function
()
{
assert
.
is
False
(
configFrom
(
fakeWindow
()).
hasOwnProperty
(
'annotations'
)
);
it
(
'sets config.annotations to null'
,
function
()
{
assert
.
is
Null
(
configFrom
(
fakeWindow
()).
annotations
);
});
});
context
(
"when there's no annotations query"
,
function
()
{
it
(
"doesn't add any .query setting to the config"
,
function
()
{
assert
.
isFalse
(
configFrom
(
fakeWindow
()).
hasOwnProperty
(
'query'
));
});
it
(
"extracts the query from the parent page's URL"
,
function
()
{
configFrom
(
fakeWindow
());
assert
.
calledOnce
(
fakeSettings
.
query
);
assert
.
calledWithExactly
(
fakeSettings
.
query
,
'LOCATION_HREF'
);
});
context
(
"when there's no annotations query"
,
function
()
{
it
(
'sets config.query to null'
,
function
()
{
assert
.
isNull
(
configFrom
(
fakeWindow
()).
query
);
});
});
context
(
"when there's an annotations query"
,
function
()
{
beforeEach
(
function
()
{
fakeSettings
.
query
.
returns
(
'QUERY'
);
});
context
(
"when there's an annotations query"
,
function
()
{
beforeEach
(
function
()
{
fakeSettings
.
query
.
returns
(
'QUERY'
);
});
it
(
'adds the query to the config'
,
function
()
{
assert
.
equal
(
configFrom
(
fakeWindow
()).
query
,
'QUERY'
);
});
it
(
'adds the query to the config'
,
function
()
{
assert
.
equal
(
configFrom
(
fakeWindow
()).
query
,
'QUERY'
);
});
});
...
...
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