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
3dc2f206
Commit
3dc2f206
authored
May 11, 2018
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some basic API docs to `DocumentMeta` class
parent
f6779e35
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
10 deletions
+30
-10
document.js
src/annotator/plugin/document.js
+26
-7
document-test.js
src/annotator/plugin/test/document-test.js
+4
-3
No files found.
src/annotator/plugin/document.js
View file @
3dc2f206
'use strict'
;
const
baseURI
=
require
(
'document-base-uri'
);
const
Plugin
=
require
(
'../plugin'
);
const
{
normalizeURI
}
=
require
(
'../util/url'
);
/*
** Adapted from:
** https://github.com/openannotation/annotator/blob/v1.2.x/src/plugin/document.coffee
...
...
@@ -17,6 +12,15 @@ const { normalizeURI } = require('../util/url');
** https://github.com/openannotation/annotator/blob/master/LICENSE
*/
const
baseURI
=
require
(
'document-base-uri'
);
const
Plugin
=
require
(
'../plugin'
);
const
{
normalizeURI
}
=
require
(
'../util/url'
);
/**
* DocumentMeta reads metadata/links from the current HTML document and
* populates the `document` property of new annotations.
*/
class
DocumentMeta
extends
Plugin
{
constructor
(
element
,
options
)
{
super
(
element
,
options
);
...
...
@@ -34,7 +38,11 @@ class DocumentMeta extends Plugin {
this
.
getDocumentMetadata
();
}
// Returns the primary URI for the document being annotated
/**
* Returns the primary URI for the document being annotated
*
* @return {string}
*/
uri
()
{
let
uri
=
decodeURIComponent
(
this
.
_getDocumentHref
());
for
(
let
link
of
this
.
metadata
.
link
)
{
...
...
@@ -45,7 +53,11 @@ class DocumentMeta extends Plugin {
return
uri
;
}
// Returns all uris for the document being annotated
/**
* Returns all uris for the document being annotated
*
* @return {string[]}
*/
uris
()
{
const
uniqueUrls
=
{};
for
(
let
link
of
this
.
metadata
.
link
)
{
...
...
@@ -54,10 +66,17 @@ class DocumentMeta extends Plugin {
return
Object
.
keys
(
uniqueUrls
);
}
/**
* Hook that augments new annotations with metadata about the document they
* came from.
*/
beforeAnnotationCreated
(
annotation
)
{
annotation
.
document
=
this
.
metadata
;
}
/**
* Return metadata for the current page.
*/
getDocumentMetadata
()
{
this
.
metadata
=
{};
...
...
src/annotator/plugin/test/document-test.js
View file @
3dc2f206
'use strict'
;
const
$
=
require
(
'jquery'
);
const
DocumentMeta
=
require
(
'../document'
);
/*
** Adapted from:
** https://github.com/openannotation/annotator/blob/v1.2.x/test/spec/plugin/document_spec.coffee
...
...
@@ -15,6 +12,10 @@ const DocumentMeta = require('../document');
** https://github.com/openannotation/annotator/blob/master/LICENSE
*/
const
$
=
require
(
'jquery'
);
const
DocumentMeta
=
require
(
'../document'
);
describe
(
'DocumentMeta'
,
function
()
{
let
testDocument
=
null
;
...
...
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