Skip to content

Commit

Permalink
Fixes a few issues with tag highlighting.
Browse files Browse the repository at this point in the history
- Fixes error when viewing annotation replies and the annotation has a
  tag that is not assigned a color (because it was not setup for the
  assignment).
- Fixes the "Enable highlight tagging" checkbox so it is automatically
  checked when it was previously enabled.
- Ensures that when tags are added to an annotation, whitespace is
  automatically stripped. This fixes colorization issues caused by
  whitespace in the tag name.
  • Loading branch information
arthurian committed Sep 6, 2017
1 parent b167ae7 commit 4e9b3b6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ <h2>Annotation Dashboard Settings</h2>
<input class='hx-textfield full-width' type='number' id='pagination-limit' value='{{form.pagination_limit.value}}'>

<h3>Optional plug-ins</h3>

<input type='checkbox' {% if form.allow_highlights.value == "True" %}checked{% endif %} id='enable-tags'>
<input type='checkbox' {% if form.allow_highlights.value == True %}checked{% endif %} id='enable-tags'>
<label for='enable-tags'>Enable highlight tagging</label>

<div class='save' id='add-tags-button' {% if not form.allow_highlights.value or tag_list|length > 0 %}style='display:none;'{% endif %}>Add custom highlight tags</div>
Expand Down
18 changes: 16 additions & 2 deletions hx_lti_initializer/static/DashboardView.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,9 +799,8 @@

jQuery('.annotationModal svg').show();
if (annotationItem.tags && annotationItem.tags.length > 0) {
var tagColor = AController.main.tags[annotationItem.tags[annotationItem.tags.length-1]];
var tagColor = this.getAnnotationColor(annotationItem);
var cssColor = "rgba(" + tagColor.red + ", " + tagColor.green + ", " + tagColor.blue + ", 1)";

jQuery('.annotationModal svg path').attr('stroke', cssColor);
if (typeof(annotationItem.svg) === "undefined" ) {
jQuery('.annotationModal.item-modal-' + annotationItem.id.toString() + ' .zoomToImageBounds img').css('border', '3px solid ' + cssColor);
Expand All @@ -813,6 +812,21 @@

};

$.DashboardView.prototype.getAnnotationColor = function(annotationItem) {
var tags = annotationItem.hasOwnProperty('tags') && annotationItem.tags ? annotationItem.tags : [];
var tag_colors = AController.main.tags || {};
var tag_color = false;

for(var i = tags.length - 1; i >= 0; i--) {
if(tag_colors[tags[i]]) {
tag_color = tag_colors[tags[i]];
break;
}
}

return tag_color;
};

$.DashboardView.prototype.sortAnnotationsByCreated = function(annotations) {
var compareCreated = function(a, b) {
if (!("created" in a && "created" in b)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,16 @@ Annotator.Plugin.HighlightTags.prototype.updateViewer = function(field, annotati

// The following function is run when a person hits submit.
Annotator.Plugin.HighlightTags.prototype.pluginSubmit = function(field, annotation) {
arr = $(field).find('input[name=tags]').val().split(',');
//console.log(arr.indexOf("") !== -1);
//console.log(arr.length === 1);
if (arr.indexOf("") !== -1 && arr.length === 1) {
annotation.tags = [];
} else {
annotation.tags = arr;
var submitted_tags = $(field).find('input[name=tags]').val().split(',');
var submitted_tag, cleaned_tags = [];
for(var i = 0; i < submitted_tags.length; i++) {
submitted_tag = submitted_tags[i].trim();
if(submitted_tag !== "") {
cleaned_tags.push(submitted_tag);
}
}
//console.log(annotation.tags);
annotation.tags = cleaned_tags;
//console.log("highlightTags::pluginSubmit()", "submitted:", submitted_tags, "cleaned:", annotation.tags);
};

// The following will call the colorize function during an external call and then return
Expand All @@ -360,4 +361,4 @@ Annotator.Plugin.HighlightTags.prototype.externalCall = function() {
var self = Annotator._instances[0].plugins.HighlightTags;
self.colorize();
self.annotator.publish('finishedExternalCallToHighlightTags');
};
};

0 comments on commit 4e9b3b6

Please sign in to comment.