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
b8b48606
Commit
b8b48606
authored
Jan 20, 2023
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Jan 23, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update comments in `annotation-counts` and convert to TS
parent
27da5169
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
22 deletions
+30
-22
annotation-counts.js
src/annotator/annotation-counts.js
+0
-22
annotation-counts.ts
src/annotator/annotation-counts.ts
+30
-0
No files found.
src/annotator/annotation-counts.js
deleted
100644 → 0
View file @
27da5169
const
ANNOTATION_COUNT_ATTR
=
'data-hypothesis-annotation-count'
;
/**
* Update the elements in the container element with the count data attribute
* with the new annotation count. See:
* https://h.readthedocs.io/projects/client/en/latest/publishers/host-page-integration/#cmdoption-arg-data-hypothesis-annotation-count
*
* @param {Element} rootEl - The DOM element which contains the elements that
* display annotation count.
* @param {import('../shared/messaging').PortRPC<'publicAnnotationCountChanged', string>} rpc - Channel for host-sidebar communication
*/
export
function
annotationCounts
(
rootEl
,
rpc
)
{
rpc
.
on
(
'publicAnnotationCountChanged'
,
updateAnnotationCountElems
);
/** @param {number} newCount */
function
updateAnnotationCountElems
(
newCount
)
{
const
elems
=
rootEl
.
querySelectorAll
(
'['
+
ANNOTATION_COUNT_ATTR
+
']'
);
Array
.
from
(
elems
).
forEach
(
elem
=>
{
elem
.
textContent
=
newCount
.
toString
();
});
}
}
src/annotator/annotation-counts.ts
0 → 100644
View file @
b8b48606
import
type
{
PortRPC
}
from
'../shared/messaging'
;
const
ANNOTATION_COUNT_ATTR
=
'data-hypothesis-annotation-count'
;
/**
* Show the current count of public annotations in designated elements.
*
* Any time the count of public annotations changes, find all elements within
* `rootEl` that have the `data-hypothesis-annotation-count` attribute and
* replace their text content with the current count of public annotations.
*
* This allows publishers to add a count of annotations to their web pages.
*
* See:
* https://h.readthedocs.io/projects/client/en/latest/publishers/host-page-integration.html#cmdoption-arg-data-hypothesis-annotation-count
*
*/
export
function
annotationCounts
(
rootEl
:
Element
,
rpc
:
PortRPC
<
'publicAnnotationCountChanged'
,
string
>
)
{
rpc
.
on
(
'publicAnnotationCountChanged'
,
updateAnnotationCountElems
);
function
updateAnnotationCountElems
(
newCount
:
number
)
{
const
elems
=
rootEl
.
querySelectorAll
(
`[
${
ANNOTATION_COUNT_ATTR
}
]`
);
Array
.
from
(
elems
).
forEach
(
elem
=>
{
elem
.
textContent
=
newCount
.
toString
();
});
}
}
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