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

feat: Change color on annotation card hover

parent 44cedec6
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,6 @@ ol { ...@@ -7,7 +7,6 @@ ol {
display: flex; display: flex;
box-sizing: border-box; box-sizing: border-box;
font-family: Arial; font-family: Arial;
background-color: #f1f1f1;
height: 100%; height: 100%;
} }
.rightcolumn { .rightcolumn {
......
// initialize userId, userColors and targetId // initialize userId, userColors and targetId
var userId = randomUserId(); var userId = randomUserId();
var userColors = new Map(); var userColors = new Map();
var userColorsDark = new Map();
var targetId = 200; var targetId = 200;
// declare document text // declare document text
...@@ -49,6 +50,7 @@ $(document).ready(function() { ...@@ -49,6 +50,7 @@ $(document).ready(function() {
"annotation": {name: "Annotation", icon: "edit"} "annotation": {name: "Annotation", icon: "edit"}
} }
}); });
/* /*
* PAGE LOADED * PAGE LOADED
*/ */
...@@ -67,8 +69,8 @@ $(document).ready(function() { ...@@ -67,8 +69,8 @@ $(document).ready(function() {
/** /**
* POST: Save an annotation in the database * POST: Save an annotation in the database
* *
* @param annotationPostRequest * @param annotationPostRequest the post request
* @param responseHandler * @param responseHandler the response handler
*/ */
function createAnnotation(annotationPostRequest, responseHandler) { function createAnnotation(annotationPostRequest, responseHandler) {
var url = "http://localhost:8080/rest/annotations/"; var url = "http://localhost:8080/rest/annotations/";
...@@ -88,8 +90,9 @@ function createAnnotation(annotationPostRequest, responseHandler) { ...@@ -88,8 +90,9 @@ function createAnnotation(annotationPostRequest, responseHandler) {
/** /**
* PATCH: Alter an annotation * PATCH: Alter an annotation
* *
* @param annotationPatchRequest * @param id the annotation id
* @param responseHandler * @param annotationPatchRequest the patch request
* @param responseHandler the response handler
*/ */
function alterAnnotation(id, annotationPatchRequest, responseHandler) { function alterAnnotation(id, annotationPatchRequest, responseHandler) {
var url = "http://localhost:8080/rest/annotations/" + id; var url = "http://localhost:8080/rest/annotations/" + id;
...@@ -110,8 +113,8 @@ function alterAnnotation(id, annotationPatchRequest, responseHandler) { ...@@ -110,8 +113,8 @@ function alterAnnotation(id, annotationPatchRequest, responseHandler) {
* GET: Get all annotations for a specific target * GET: Get all annotations for a specific target
* *
* *
* @param targetId * @param targetId the target id
* @param responseHandler * @param responseHandler the response handler
*/ */
function getAnnotations(targetId, responseHandler) { function getAnnotations(targetId, responseHandler) {
var url = "http://localhost:8080/rest/annotations/target/" + targetId; var url = "http://localhost:8080/rest/annotations/target/" + targetId;
...@@ -160,10 +163,16 @@ function displayAnnotation(annotation) { ...@@ -160,10 +163,16 @@ function displayAnnotation(annotation) {
.mouseleave(function () { .mouseleave(function () {
deleteHighlightedText(); deleteHighlightedText();
}) })
.data(annotation) .data('annotation', annotation)
.attr('class', 'listelement') .attr('class', 'listelement')
.append( .append(
$('<div>').attr('class', 'annotation-card') $('<div>').attr('class', 'annotation-card')
.mouseenter(function () {
$(this).children('.annotation-header').css('background-color', getDarkUserColor(annotation.userId));
})
.mouseleave(function () {
$(this).children('.annotation-header').css('background-color', getUserColor(annotation.userId));
})
.append( .append(
$('<div>').attr('class', 'annotation-header') $('<div>').attr('class', 'annotation-header')
.css('background-color', getUserColor(annotation.userId)) .css('background-color', getUserColor(annotation.userId))
...@@ -223,6 +232,7 @@ function displayAnnotation(annotation) { ...@@ -223,6 +232,7 @@ 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
* @param userId the user id
*/ */
function addHighlightedText(startCharacter, endCharacter, userId) { function addHighlightedText(startCharacter, endCharacter, userId) {
// create <span> tag with the annotated text // create <span> tag with the annotated text
...@@ -248,7 +258,7 @@ function deleteHighlightedText() { ...@@ -248,7 +258,7 @@ function deleteHighlightedText() {
/** /**
* Get the text value of the selected text * Get the text value of the selected text
* *
* @returns {*} the text * @returns {string} the text
*/ */
function getSelectedText() { function getSelectedText() {
if(window.getSelection){ if(window.getSelection){
...@@ -271,23 +281,45 @@ function getSelectedText() { ...@@ -271,23 +281,45 @@ function getSelectedText() {
function getUserColor(userId) { function getUserColor(userId) {
// insert new color if there is no userId key // insert new color if there is no userId key
if (userColors.get(userId) == null) { if (userColors.get(userId) == null) {
userColors.set(userId, getRandomColor()); generateRandomColor(userId);
} }
// return the color // return the color
return userColors.get(userId); return userColors.get(userId);
} }
/**
* Get dark color based on user id
*
* @param userId the id of the user
* @returns {string} the dark user color
*/
function getDarkUserColor(userId) {
// insert new color if there is no userId key
if (userColorsDark.get(userId) == null) {
generateRandomColor(userId);
}
// return the color
return userColorsDark.get(userId);
}
/** /**
* Generate a random color of the format 'rgb(r, g, b)' * Generate a random color of the format 'rgb(r, g, b)'
* *
* @returns {string} the new color * @param userId the given user id
*/ */
function getRandomColor() { function generateRandomColor(userId) {
return 'rgb(' + var r = Math.floor(Math.random()*56)+170;
(Math.floor(Math.random()*56)+170) + ', ' + var g = Math.floor(Math.random()*56)+170;
(Math.floor(Math.random()*56)+170) + ', ' + var b = Math.floor(Math.random()*56)+170;
(Math.floor(Math.random()*56)+170) + var r_d = r - 50;
')'; var g_d = g - 50;
var b_d = b - 50;
var color = 'rgb(' + r + ',' + g + ',' + b + ')';
var colorDark = 'rgb(' + r_d + ',' + g_d + ',' + b_d + ')';
userColors.set(userId, color);
userColorsDark.set(userId, colorDark);
} }
/** /**
...@@ -357,7 +389,9 @@ function timestampIsToday(timestamp) { ...@@ -357,7 +389,9 @@ function timestampIsToday(timestamp) {
* @param element the given toggle button * @param element the given toggle button
*/ */
function toggleButtonHandler(element) { function toggleButtonHandler(element) {
// open and close annotation text
element.parent().siblings(".annotation-body").children("p").toggleClass("overflow-hidden"); element.parent().siblings(".annotation-body").children("p").toggleClass("overflow-hidden");
// toggle between up and down button
element.children("i").toggleClass("fa-chevron-down fa-chevron-up") element.children("i").toggleClass("fa-chevron-down fa-chevron-up")
} }
......
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