Skip to content

Commit

Permalink
Open annotation automatically on link click
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Aug 3, 2024
1 parent b98e4a0 commit c6ef83c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 12 additions & 1 deletion app/assets/javascripts/thyme/thyme_player.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
function openAnnotationIfSpecifiedInUrl() {
const annotationValue = new URLSearchParams(window.location.search).get("ann");
if (!annotationValue) {
return;
}
const annotationId = Number(annotationValue);
thymeAttributes.annotationArea.showAnnotationWithId(annotationId);
}

$(document).on("turbolinks:load", function () {
/*
VIDEO INITIALIZATION
Expand Down Expand Up @@ -96,7 +105,9 @@ $(document).on("turbolinks:load", function () {
thymeAttributes.annotationManager = annotationManager;

// update annotations manually once as initialization
annotationManager.updateAnnotations();
annotationManager.updateAnnotations(() => {
openAnnotationIfSpecifiedInUrl();
});

// Update annotations after deleting an annotation
const ANNOTATION_DELETE_SELECTOR = "#annotation-delete-button";
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/annotations_overview_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ class AnnotationsOverviewController < ApplicationController

def show
@user_annotations = Annotation.where(user_id: current_user.id).map do |annotation|
link = helpers.video_link_timed(annotation.medium_id, annotation.timestamp)
link += "&ann=#{annotation.id}"
{
category: annotation.category,
text: annotation.comment_optional,
link: helpers.video_link_timed(annotation.medium_id, annotation.timestamp),
link: link,
color: annotation.color,
updated_at: annotation.updated_at
}
Expand Down

0 comments on commit c6ef83c

Please sign in to comment.