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
77867094
Commit
77867094
authored
Jan 15, 2020
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert src/annotator/util to ES modules
parent
cbdaaf0f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
35 deletions
+15
-35
frame-util.js
src/annotator/util/frame-util.js
+6
-15
observable.js
src/annotator/util/observable.js
+7
-14
url.js
src/annotator/util/url.js
+2
-6
No files found.
src/annotator/util/frame-util.js
View file @
77867094
...
@@ -4,18 +4,18 @@
...
@@ -4,18 +4,18 @@
* @param {Element} container
* @param {Element} container
* @return {HTMLIFrameElement[]}
* @return {HTMLIFrameElement[]}
*/
*/
function
findFrames
(
container
)
{
export
function
findFrames
(
container
)
{
const
frames
=
Array
.
from
(
container
.
getElementsByTagName
(
'iframe'
));
const
frames
=
Array
.
from
(
container
.
getElementsByTagName
(
'iframe'
));
return
frames
.
filter
(
shouldEnableAnnotation
);
return
frames
.
filter
(
shouldEnableAnnotation
);
}
}
// Check if the iframe has already been injected
// Check if the iframe has already been injected
function
hasHypothesis
(
iframe
)
{
export
function
hasHypothesis
(
iframe
)
{
return
iframe
.
contentWindow
.
__hypothesis_frame
===
true
;
return
iframe
.
contentWindow
.
__hypothesis_frame
===
true
;
}
}
// Inject embed.js into the iframe
// Inject embed.js into the iframe
function
injectHypothesis
(
iframe
,
scriptUrl
,
config
)
{
export
function
injectHypothesis
(
iframe
,
scriptUrl
,
config
)
{
const
configElement
=
document
.
createElement
(
'script'
);
const
configElement
=
document
.
createElement
(
'script'
);
configElement
.
className
=
'js-hypothesis-config'
;
configElement
.
className
=
'js-hypothesis-config'
;
configElement
.
type
=
'application/json'
;
configElement
.
type
=
'application/json'
;
...
@@ -32,7 +32,7 @@ function injectHypothesis(iframe, scriptUrl, config) {
...
@@ -32,7 +32,7 @@ function injectHypothesis(iframe, scriptUrl, config) {
}
}
// Check if we can access this iframe's document
// Check if we can access this iframe's document
function
isAccessible
(
iframe
)
{
export
function
isAccessible
(
iframe
)
{
try
{
try
{
return
!!
iframe
.
contentDocument
;
return
!!
iframe
.
contentDocument
;
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -63,7 +63,7 @@ function shouldEnableAnnotation(iframe) {
...
@@ -63,7 +63,7 @@ function shouldEnableAnnotation(iframe) {
return
isNotClientFrame
&&
enabled
;
return
isNotClientFrame
&&
enabled
;
}
}
function
isDocumentReady
(
iframe
,
callback
)
{
export
function
isDocumentReady
(
iframe
,
callback
)
{
if
(
iframe
.
contentDocument
.
readyState
===
'loading'
)
{
if
(
iframe
.
contentDocument
.
readyState
===
'loading'
)
{
iframe
.
contentDocument
.
addEventListener
(
'DOMContentLoaded'
,
function
()
{
iframe
.
contentDocument
.
addEventListener
(
'DOMContentLoaded'
,
function
()
{
callback
();
callback
();
...
@@ -73,7 +73,7 @@ function isDocumentReady(iframe, callback) {
...
@@ -73,7 +73,7 @@ function isDocumentReady(iframe, callback) {
}
}
}
}
function
isLoaded
(
iframe
,
callback
)
{
export
function
isLoaded
(
iframe
,
callback
)
{
if
(
iframe
.
contentDocument
.
readyState
!==
'complete'
)
{
if
(
iframe
.
contentDocument
.
readyState
!==
'complete'
)
{
iframe
.
addEventListener
(
'load'
,
function
()
{
iframe
.
addEventListener
(
'load'
,
function
()
{
callback
();
callback
();
...
@@ -82,12 +82,3 @@ function isLoaded(iframe, callback) {
...
@@ -82,12 +82,3 @@ function isLoaded(iframe, callback) {
callback
();
callback
();
}
}
}
}
module
.
exports
=
{
findFrames
:
findFrames
,
hasHypothesis
:
hasHypothesis
,
injectHypothesis
:
injectHypothesis
,
isAccessible
:
isAccessible
,
isLoaded
:
isLoaded
,
isDocumentReady
:
isDocumentReady
,
};
src/annotator/util/observable.js
View file @
77867094
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
* values using the Observable API.
* values using the Observable API.
*/
*/
const
Observable
=
require
(
'zen-observable'
)
;
import
Observable
from
'zen-observable'
;
/**
/**
* Returns an observable of events emitted by a DOM event source
* Returns an observable of events emitted by a DOM event source
...
@@ -12,7 +12,7 @@ const Observable = require('zen-observable');
...
@@ -12,7 +12,7 @@ const Observable = require('zen-observable');
* @param {EventTarget} src - The event source.
* @param {EventTarget} src - The event source.
* @param {Array<string>} eventNames - List of events to subscribe to
* @param {Array<string>} eventNames - List of events to subscribe to
*/
*/
function
listen
(
src
,
eventNames
)
{
export
function
listen
(
src
,
eventNames
)
{
return
new
Observable
(
function
(
observer
)
{
return
new
Observable
(
function
(
observer
)
{
const
onNext
=
function
(
event
)
{
const
onNext
=
function
(
event
)
{
observer
.
next
(
event
);
observer
.
next
(
event
);
...
@@ -33,7 +33,7 @@ function listen(src, eventNames) {
...
@@ -33,7 +33,7 @@ function listen(src, eventNames) {
/**
/**
* Delay events from a source Observable by `delay` ms.
* Delay events from a source Observable by `delay` ms.
*/
*/
function
delay
(
delay
,
src
)
{
export
function
delay
(
delay
,
src
)
{
return
new
Observable
(
function
(
obs
)
{
return
new
Observable
(
function
(
obs
)
{
let
timeouts
=
[];
let
timeouts
=
[];
const
sub
=
src
.
subscribe
({
const
sub
=
src
.
subscribe
({
...
@@ -62,7 +62,7 @@ function delay(delay, src) {
...
@@ -62,7 +62,7 @@ function delay(delay, src) {
* @param {Observable<T>} src
* @param {Observable<T>} src
* @return {Observable<T>}
* @return {Observable<T>}
*/
*/
function
buffer
(
delay
,
src
)
{
export
function
buffer
(
delay
,
src
)
{
return
new
Observable
(
function
(
obs
)
{
return
new
Observable
(
function
(
obs
)
{
let
lastValue
;
let
lastValue
;
let
timeout
;
let
timeout
;
...
@@ -92,7 +92,7 @@ function buffer(delay, src) {
...
@@ -92,7 +92,7 @@ function buffer(delay, src) {
* @param {Array<Observable>} sources
* @param {Array<Observable>} sources
* @return Observable
* @return Observable
*/
*/
function
merge
(
sources
)
{
export
function
merge
(
sources
)
{
return
new
Observable
(
function
(
obs
)
{
return
new
Observable
(
function
(
obs
)
{
const
subs
=
sources
.
map
(
function
(
src
)
{
const
subs
=
sources
.
map
(
function
(
src
)
{
return
src
.
subscribe
({
return
src
.
subscribe
({
...
@@ -111,7 +111,7 @@ function merge(sources) {
...
@@ -111,7 +111,7 @@ function merge(sources) {
}
}
/** Drop the first `n` events from the `src` Observable. */
/** Drop the first `n` events from the `src` Observable. */
function
drop
(
src
,
n
)
{
export
function
drop
(
src
,
n
)
{
let
count
=
0
;
let
count
=
0
;
return
src
.
filter
(
function
()
{
return
src
.
filter
(
function
()
{
++
count
;
++
count
;
...
@@ -119,11 +119,4 @@ function drop(src, n) {
...
@@ -119,11 +119,4 @@ function drop(src, n) {
});
});
}
}
module
.
exports
=
{
export
{
Observable
};
buffer
:
buffer
,
delay
:
delay
,
drop
:
drop
,
listen
:
listen
,
merge
:
merge
,
Observable
:
Observable
,
};
src/annotator/util/url.js
View file @
77867094
const
baseURI
=
require
(
'document-base-uri'
)
;
import
baseURI
from
'document-base-uri'
;
/**
/**
* Return a normalized version of a URI.
* Return a normalized version of a URI.
...
@@ -9,7 +9,7 @@ const baseURI = require('document-base-uri');
...
@@ -9,7 +9,7 @@ const baseURI = require('document-base-uri');
* @param {string} [base] - Base URL to resolve relative to. Defaults to
* @param {string} [base] - Base URL to resolve relative to. Defaults to
* the document's base URL.
* the document's base URL.
*/
*/
function
normalizeURI
(
uri
,
base
=
baseURI
)
{
export
function
normalizeURI
(
uri
,
base
=
baseURI
)
{
const
absUrl
=
new
URL
(
uri
,
base
).
href
;
const
absUrl
=
new
URL
(
uri
,
base
).
href
;
// Remove the fragment identifier.
// Remove the fragment identifier.
...
@@ -18,7 +18,3 @@ function normalizeURI(uri, base = baseURI) {
...
@@ -18,7 +18,3 @@ function normalizeURI(uri, base = baseURI) {
// See https://github.com/hypothesis/h/issues/3471#issuecomment-226713750
// See https://github.com/hypothesis/h/issues/3471#issuecomment-226713750
return
absUrl
.
toString
().
replace
(
/#.*/
,
''
);
return
absUrl
.
toString
().
replace
(
/#.*/
,
''
);
}
}
module
.
exports
=
{
normalizeURI
,
};
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