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

feat: Scroll to highlighted text on card hover

parent a049883e
No related branches found
No related tags found
No related merge requests found
...@@ -341,6 +341,11 @@ function displayAnnotation(annotation) { ...@@ -341,6 +341,11 @@ function displayAnnotation(annotation) {
.data('annotation', annotation) .data('annotation', annotation)
.mouseenter(function () { .mouseenter(function () {
addHighlightedText(annotation.body.startCharacter, annotation.body.endCharacter, annotation.userToken); addHighlightedText(annotation.body.startCharacter, annotation.body.endCharacter, annotation.userToken);
// scroll document text to anchor element
let documentText = $('#documentText');
let anchor = $('#anchor');
documentText.scrollTo(anchor);
}) })
.mouseleave(function () { .mouseleave(function () {
deleteHighlightedText(); deleteHighlightedText();
...@@ -362,7 +367,7 @@ function displayAnnotation(annotation) { ...@@ -362,7 +367,7 @@ function displayAnnotation(annotation) {
*/ */
function addHighlightedText(startCharacter, endCharacter, userToken) { function addHighlightedText(startCharacter, endCharacter, userToken) {
// create <span> tag with the annotated text // create <span> tag with the annotated text
var replacement = $('<span></span>').css('background-color', getUserColor(userToken)).html(documentText.slice(startCharacter, endCharacter)); var replacement = $('<span></span>').attr('id', 'anchor').css('background-color', getUserColor(userToken)).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();
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" type="text/javascript"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" type="text/javascript"></script>
<!-- js - contextMenu script --> <!-- js - contextMenu script -->
<script src="https://swisnl.github.io/jQuery-contextMenu/dist/jquery.contextMenu.js" type="text/javascript"></script> <script src="https://swisnl.github.io/jQuery-contextMenu/dist/jquery.contextMenu.js" type="text/javascript"></script>
<!-- js - scrollTo -->
<script src="//cdn.jsdelivr.net/npm/jquery.scrollto@2.1.2/jquery.scrollTo.min.js"></script>
<!-- js - annotation websocket script --> <!-- js - annotation websocket script -->
<script src="../assets/js/annotationWebsocket.js"></script> <script src="../assets/js/annotationWebsocket.js"></script>
<!-- js - annotation REST script --> <!-- js - annotation REST script -->
......
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