File tree Expand file tree Collapse file tree 6 files changed +14
-10
lines changed Expand file tree Collapse file tree 6 files changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -474,7 +474,7 @@ export default class Guest extends Delegator {
474
474
475
475
const highlights = /** @type {AnnotationHighlight[] } */ ( highlightRange (
476
476
range ,
477
- Math . random ( ) * ( 6 - 1 ) + 1
477
+ annotation . $color
478
478
) ) ;
479
479
highlights . forEach ( h => {
480
480
h . _annotation = anchor . annotation ;
Original file line number Diff line number Diff line change @@ -212,13 +212,13 @@ function wholeTextNodesInRange(range) {
212
212
* element of the specified class and returns the highlight Elements.
213
213
*
214
214
* @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
216
216
* @param {string } cssClass - A CSS class to use for the highlight
217
217
* @return {HighlightElement[] } - Elements wrapping text in `normedRange` to add a highlight effect
218
218
*/
219
219
export function highlightRange (
220
220
range ,
221
- colorNum ,
221
+ color ,
222
222
cssClass = 'hypothesis-highlight'
223
223
) {
224
224
const textNodes = wholeTextNodesInRange ( range ) ;
@@ -265,11 +265,7 @@ export function highlightRange(
265
265
/** @type {HighlightElement } */
266
266
const highlightEl = document . createElement ( 'hypothesis-highlight' ) ;
267
267
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 ;
273
269
274
270
nodes [ 0 ] . parentNode . replaceChild ( highlightEl , nodes [ 0 ] ) ;
275
271
nodes . forEach ( node => highlightEl . appendChild ( node ) ) ;
Original file line number Diff line number Diff line change @@ -56,7 +56,6 @@ function SidebarView({
56
56
const searchUris = store . searchUris ( ) ;
57
57
const sidebarHasOpened = store . hasSidebarOpened ( ) ;
58
58
const userId = store . profile ( ) . userid ;
59
- //WILLNOTE we can use this to hide/show for this user!
60
59
61
60
// The local `$tag` of a direct-linked annotation; populated once it
62
61
// has anchored: meaning that it's ready to be focused and scrolled to
Original file line number Diff line number Diff line change @@ -14,12 +14,20 @@ import { watch } from '../util/watch';
14
14
* within the current session and anchor it in the document.
15
15
*/
16
16
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
+ }
17
24
return {
18
25
tag : ann . $tag ,
19
26
msg : {
20
27
document : ann . document ,
21
28
target : ann . target ,
22
29
uri : ann . uri ,
30
+ $color : hashColor ( ann . user ) ,
23
31
} ,
24
32
} ;
25
33
}
Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ function initializeAnnotation(annotation, tag) {
86
86
$anchorTimeout : false ,
87
87
$tag : annotation . $tag || tag ,
88
88
$orphan : orphan ,
89
- $doodle : annotation . $doodle ,
89
+ $user : annotation . user ,
90
90
} ) ;
91
91
}
92
92
Original file line number Diff line number Diff line change 31
31
* @prop {string } uri
32
32
* @prop {Target[] } target
33
33
* @prop {string } $tag
34
+ * @prop {string } $color - What color to display the highlight in? This corresponds to the user who created the annotation.
34
35
* @prop {boolean } [$doodle] -
35
36
* Flag indicating that this annotation is a doodle
36
37
* @prop {DoodleLine[] } [doodleLines] -
You can’t perform that action at this time.
0 commit comments