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
8bc370c8
Unverified
Commit
8bc370c8
authored
Jan 16, 2020
by
Robert Knight
Committed by
GitHub
Jan 16, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1680 from hypothesis/convert-annotator-to-es-modules
Convert most modules in src/annotator to ES modules
parents
d78c29cd
fac2a28d
Changes
33
Show whitespace changes
Inline
Side-by-side
Showing
33 changed files
with
95 additions
and
131 deletions
+95
-131
pdf.js
src/annotator/anchoring/pdf.js
+9
-14
fake-pdf-viewer-application.js
src/annotator/anchoring/test/fake-pdf-viewer-application.js
+2
-4
index.js
src/annotator/anchoring/test/html-baselines/index.js
+1
-1
html-test.js
src/annotator/anchoring/test/html-test.js
+5
-5
pdf-test.js
src/annotator/anchoring/test/pdf-test.js
+4
-3
text-position-test.js
src/annotator/anchoring/test/text-position-test.js
+1
-1
types-test.js
src/annotator/anchoring/test/types-test.js
+1
-1
text-position.js
src/annotator/anchoring/text-position.js
+1
-5
config-func-settings-from.js
src/annotator/config/config-func-settings-from.js
+1
-3
index.js
src/annotator/config/index.js
+2
-4
is-browser-extension.js
src/annotator/config/is-browser-extension.js
+1
-3
settings.js
src/annotator/config/settings.js
+5
-6
config-func-settings-from-test.js
src/annotator/config/test/config-func-settings-from-test.js
+1
-1
index-test.js
src/annotator/config/test/index-test.js
+2
-2
is-browser-extension-test.js
src/annotator/config/test/is-browser-extension-test.js
+1
-1
settings-test.js
src/annotator/config/test/settings-test.js
+2
-2
index.js
src/annotator/index.js
+17
-12
document.js
src/annotator/plugin/document.js
+4
-6
pdf-metadata.js
src/annotator/plugin/pdf-metadata.js
+2
-4
pdf.coffee
src/annotator/plugin/pdf.coffee
+1
-1
document-test.js
src/annotator/plugin/test/document-test.js
+3
-3
pdf-metadata-test.js
src/annotator/plugin/test/pdf-metadata-test.js
+1
-1
toolbar-test.js
src/annotator/plugin/test/toolbar-test.js
+2
-2
adder-test.js
src/annotator/test/adder-test.js
+1
-1
annotation-counts-test.js
src/annotator/test/annotation-counts-test.js
+1
-1
annotation-sync-test.js
src/annotator/test/annotation-sync-test.js
+2
-2
features-test.js
src/annotator/test/features-test.js
+3
-3
range-util-test.js
src/annotator/test/range-util-test.js
+1
-1
selections-test.js
src/annotator/test/selections-test.js
+2
-2
sidebar-trigger-test.js
src/annotator/test/sidebar-trigger-test.js
+1
-1
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/anchoring/pdf.js
View file @
8bc370c8
/* global PDFViewerApplication */
/* global PDFViewerApplication */
const
seek
=
require
(
'dom-seek'
)
;
import
seek
from
'dom-seek'
;
// `dom-node-iterator` polyfills optional arguments of `createNodeIterator`
// `dom-node-iterator` polyfills optional arguments of `createNodeIterator`
// and properties of the returned `NodeIterator` for IE 11 compatibility.
// and properties of the returned `NodeIterator` for IE 11 compatibility.
const
createNodeIterator
=
require
(
'dom-node-iterator/polyfill'
)();
const
createNodeIterator
=
require
(
'dom-node-iterator/polyfill'
)();
const
xpathRange
=
require
(
'./range'
);
import
RenderingStates
from
'../pdfjs-rendering-states'
;
const
RenderingStates
=
require
(
'../pdfjs-rendering-states'
);
const
{
TextPositionAnchor
,
TextQuoteAnchor
}
=
require
(
'./types'
);
import
xpathRange
from
'./range'
;
const
{
toRange
:
textPositionToRange
}
=
require
(
'./text-position'
);
import
{
toRange
as
textPositionToRange
}
from
'./text-position'
;
import
{
TextPositionAnchor
,
TextQuoteAnchor
}
from
'./types'
;
// Caches for performance.
// Caches for performance.
...
@@ -342,7 +343,7 @@ function prioritizePages(position) {
...
@@ -342,7 +343,7 @@ function prioritizePages(position) {
* @param {Array} selectors - Selector objects to anchor
* @param {Array} selectors - Selector objects to anchor
* @return {Promise<Range>}
* @return {Promise<Range>}
*/
*/
function
anchor
(
root
,
selectors
)
{
export
function
anchor
(
root
,
selectors
)
{
const
position
=
selectors
.
find
(
s
=>
s
.
type
===
'TextPositionSelector'
);
const
position
=
selectors
.
find
(
s
=>
s
.
type
===
'TextPositionSelector'
);
const
quote
=
selectors
.
find
(
s
=>
s
.
type
===
'TextQuoteSelector'
);
const
quote
=
selectors
.
find
(
s
=>
s
.
type
===
'TextQuoteSelector'
);
...
@@ -406,7 +407,7 @@ function anchor(root, selectors) {
...
@@ -406,7 +407,7 @@ function anchor(root, selectors) {
* `toSelector` methods.
* `toSelector` methods.
* @return {Promise<[TextPositionSelector, TextQuoteSelector]>}
* @return {Promise<[TextPositionSelector, TextQuoteSelector]>}
*/
*/
function
describe
(
root
,
range
,
options
=
{})
{
export
function
describe
(
root
,
range
,
options
=
{})
{
const
normalizedRange
=
new
xpathRange
.
BrowserRange
(
range
).
normalize
();
const
normalizedRange
=
new
xpathRange
.
BrowserRange
(
range
).
normalize
();
const
startTextLayer
=
getNodeTextLayer
(
normalizedRange
.
start
);
const
startTextLayer
=
getNodeTextLayer
(
normalizedRange
.
start
);
...
@@ -461,13 +462,7 @@ function describe(root, range, options = {}) {
...
@@ -461,13 +462,7 @@ function describe(root, range, options = {}) {
*
*
* This exists mainly as a helper for use in tests.
* This exists mainly as a helper for use in tests.
*/
*/
function
purgeCache
()
{
export
function
purgeCache
()
{
pageTextCache
=
{};
pageTextCache
=
{};
quotePositionCache
=
{};
quotePositionCache
=
{};
}
}
module
.
exports
=
{
anchor
,
describe
,
purgeCache
,
};
src/annotator/anchoring/test/fake-pdf-viewer-application.js
View file @
8bc370c8
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
* each of the relevant classes in PDF.js.
* each of the relevant classes in PDF.js.
*/
*/
const
RenderingStates
=
require
(
'../../pdfjs-rendering-states'
)
;
import
RenderingStates
from
'../../pdfjs-rendering-states'
;
/**
/**
* Create the DOM structure for a page which matches the structure produced by
* Create the DOM structure for a page which matches the structure produced by
...
@@ -197,7 +197,7 @@ class FakePDFViewer {
...
@@ -197,7 +197,7 @@ class FakePDFViewer {
*
*
* The original is defined at https://github.com/mozilla/pdf.js/blob/master/web/app.js
* The original is defined at https://github.com/mozilla/pdf.js/blob/master/web/app.js
*/
*/
class
FakePDFViewerApplication
{
export
default
class
FakePDFViewerApplication
{
/**
/**
* @param {Options} options
* @param {Options} options
*/
*/
...
@@ -215,5 +215,3 @@ class FakePDFViewerApplication {
...
@@ -215,5 +215,3 @@ class FakePDFViewerApplication {
this
.
pdfViewer
.
dispose
();
this
.
pdfViewer
.
dispose
();
}
}
}
}
module
.
exports
=
FakePDFViewerApplication
;
src/annotator/anchoring/test/html-baselines/index.js
View file @
8bc370c8
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
// them as `<fixture name>.json` in this directory
// them as `<fixture name>.json` in this directory
// 4. Add an entry to the fixture list below.
// 4. Add an entry to the fixture list below.
module
.
exports
=
[
export
default
[
{
{
name
:
'Minimal Document'
,
name
:
'Minimal Document'
,
html
:
require
(
'./minimal.html'
),
html
:
require
(
'./minimal.html'
),
...
...
src/annotator/anchoring/test/html-test.js
View file @
8bc370c8
const
html
=
require
(
'../html'
);
import
{
toResult
}
from
'../../../shared/test/promise-util'
;
import
*
as
html
from
'../html'
;
const
{
toResult
}
=
require
(
'../../../shared/test/promise-util'
)
;
import
fixture
from
'./html-anchoring-fixture.html'
;
const
fixture
=
require
(
'./html-anchoring-fixture.html'
)
;
import
htmlBaselines
from
'./html-baselines'
;
/** Return all text node children of `container`. */
/** Return all text node children of `container`. */
function
textNodes
(
container
)
{
function
textNodes
(
container
)
{
...
@@ -419,7 +420,6 @@ describe('HTML anchoring', function() {
...
@@ -419,7 +420,6 @@ describe('HTML anchoring', function() {
});
});
describe
(
'Web page baselines'
,
function
()
{
describe
(
'Web page baselines'
,
function
()
{
const
fixtures
=
require
(
'./html-baselines'
);
let
frame
;
let
frame
;
before
(
function
()
{
before
(
function
()
{
...
@@ -431,7 +431,7 @@ describe('HTML anchoring', function() {
...
@@ -431,7 +431,7 @@ describe('HTML anchoring', function() {
frame
.
remove
();
frame
.
remove
();
});
});
fixtur
es
.
forEach
(
fixture
=>
{
htmlBaselin
es
.
forEach
(
fixture
=>
{
it
(
`generates selectors which match the baseline
${
fixture
.
name
}
`
,
()
=>
{
it
(
`generates selectors which match the baseline
${
fixture
.
name
}
`
,
()
=>
{
let
fixtureHtml
=
fixture
.
html
;
let
fixtureHtml
=
fixture
.
html
;
const
annotations
=
fixture
.
annotations
.
rows
;
const
annotations
=
fixture
.
annotations
.
rows
;
...
...
src/annotator/anchoring/test/pdf-test.js
View file @
8bc370c8
const
domAnchorTextQuote
=
require
(
'dom-anchor-text-quote'
)
;
import
*
as
domAnchorTextQuote
from
'dom-anchor-text-quote'
;
const
FakePDFViewerApplication
=
require
(
'./fake-pdf-viewer-application'
);
import
*
as
pdfAnchoring
from
'../pdf'
;
const
pdfAnchoring
=
require
(
'../pdf'
);
import
FakePDFViewerApplication
from
'./fake-pdf-viewer-application'
;
/**
/**
* Return a DOM Range which refers to the specified `text` in `container`.
* Return a DOM Range which refers to the specified `text` in `container`.
...
...
src/annotator/anchoring/test/text-position-test.js
View file @
8bc370c8
const
{
toRange
}
=
require
(
'../text-position'
)
;
import
{
toRange
}
from
'../text-position'
;
describe
(
'text-position'
,
()
=>
{
describe
(
'text-position'
,
()
=>
{
let
container
;
let
container
;
...
...
src/annotator/anchoring/test/types-test.js
View file @
8bc370c8
const
types
=
require
(
'../types'
)
;
import
*
as
types
from
'../types'
;
const
TextQuoteAnchor
=
types
.
TextQuoteAnchor
;
const
TextQuoteAnchor
=
types
.
TextQuoteAnchor
;
const
TextPositionAnchor
=
types
.
TextPositionAnchor
;
const
TextPositionAnchor
=
types
.
TextPositionAnchor
;
...
...
src/annotator/anchoring/text-position.js
View file @
8bc370c8
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
* @param {number} end - Character offset within `root.textContent`
* @param {number} end - Character offset within `root.textContent`
* @return {Range} Range spanning text from `start` to `end`
* @return {Range} Range spanning text from `start` to `end`
*/
*/
function
toRange
(
root
,
start
,
end
)
{
export
function
toRange
(
root
,
start
,
end
)
{
// The `filter` and `expandEntityReferences` arguments are mandatory in IE
// The `filter` and `expandEntityReferences` arguments are mandatory in IE
// although optional according to the spec.
// although optional according to the spec.
const
nodeIter
=
root
.
ownerDocument
.
createNodeIterator
(
const
nodeIter
=
root
.
ownerDocument
.
createNodeIterator
(
...
@@ -76,7 +76,3 @@ function toRange(root, start, end) {
...
@@ -76,7 +76,3 @@ function toRange(root, start, end) {
return
range
;
return
range
;
}
}
module
.
exports
=
{
toRange
,
};
src/annotator/config/config-func-settings-from.js
View file @
8bc370c8
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
* @return {Object} - Any config settings returned by hypothesisConfig()
* @return {Object} - Any config settings returned by hypothesisConfig()
*
*
*/
*/
function
configFuncSettingsFrom
(
window_
)
{
export
default
function
configFuncSettingsFrom
(
window_
)
{
if
(
!
window_
.
hasOwnProperty
(
'hypothesisConfig'
))
{
if
(
!
window_
.
hasOwnProperty
(
'hypothesisConfig'
))
{
return
{};
return
{};
}
}
...
@@ -30,5 +30,3 @@ function configFuncSettingsFrom(window_) {
...
@@ -30,5 +30,3 @@ function configFuncSettingsFrom(window_) {
return
window_
.
hypothesisConfig
();
return
window_
.
hypothesisConfig
();
}
}
module
.
exports
=
configFuncSettingsFrom
;
src/annotator/config/index.js
View file @
8bc370c8
const
settingsFrom
=
require
(
'./settings'
)
;
import
settingsFrom
from
'./settings'
;
/**
/**
* Reads the Hypothesis configuration from the environment.
* Reads the Hypothesis configuration from the environment.
*
*
* @param {Window} window_ - The Window object to read config from.
* @param {Window} window_ - The Window object to read config from.
*/
*/
function
configFrom
(
window_
)
{
export
default
function
configFrom
(
window_
)
{
const
settings
=
settingsFrom
(
window_
);
const
settings
=
settingsFrom
(
window_
);
return
{
return
{
annotations
:
settings
.
annotations
,
annotations
:
settings
.
annotations
,
...
@@ -44,5 +44,3 @@ function configFrom(window_) {
...
@@ -44,5 +44,3 @@ function configFrom(window_) {
),
),
};
};
}
}
module
.
exports
=
configFrom
;
src/annotator/config/is-browser-extension.js
View file @
8bc370c8
...
@@ -6,8 +6,6 @@
...
@@ -6,8 +6,6 @@
* website.
* website.
*
*
*/
*/
function
isBrowserExtension
(
app
)
{
export
default
function
isBrowserExtension
(
app
)
{
return
!
(
app
.
startsWith
(
'http://'
)
||
app
.
startsWith
(
'https://'
));
return
!
(
app
.
startsWith
(
'http://'
)
||
app
.
startsWith
(
'https://'
));
}
}
module
.
exports
=
isBrowserExtension
;
src/annotator/config/settings.js
View file @
8bc370c8
const
configFuncSettingsFrom
=
require
(
'./config-func-settings-from'
);
import
*
as
sharedSettings
from
'../../shared/settings'
;
const
isBrowserExtension
=
require
(
'./is-browser-extension'
);
const
sharedSettings
=
require
(
'../../shared/settings'
);
function
settingsFrom
(
window_
)
{
import
configFuncSettingsFrom
from
'./config-func-settings-from'
;
import
isBrowserExtension
from
'./is-browser-extension'
;
export
default
function
settingsFrom
(
window_
)
{
const
jsonConfigs
=
sharedSettings
.
jsonConfigsFrom
(
window_
.
document
);
const
jsonConfigs
=
sharedSettings
.
jsonConfigsFrom
(
window_
.
document
);
const
configFuncSettings
=
configFuncSettingsFrom
(
window_
);
const
configFuncSettings
=
configFuncSettingsFrom
(
window_
);
...
@@ -214,5 +215,3 @@ function settingsFrom(window_) {
...
@@ -214,5 +215,3 @@ function settingsFrom(window_) {
hostPageSetting
:
hostPageSetting
,
hostPageSetting
:
hostPageSetting
,
};
};
}
}
module
.
exports
=
settingsFrom
;
src/annotator/config/test/config-func-settings-from-test.js
View file @
8bc370c8
const
configFuncSettingsFrom
=
require
(
'../config-func-settings-from'
)
;
import
configFuncSettingsFrom
from
'../config-func-settings-from'
;
describe
(
'annotator.config.configFuncSettingsFrom'
,
function
()
{
describe
(
'annotator.config.configFuncSettingsFrom'
,
function
()
{
const
sandbox
=
sinon
.
createSandbox
();
const
sandbox
=
sinon
.
createSandbox
();
...
...
src/annotator/config/test/index-test.js
View file @
8bc370c8
const
configFrom
=
require
(
'../index'
)
;
import
configFrom
from
'../index'
;
const
{
$imports
}
=
require
(
'../index'
)
;
import
{
$imports
}
from
'../index'
;
describe
(
'annotator.config.index'
,
function
()
{
describe
(
'annotator.config.index'
,
function
()
{
let
fakeSettingsFrom
;
let
fakeSettingsFrom
;
...
...
src/annotator/config/test/is-browser-extension-test.js
View file @
8bc370c8
const
isBrowserExtension
=
require
(
'../is-browser-extension'
)
;
import
isBrowserExtension
from
'../is-browser-extension'
;
describe
(
'annotator.config.isBrowserExtension'
,
function
()
{
describe
(
'annotator.config.isBrowserExtension'
,
function
()
{
[
[
...
...
src/annotator/config/test/settings-test.js
View file @
8bc370c8
const
settingsFrom
=
require
(
'../settings'
)
;
import
settingsFrom
from
'../settings'
;
const
{
$imports
}
=
require
(
'../settings'
)
;
import
{
$imports
}
from
'../settings'
;
describe
(
'annotator.config.settingsFrom'
,
function
()
{
describe
(
'annotator.config.settingsFrom'
,
function
()
{
let
fakeConfigFuncSettingsFrom
;
let
fakeConfigFuncSettingsFrom
;
...
...
src/annotator/index.js
View file @
8bc370c8
const
$
=
require
(
'jquery'
)
;
import
$
from
'jquery'
;
// Load polyfill for :focus-visible pseudo-class.
// Load polyfill for :focus-visible pseudo-class.
require
(
'focus-visible'
);
import
'focus-visible'
;
const
configFrom
=
require
(
'./config/index'
);
import
configFrom
from
'./config/index'
;
const
Guest
=
require
(
'./guest'
);
import
Guest
from
'./guest'
;
const
Sidebar
=
require
(
'./sidebar'
);
import
PdfSidebar
from
'./pdf-sidebar'
;
const
PdfSidebar
=
require
(
'./pdf-sidebar'
);
import
BucketBarPlugin
from
'./plugin/bucket-bar'
;
import
CrossFramePlugin
from
'./plugin/cross-frame'
;
import
DocumentPlugin
from
'./plugin/document'
;
import
PDFPlugin
from
'./plugin/pdf'
;
import
ToolbarPlugin
from
'./plugin/toolbar'
;
import
Sidebar
from
'./sidebar'
;
const
pluginClasses
=
{
const
pluginClasses
=
{
// UI plugins
// UI plugins
BucketBar
:
require
(
'./plugin/bucket-bar'
)
,
BucketBar
:
BucketBarPlugin
,
Toolbar
:
require
(
'./plugin/toolbar'
)
,
Toolbar
:
ToolbarPlugin
,
// Document type plugins
// Document type plugins
PDF
:
require
(
'./plugin/pdf'
)
,
PDF
:
PDFPlugin
,
Document
:
require
(
'./plugin/document'
)
,
Document
:
DocumentPlugin
,
// Cross-frame communication
// Cross-frame communication
CrossFrame
:
require
(
'./plugin/cross-frame'
)
,
CrossFrame
:
CrossFramePlugin
,
};
};
const
appLinkEl
=
document
.
querySelector
(
const
appLinkEl
=
document
.
querySelector
(
...
...
src/annotator/plugin/document.js
View file @
8bc370c8
...
@@ -10,16 +10,16 @@
...
@@ -10,16 +10,16 @@
** https://github.com/openannotation/annotator/blob/master/LICENSE
** https://github.com/openannotation/annotator/blob/master/LICENSE
*/
*/
const
baseURI
=
require
(
'document-base-uri'
)
;
import
baseURI
from
'document-base-uri'
;
const
Plugin
=
require
(
'../plugin'
)
;
import
Plugin
from
'../plugin'
;
const
{
normalizeURI
}
=
require
(
'../util/url'
)
;
import
{
normalizeURI
}
from
'../util/url'
;
/**
/**
* DocumentMeta reads metadata/links from the current HTML document and
* DocumentMeta reads metadata/links from the current HTML document and
* populates the `document` property of new annotations.
* populates the `document` property of new annotations.
*/
*/
class
DocumentMeta
extends
Plugin
{
export
default
class
DocumentMeta
extends
Plugin
{
constructor
(
element
,
options
)
{
constructor
(
element
,
options
)
{
super
(
element
,
options
);
super
(
element
,
options
);
...
@@ -298,5 +298,3 @@ class DocumentMeta extends Plugin {
...
@@ -298,5 +298,3 @@ class DocumentMeta extends Plugin {
return
href
;
return
href
;
}
}
}
}
module
.
exports
=
DocumentMeta
;
src/annotator/plugin/pdf-metadata.js
View file @
8bc370c8
const
{
normalizeURI
}
=
require
(
'../util/url'
)
;
import
{
normalizeURI
}
from
'../util/url'
;
/**
/**
* @typedef Link
* @typedef Link
...
@@ -25,7 +25,7 @@ const { normalizeURI } = require('../util/url');
...
@@ -25,7 +25,7 @@ const { normalizeURI } = require('../util/url');
* // Do something with the URL of the PDF.
* // Do something with the URL of the PDF.
* })
* })
*/
*/
class
PDFMetadata
{
export
default
class
PDFMetadata
{
/**
/**
* Construct a `PDFMetadata` that returns URIs/metadata associated with a
* Construct a `PDFMetadata` that returns URIs/metadata associated with a
* given PDF viewer.
* given PDF viewer.
...
@@ -126,5 +126,3 @@ function getPDFURL(app) {
...
@@ -126,5 +126,3 @@ function getPDFURL(app) {
return
null
;
return
null
;
}
}
module
.
exports
=
PDFMetadata
;
src/annotator/plugin/pdf.coffee
View file @
8bc370c8
...
@@ -9,7 +9,7 @@ module.exports = class PDF extends Plugin
...
@@ -9,7 +9,7 @@ module.exports = class PDF extends Plugin
pluginInit
:
->
pluginInit
:
->
@
annotator
.
anchoring
=
require
(
'../anchoring/pdf'
)
@
annotator
.
anchoring
=
require
(
'../anchoring/pdf'
)
PDFMetadata
=
require
(
'./pdf-metadata'
)
{
default
:
PDFMetadata
}
=
require
(
'./pdf-metadata'
)
@
pdfViewer
=
PDFViewerApplication
.
pdfViewer
@
pdfViewer
=
PDFViewerApplication
.
pdfViewer
@
pdfViewer
.
viewer
.
classList
.
add
(
'has-transparent-text-layer'
)
@
pdfViewer
.
viewer
.
classList
.
add
(
'has-transparent-text-layer'
)
...
...
src/annotator/plugin/test/document-test.js
View file @
8bc370c8
...
@@ -10,10 +10,10 @@
...
@@ -10,10 +10,10 @@
** https://github.com/openannotation/annotator/blob/master/LICENSE
** https://github.com/openannotation/annotator/blob/master/LICENSE
*/
*/
const
$
=
require
(
'jquery'
)
;
import
$
from
'jquery'
;
const
DocumentMeta
=
require
(
'../document'
)
;
import
{
normalizeURI
}
from
'../../util/url'
;
const
{
normalizeURI
}
=
require
(
'../../util/url'
)
;
import
DocumentMeta
from
'../document'
;
describe
(
'DocumentMeta'
,
function
()
{
describe
(
'DocumentMeta'
,
function
()
{
let
fakeNormalizeURI
;
let
fakeNormalizeURI
;
...
...
src/annotator/plugin/test/pdf-metadata-test.js
View file @
8bc370c8
const
PDFMetadata
=
require
(
'../pdf-metadata'
)
;
import
PDFMetadata
from
'../pdf-metadata'
;
/**
/**
* Fake implementation of PDF.js `window.PDFViewerApplication.metadata`.
* Fake implementation of PDF.js `window.PDFViewerApplication.metadata`.
...
...
src/annotator/plugin/test/toolbar-test.js
View file @
8bc370c8
const
$
=
require
(
'jquery'
)
;
import
$
from
'jquery'
;
const
Toolbar
=
require
(
'../toolbar'
)
;
import
Toolbar
from
'../toolbar'
;
describe
(
'Toolbar'
,
()
=>
{
describe
(
'Toolbar'
,
()
=>
{
let
container
;
let
container
;
...
...
src/annotator/test/adder-test.js
View file @
8bc370c8
const
adder
=
require
(
'../adder'
)
;
import
*
as
adder
from
'../adder'
;
function
rect
(
left
,
top
,
width
,
height
)
{
function
rect
(
left
,
top
,
width
,
height
)
{
return
{
left
:
left
,
top
:
top
,
width
:
width
,
height
:
height
};
return
{
left
:
left
,
top
:
top
,
width
:
width
,
height
:
height
};
...
...
src/annotator/test/annotation-counts-test.js
View file @
8bc370c8
const
annotationCounts
=
require
(
'../annotation-counts'
)
;
import
annotationCounts
from
'../annotation-counts'
;
describe
(
'annotationCounts'
,
function
()
{
describe
(
'annotationCounts'
,
function
()
{
let
countEl1
;
let
countEl1
;
...
...
src/annotator/test/annotation-sync-test.js
View file @
8bc370c8
const
EventEmitter
=
require
(
'tiny-emitter'
)
;
import
EventEmitter
from
'tiny-emitter'
;
const
AnnotationSync
=
require
(
'../annotation-sync'
)
;
import
AnnotationSync
from
'../annotation-sync'
;
describe
(
'AnnotationSync'
,
function
()
{
describe
(
'AnnotationSync'
,
function
()
{
let
createAnnotationSync
;
let
createAnnotationSync
;
...
...
src/annotator/test/features-test.js
View file @
8bc370c8
const
events
=
require
(
'../../shared/bridge-events'
)
;
import
events
from
'../../shared/bridge-events'
;
const
features
=
require
(
'../features'
)
;
import
features
from
'../features'
;
const
{
$imports
}
=
require
(
'../features'
)
;
import
{
$imports
}
from
'../features'
;
describe
(
'features - annotation layer'
,
function
()
{
describe
(
'features - annotation layer'
,
function
()
{
let
featureFlagsUpdateHandler
;
let
featureFlagsUpdateHandler
;
...
...
src/annotator/test/range-util-test.js
View file @
8bc370c8
const
rangeUtil
=
require
(
'../range-util'
)
;
import
*
as
rangeUtil
from
'../range-util'
;
function
createRange
(
node
,
start
,
end
)
{
function
createRange
(
node
,
start
,
end
)
{
const
range
=
node
.
ownerDocument
.
createRange
();
const
range
=
node
.
ownerDocument
.
createRange
();
...
...
src/annotator/test/selections-test.js
View file @
8bc370c8
const
observable
=
require
(
'../util/observable'
)
;
import
selections
from
'../selections'
;
const
selections
=
require
(
'../selections'
)
;
import
*
as
observable
from
'../util/observable'
;
function
FakeDocument
()
{
function
FakeDocument
()
{
const
listeners
=
{};
const
listeners
=
{};
...
...
src/annotator/test/sidebar-trigger-test.js
View file @
8bc370c8
const
sidebarTrigger
=
require
(
'../sidebar-trigger'
)
;
import
sidebarTrigger
from
'../sidebar-trigger'
;
describe
(
'sidebarTrigger'
,
function
()
{
describe
(
'sidebarTrigger'
,
function
()
{
let
triggerEl1
;
let
triggerEl1
;
...
...
src/annotator/util/frame-util.js
View file @
8bc370c8
...
@@ -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 @
8bc370c8
...
@@ -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 @
8bc370c8
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