Skip to content
Snippets Groups Projects
Commit 44cedec6 authored by Sven Kästle's avatar Sven Kästle
Browse files

feat: Add user color support for different users

parent 67819811
No related branches found
No related tags found
No related merge requests found
...@@ -33,9 +33,6 @@ ol { ...@@ -33,9 +33,6 @@ ol {
height: 10px; height: 10px;
/* background-color: orange; */ /* background-color: orange; */
} }
.hl {
background-color: yellow;
}
.annotation-card { .annotation-card {
width: 100%; width: 100%;
......
// set color, userId and targetId // initialize userId, userColors and targetId
var userId = 11; var userId = randomUserId();
var userColors = new Map();
var targetId = 200; var targetId = 200;
var color = getRandomColor();
// declare document text // declare document text
var documentText; var documentText;
...@@ -155,7 +155,7 @@ function displayAnnotation(annotation) { ...@@ -155,7 +155,7 @@ function displayAnnotation(annotation) {
list.prepend( list.prepend(
$('<li>') $('<li>')
.mouseenter(function () { .mouseenter(function () {
addHighlightedText(annotation.startCharacter, annotation.endCharacter); addHighlightedText(annotation.startCharacter, annotation.endCharacter, annotation.userId);
}) })
.mouseleave(function () { .mouseleave(function () {
deleteHighlightedText(); deleteHighlightedText();
...@@ -166,7 +166,7 @@ function displayAnnotation(annotation) { ...@@ -166,7 +166,7 @@ function displayAnnotation(annotation) {
$('<div>').attr('class', 'annotation-card') $('<div>').attr('class', 'annotation-card')
.append( .append(
$('<div>').attr('class', 'annotation-header') $('<div>').attr('class', 'annotation-header')
.css('background-color', color) .css('background-color', getUserColor(annotation.userId))
.append( .append(
$('<div>').attr('class', 'annotation-header-title') $('<div>').attr('class', 'annotation-header-title')
.append( .append(
...@@ -224,9 +224,9 @@ function displayAnnotation(annotation) { ...@@ -224,9 +224,9 @@ function displayAnnotation(annotation) {
* @param startCharacter the offset of the start character * @param startCharacter the offset of the start character
* @param endCharacter the offset of the end character * @param endCharacter the offset of the end character
*/ */
function addHighlightedText(startCharacter, endCharacter) { function addHighlightedText(startCharacter, endCharacter, userId) {
// create <span> tag with the annotated text // create <span> tag with the annotated text
var replacement = $('<span></span>').css('background-color', color).html(documentText.slice(startCharacter, endCharacter)); var replacement = $('<span></span>').css('background-color', getUserColor(userId)).html(documentText.slice(startCharacter, endCharacter));
// wrap an <p> tag around the replacement, get its parent (the <p>) and ask for the html // wrap an <p> tag around the replacement, get its parent (the <p>) and ask for the html
var replacementHtml = replacement.wrap('<p/>').parent().html(); var replacementHtml = replacement.wrap('<p/>').parent().html();
...@@ -262,6 +262,21 @@ function getSelectedText() { ...@@ -262,6 +262,21 @@ function getSelectedText() {
} }
} }
/**
* Get color based on user id
*
* @param userId the id of the user
* @returns {string} the user color
*/
function getUserColor(userId) {
// insert new color if there is no userId key
if (userColors.get(userId) == null) {
userColors.set(userId, getRandomColor());
}
// return the color
return userColors.get(userId);
}
/** /**
* Generate a random color of the format 'rgb(r, g, b)' * Generate a random color of the format 'rgb(r, g, b)'
* *
...@@ -346,3 +361,10 @@ function toggleButtonHandler(element) { ...@@ -346,3 +361,10 @@ function toggleButtonHandler(element) {
element.children("i").toggleClass("fa-chevron-down fa-chevron-up") element.children("i").toggleClass("fa-chevron-down fa-chevron-up")
} }
/*
MOCKUP FUNCTIONS
*/
function randomUserId() {
return Math.floor((Math.random() * 10) + 1);;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment