Skip to content

Commit 8d99a69

Browse files
author
Sydney Jaques
authored
User highlight color (#1)
* different color highlight ability. need to make per user next * make colors more vibrant * fixed pull review actions * made pretty * updating highlightRange test * made pretty again * fixing bracket it didnt like * pretty * fixed equal format
1 parent 4471301 commit 8d99a69

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

src/annotator/guest.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ export default class Guest extends Delegator {
454454
}
455455

456456
const highlights = /** @type {AnnotationHighlight[]} */ (highlightRange(
457-
range
457+
range,
458+
Math.random() * (6 - 1) + 1
458459
));
459460
highlights.forEach(h => {
460461
h._annotation = anchor.annotation;

src/annotator/highlighter.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,15 @@ 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
215216
* @param {string} cssClass - A CSS class to use for the highlight
216217
* @return {HighlightElement[]} - Elements wrapping text in `normedRange` to add a highlight effect
217218
*/
218-
export function highlightRange(range, cssClass = 'hypothesis-highlight') {
219+
export function highlightRange(
220+
range,
221+
colorNum,
222+
cssClass = 'hypothesis-highlight'
223+
) {
219224
const textNodes = wholeTextNodesInRange(range);
220225

221226
// Check if this range refers to a placeholder for not-yet-rendered text in
@@ -260,6 +265,11 @@ export function highlightRange(range, cssClass = 'hypothesis-highlight') {
260265
/** @type {HighlightElement} */
261266
const highlightEl = document.createElement('hypothesis-highlight');
262267
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+
}
263273

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

src/annotator/test/highlighter-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ describe('annotator/highlighter', () => {
141141
const range = new Range();
142142
range.setStart(el.firstChild, 4);
143143
range.setEnd(el, 1);
144-
highlightRange(range, '' /* cssClass */);
144+
highlightRange(range, -1, '' /* cssClass */);
145145

146146
assert.equal(
147147
el.innerHTML,

src/styles/annotator/highlights.scss

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919

2020
.hypothesis-highlight {
21-
background-color: var.$color-highlight;
21+
background-color: var.$user-colors;
2222

2323
// For PDFs, we still create highlight elements to wrap the text but the
2424
// highlight effect is created by another element.
@@ -72,5 +72,23 @@
7272
background-color: transparent !important;
7373
}
7474
}
75+
&.user-color1 {
76+
background-color: nth(var.$user-colors, 1);
77+
}
78+
&.user-color2 {
79+
background-color: nth(var.$user-colors, 2);
80+
}
81+
&.user-color3 {
82+
background-color: nth(var.$user-colors, 3);
83+
}
84+
&.user-color4 {
85+
background-color: nth(var.$user-colors, 4);
86+
}
87+
&.user-color5 {
88+
background-color: nth(var.$user-colors, 5);
89+
}
90+
&.user-color6 {
91+
background-color: nth(var.$user-colors, 6);
92+
}
7593
}
7694
}

src/styles/variables.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,6 @@ $annotator-border-radius: 4px;
136136

137137
$annotator-shadow--sidebar: 0px 1px 4px color.scale($color-shadow, $alpha: -50%);
138138
$annotator-timing--sidebar-collapse-transition: 150ms;
139+
140+
//test for highlight colors per user
141+
$user-colors: #ff0a0a, #20e9ff, #447fff, #fff400, #8335ff, #2fffa2;

0 commit comments

Comments
 (0)