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
6ed8c93b
Commit
6ed8c93b
authored
Feb 04, 2022
by
Eduardo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply suggestions from code review
Co-authored-by:
Robert Knight
<
robertknight@gmail.com
>
parent
1b8e8a4d
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
31 deletions
+29
-31
hypothesis-injector.js
src/annotator/hypothesis-injector.js
+1
-1
index.js
src/annotator/index.js
+23
-26
index.js
src/annotator/integrations/index.js
+1
-1
pdf.js
src/annotator/integrations/pdf.js
+1
-1
vitalsource.js
src/annotator/integrations/vitalsource.js
+2
-1
hypothesis-injector-test.js
src/annotator/test/integration/hypothesis-injector-test.js
+1
-1
No files found.
src/annotator/hypothesis-injector.js
View file @
6ed8c93b
...
@@ -52,7 +52,7 @@ function hasHypothesis(iframe) {
...
@@ -52,7 +52,7 @@ function hasHypothesis(iframe) {
/**
/**
* Inject Hypothesis client into a frame.
* Inject Hypothesis client into a frame.
*
*
* IMPORTANT: This method requires that the iframe is
"accessible"
* IMPORTANT: This method requires that the iframe is
same-origin
* (frame.contentDocument|contentWindow is not null).
* (frame.contentDocument|contentWindow is not null).
*
*
* This waits for the frame to finish loading before injecting the client.
* This waits for the frame to finish loading before injecting the client.
...
...
src/annotator/index.js
View file @
6ed8c93b
...
@@ -21,6 +21,8 @@ import { Notebook } from './notebook';
...
@@ -21,6 +21,8 @@ import { Notebook } from './notebook';
import
{
Sidebar
}
from
'./sidebar'
;
import
{
Sidebar
}
from
'./sidebar'
;
import
{
EventBus
}
from
'./util/emitter'
;
import
{
EventBus
}
from
'./util/emitter'
;
/** @typedef {import('../types/annotator').Destroyable} Destroyable */
// Look up the URL of the sidebar. This element is added to the page by the
// Look up the URL of the sidebar. This element is added to the page by the
// boot script before the "annotator" bundle loads.
// boot script before the "annotator" bundle loads.
const
sidebarLinkElement
=
/** @type {HTMLLinkElement} */
(
const
sidebarLinkElement
=
/** @type {HTMLLinkElement} */
(
...
@@ -46,51 +48,46 @@ function init() {
...
@@ -46,51 +48,46 @@ function init() {
const
hostFrame
=
annotatorConfig
.
subFrameIdentifier
?
window
.
parent
:
window
;
const
hostFrame
=
annotatorConfig
.
subFrameIdentifier
?
window
.
parent
:
window
;
/** @type {Sidebar|undefined} */
/** @type {Destroyable[]} */
let
sidebar
;
const
destroyables
=
[];
/** @type {Notebook|undefined} */
let
notebook
;
/** @type {PortProvider|undefined} */
let
portProvider
;
if
(
hostFrame
===
window
)
{
if
(
hostFrame
===
window
)
{
const
sidebarConfig
=
getConfig
(
'sidebar'
);
const
sidebarConfig
=
getConfig
(
'sidebar'
);
const
hypothesisAppsOrigin
=
new
URL
(
sidebarConfig
.
sidebarAppUrl
).
origin
;
const
hypothesisAppsOrigin
=
new
URL
(
sidebarConfig
.
sidebarAppUrl
).
origin
;
portProvider
=
new
PortProvider
(
hypothesisAppsOrigin
);
const
portProvider
=
new
PortProvider
(
hypothesisAppsOrigin
);
const
eventBus
=
new
EventBus
();
const
eventBus
=
new
EventBus
();
sidebar
=
new
Sidebar
(
document
.
body
,
eventBus
,
sidebarConfig
);
const
sidebar
=
new
Sidebar
(
document
.
body
,
eventBus
,
sidebarConfig
);
notebook
=
new
Notebook
(
document
.
body
,
eventBus
,
getConfig
(
'notebook'
));
const
notebook
=
new
Notebook
(
document
.
body
,
eventBus
,
getConfig
(
'notebook'
)
);
portProvider
.
on
(
'frameConnected'
,
(
source
,
port
)
=>
portProvider
.
on
(
'frameConnected'
,
(
source
,
port
)
=>
/** @type {Sidebar} */
(
sidebar
).
onFrameConnected
(
source
,
port
)
/** @type {Sidebar} */
(
sidebar
).
onFrameConnected
(
source
,
port
)
);
);
destroyables
.
push
(
portProvider
,
sidebar
,
notebook
);
}
}
/** @type {Guest|undefined} */
let
guest
;
/** @type {VitalSourceInjector|undefined} */
let
vitalSourceInjector
;
/** @type {HypothesisInjector|undefined} */
let
hypothesisInjector
;
const
vsFrameRole
=
vitalSourceFrameRole
();
const
vsFrameRole
=
vitalSourceFrameRole
();
if
(
vsFrameRole
===
'container'
)
{
if
(
vsFrameRole
===
'container'
)
{
vitalSourceInjector
=
new
VitalSourceInjector
(
annotatorConfig
);
const
vitalSourceInjector
=
new
VitalSourceInjector
(
annotatorConfig
);
destroyables
.
push
(
vitalSourceInjector
);
}
else
{
}
else
{
// Set up automatic and integration-triggered injection of client into
// Set up automatic injection of the client into iframes in this frame.
// iframes in this frame.
const
hypothesisInjector
=
new
HypothesisInjector
(
hypothesisInjector
=
new
HypothesisInjector
(
document
.
body
,
annotatorConfig
);
document
.
body
,
annotatorConfig
);
// Create the guest that handles creating annotations and displaying highlights.
// Create the guest that handles creating annotations and displaying highlights.
guest
=
new
Guest
(
document
.
body
,
annotatorConfig
,
hostFrame
);
const
guest
=
new
Guest
(
document
.
body
,
annotatorConfig
,
hostFrame
);
destroyables
.
push
(
hypothesisInjector
,
guest
);
}
}
sidebarLinkElement
.
addEventListener
(
'destroy'
,
()
=>
{
sidebarLinkElement
.
addEventListener
(
'destroy'
,
()
=>
{
portProvider
?.
destroy
();
destroyables
.
forEach
(
instance
=>
instance
.
destroy
());
sidebar
?.
destroy
();
notebook
?.
destroy
();
vitalSourceInjector
?.
destroy
();
hypothesisInjector
?.
destroy
();
guest
?.
destroy
();
// Remove all the `<link>`, `<script>` and `<style>` elements added to the
// Remove all the `<link>`, `<script>` and `<style>` elements added to the
// page by the boot script.
// page by the boot script.
...
...
src/annotator/integrations/index.js
View file @
6ed8c93b
...
@@ -14,7 +14,7 @@ import {
...
@@ -14,7 +14,7 @@ import {
* Create the integration that handles document-type specific aspects of
* Create the integration that handles document-type specific aspects of
* guest functionality.
* guest functionality.
*
*
* @param {
Pick<Annotator, 'anchor'|'anchors'>
} annotator
* @param {
Annotator
} annotator
* @return {Integration}
* @return {Integration}
*/
*/
export
function
createIntegration
(
annotator
)
{
export
function
createIntegration
(
annotator
)
{
...
...
src/annotator/integrations/pdf.js
View file @
6ed8c93b
...
@@ -61,7 +61,7 @@ export function isPDF() {
...
@@ -61,7 +61,7 @@ export function isPDF() {
*/
*/
export
class
PDFIntegration
{
export
class
PDFIntegration
{
/**
/**
* @param {
Pick<Annotator, 'anchor'|'anchors'>
} annotator
* @param {
Annotator
} annotator
* @param {object} options
* @param {object} options
* @param {number} [options.reanchoringMaxWait] - Max time to wait for
* @param {number} [options.reanchoringMaxWait] - Max time to wait for
* re-anchoring to complete when scrolling to an un-rendered page.
* re-anchoring to complete when scrolling to an un-rendered page.
...
...
src/annotator/integrations/vitalsource.js
View file @
6ed8c93b
...
@@ -39,7 +39,8 @@ export function vitalSourceFrameRole(window_ = window) {
...
@@ -39,7 +39,8 @@ export function vitalSourceFrameRole(window_ = window) {
}
}
/**
/**
* Observe the book content iframe and load the client into this frame.
* VitalSourceInjector runs in the book container frame and loads the client into
* book content frames.
*/
*/
export
class
VitalSourceInjector
{
export
class
VitalSourceInjector
{
/**
/**
...
...
src/annotator/test/integration/hypothesis-injector-test.js
View file @
6ed8c93b
...
@@ -88,7 +88,7 @@ describe('HypothesisInjector integration test', () => {
...
@@ -88,7 +88,7 @@ describe('HypothesisInjector integration test', () => {
it
(
'copies client asset locations from host frame'
,
async
()
=>
{
it
(
'copies client asset locations from host frame'
,
async
()
=>
{
hostJSONConfig
=
{
hostJSONConfig
=
{
clientUrl
:
'chrome-extension://
/o
'
,
clientUrl
:
'chrome-extension://
abc/client/build/boot.js
'
,
assetRoot
:
'chrome-extension://abc/client'
,
assetRoot
:
'chrome-extension://abc/client'
,
notebookAppUrl
:
'chrome-extension://abc/client/notebook.html'
,
notebookAppUrl
:
'chrome-extension://abc/client/notebook.html'
,
sidebarAppUrl
:
'chrome-extension://abc/client/sidebar.html'
,
sidebarAppUrl
:
'chrome-extension://abc/client/sidebar.html'
,
...
...
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