Skip to content

Commit 7846509

Browse files
committed
ooooffff
1 parent 94ffb93 commit 7846509

File tree

6 files changed

+14
-10
lines changed

6 files changed

+14
-10
lines changed

src/annotator/guest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ export default class Guest extends Delegator {
474474

475475
const highlights = /** @type {AnnotationHighlight[]} */ (highlightRange(
476476
range,
477-
Math.random() * (6 - 1) + 1
477+
annotation.$color
478478
));
479479
highlights.forEach(h => {
480480
h._annotation = anchor.annotation;

src/annotator/highlighter.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,13 @@ function wholeTextNodesInRange(range) {
212212
* element of the specified class and returns the highlight Elements.
213213
*
214214
* @param {Range} range - Range to be highlighted
215-
* @param {Number} colorNum - number to index color list
215+
* @param {String} color - What color to display the annotation in
216216
* @param {string} cssClass - A CSS class to use for the highlight
217217
* @return {HighlightElement[]} - Elements wrapping text in `normedRange` to add a highlight effect
218218
*/
219219
export function highlightRange(
220220
range,
221-
colorNum,
221+
color,
222222
cssClass = 'hypothesis-highlight'
223223
) {
224224
const textNodes = wholeTextNodesInRange(range);
@@ -265,11 +265,7 @@ export function highlightRange(
265265
/** @type {HighlightElement} */
266266
const highlightEl = document.createElement('hypothesis-highlight');
267267
highlightEl.className = cssClass;
268-
//here is where we can call another function to get the color for the user
269-
//color-->index number in the 'user-color' class
270-
if (colorNum !== -1) {
271-
highlightEl.classList.toggle('user-color' + Math.round(colorNum), true);
272-
}
268+
highlightEl.style.backgroundColor = color;
273269

274270
nodes[0].parentNode.replaceChild(highlightEl, nodes[0]);
275271
nodes.forEach(node => highlightEl.appendChild(node));

src/sidebar/components/SidebarView.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ function SidebarView({
5656
const searchUris = store.searchUris();
5757
const sidebarHasOpened = store.hasSidebarOpened();
5858
const userId = store.profile().userid;
59-
//WILLNOTE we can use this to hide/show for this user!
6059

6160
// The local `$tag` of a direct-linked annotation; populated once it
6261
// has anchored: meaning that it's ready to be focused and scrolled to

src/sidebar/services/frame-sync.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ import { watch } from '../util/watch';
1414
* within the current session and anchor it in the document.
1515
*/
1616
export function formatAnnot(ann) {
17+
function hashColor(s) {
18+
let h = 0;
19+
for (let i = 0; i < s.length; i++)
20+
{h = (Math.imul(31, h) + s.charCodeAt(i)) | 0;}
21+
22+
return `#${Math.abs(h).toString(16).padStart(6, '0').substr(0, 6)}`;
23+
}
1724
return {
1825
tag: ann.$tag,
1926
msg: {
2027
document: ann.document,
2128
target: ann.target,
2229
uri: ann.uri,
30+
$color: hashColor(ann.user),
2331
},
2432
};
2533
}

src/sidebar/store/modules/annotations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function initializeAnnotation(annotation, tag) {
8686
$anchorTimeout: false,
8787
$tag: annotation.$tag || tag,
8888
$orphan: orphan,
89-
$doodle: annotation.$doodle,
89+
$user: annotation.user,
9090
});
9191
}
9292

src/types/annotator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* @prop {string} uri
3232
* @prop {Target[]} target
3333
* @prop {string} $tag
34+
* @prop {string} $color - What color to display the highlight in? This corresponds to the user who created the annotation.
3435
* @prop {boolean} [$doodle] -
3536
* Flag indicating that this annotation is a doodle
3637
* @prop {DoodleLine[]} [doodleLines] -

0 commit comments

Comments
 (0)