-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3085 from hypothesis/open-sidebar-when-annot-frag…
…ment-present (1/3) Open sidebar and set selection when '#annotations' URL fragment is present
- Loading branch information
Showing
12 changed files
with
161 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
var docs = 'https://h.readthedocs.org/en/latest/hacking/customized-embedding.html'; | ||
|
||
/** | ||
* Reads the Hypothesis configuration from the environment. | ||
* | ||
* @param {Window} window_ - The Window object to read config from. | ||
*/ | ||
function config(window_) { | ||
var options = { | ||
app: window_. | ||
document.querySelector('link[type="application/annotator+html"]').href, | ||
}; | ||
|
||
if (window_.hasOwnProperty('hypothesisConfig')) { | ||
if (typeof window_.hypothesisConfig === 'function') { | ||
Object.assign(options, window_.hypothesisConfig()); | ||
} else { | ||
throw new TypeError('hypothesisConfig must be a function, see: ' + docs); | ||
} | ||
} | ||
|
||
var annotFragmentMatch = window_.location.hash.match(/^#annotations:(.*)/); | ||
if (annotFragmentMatch) { | ||
options.annotations = annotFragmentMatch[1]; | ||
} | ||
return options; | ||
} | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
|
||
var config = require('../config'); | ||
|
||
describe('annotator configuration', function () { | ||
var fakeWindowBase = { | ||
document: { | ||
querySelector: sinon.stub().returns({href: 'app.html'}), | ||
}, | ||
location: {hash: ''}, | ||
}; | ||
|
||
it('reads the app src from the link tag', function () { | ||
var linkEl = document.createElement('link'); | ||
linkEl.type = 'application/annotator+html'; | ||
linkEl.href = 'https://test.hypothes.is/app.html'; | ||
document.head.appendChild(linkEl); | ||
assert.deepEqual(config(window), { | ||
app: linkEl.href, | ||
}); | ||
document.head.removeChild(linkEl); | ||
}); | ||
|
||
it('reads the #annotation query fragment', function () { | ||
var fakeWindow = Object.assign({}, fakeWindowBase, { | ||
location: {hash:'#annotations:456'}, | ||
}); | ||
assert.deepEqual(config(fakeWindow), { | ||
app: 'app.html', | ||
annotations: '456', | ||
}); | ||
}); | ||
|
||
it('merges the config from hypothesisConfig()', function () { | ||
var fakeWindow = Object.assign({}, fakeWindowBase, { | ||
hypothesisConfig: function () { | ||
return {firstRun: true}; | ||
}, | ||
}); | ||
assert.deepEqual(config(fakeWindow), { | ||
app: 'app.html', | ||
firstRun: true, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters