ydshieh HF staff commited on
Commit
ef87b45
1 Parent(s): b7efb7a

Update transcript-tracer.js

Browse files
Files changed (1) hide show
  1. transcript-tracer.js +43 -0
transcript-tracer.js CHANGED
@@ -258,6 +258,11 @@ function linkTranscripts(mediaPlayer) {
258
  for (const word of document.querySelectorAll('.tt-word')) {
259
  word.addEventListener('click', handleWordClick);
260
  }
 
 
 
 
 
261
  }
262
  }
263
  }
@@ -283,6 +288,11 @@ function unlinkTranscript(transcript) {
283
  for (const word of document.querySelectorAll('.tt-word')) {
284
  word.removeEventListener('click', handleWordClick);
285
  }
 
 
 
 
 
286
  }
287
 
288
 
@@ -485,4 +495,37 @@ function handleWordClick(e) {
485
 
486
  }
487
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
488
  loadTranscriptTracer({ blockSelector: null, phraseSelector: null, alignmentFuzziness: 0, timeOffset: 0, autoScroll: "word", clickable: true})
 
258
  for (const word of document.querySelectorAll('.tt-word')) {
259
  word.addEventListener('click', handleWordClick);
260
  }
261
+
262
+ for (const word of document.querySelectorAll('.tt-word')) {
263
+ word.addEventListener('dblclick', handleWordDBClick);
264
+ }
265
+
266
  }
267
  }
268
  }
 
288
  for (const word of document.querySelectorAll('.tt-word')) {
289
  word.removeEventListener('click', handleWordClick);
290
  }
291
+
292
+ for (const word of document.querySelectorAll('.tt-word')) {
293
+ word.removeEventListener('dblclick', handleWordDBClick);
294
+ }
295
+
296
  }
297
 
298
 
 
495
 
496
  }
497
 
498
+ // Handle when a word in the transcript with an event listener is clicked
499
+ function handleDBWordClick(e) {
500
+ var wordElement = e.currentTarget;
501
+ var wordIndex = wordElement.dataset.ttWord;
502
+ var transcript = wordElement.closest('.tt-transcript');
503
+ var mediaUrl = transcript.dataset.ttCurrentMediaUrl;
504
+ var startSeconds = ttLinkedDataByMediaUrl[mediaUrl].wordTimings[wordIndex].startSeconds
505
+
506
+ ttLinkedDataByMediaUrl[mediaUrl].mediaElement.currentTime = startSeconds;
507
+
508
+ var ttData = ttLinkedDataByMediaUrl[mediaUrl];
509
+
510
+ // Make sure the correct transcript is selected
511
+ if (!ttCurrentTranscript || ttCurrentTranscript.dataset.ttTranscript != ttData.transcriptIndex) {
512
+ ttCurrentTranscript = document.querySelector(`[data-tt-transcript="${ttData.transcriptIndex}"]`);
513
+ }
514
+
515
+ // Clear words that were highlighted from the previous event
516
+ clearHighlightedWords(ttCurrentTranscript);
517
+
518
+ // Mark words
519
+ wordElement.classList.add('tt-current-word');
520
+
521
+ for (const wordElement of ttCurrentTranscript.getElementsByClassName('tt-word')) {
522
+ if (wordElement.classList.contains('tt-current-word')) break;
523
+ wordElement.classList.add('tt-previous-word');
524
+ }
525
+
526
+ // pause
527
+ ttActivePlayer.play()
528
+ }
529
+
530
+
531
  loadTranscriptTracer({ blockSelector: null, phraseSelector: null, alignmentFuzziness: 0, timeOffset: 0, autoScroll: "word", clickable: true})