ydshieh HF staff commited on
Commit
52faf4e
1 Parent(s): c49adc5

Update transcript-tracer.js

Browse files
Files changed (1) hide show
  1. transcript-tracer.js +29 -15
transcript-tracer.js CHANGED
@@ -528,30 +528,44 @@ function handleWordDBClick(e) {
528
 
529
  function handleSelection() {
530
 
531
- // selection
532
- var temp = document.getSelection();
533
-
534
- if (temp.type != "Range") return;
535
-
536
 
537
  var startNode = temp.baseNode;
 
 
 
 
 
538
 
539
- var wordElement = startNode.parentNode;
540
-
541
- while (wordElement.className == "tt-whitespace") {
542
- wordElement = wordElement.nextElementSibling;
543
  }
544
 
545
- var wordIndex = wordElement.dataset.ttWord;
546
- var transcript = wordElement.closest('.tt-transcript');
547
- var mediaUrl = transcript.dataset.ttCurrentMediaUrl;
548
 
549
- var startWordElement = wordElement;
550
- var startWordIndex = wordIndex;
551
- var startSeconds = ttLinkedDataByMediaUrl[mediaUrl].wordTimings[wordIndex].startSeconds;
 
 
 
552
 
 
 
 
 
 
 
 
553
  console.log(startSeconds);
554
 
 
 
555
  var endNode = temp.extentNode;
556
 
557
  var wordElement = endNode.parentNode;
 
528
 
529
  function handleSelection() {
530
 
531
+ // Get selection
532
+ var selection = document.getSelection();
533
+ if (selection.type != "Range") return;
 
 
534
 
535
  var startNode = temp.baseNode;
536
+ var startWordElement = startNode.parentNode;
537
+
538
+ // These can be obtained simply with `startWordElement`
539
+ var transcript = startWordElement.closest('.tt-transcript');
540
+ var mediaUrl = transcript.dataset.ttCurrentMediaUrl;
541
 
542
+ // Used for highlight
543
+ var startWordElementForHighlight = startWordElement;
544
+ while (startWordElementForHighlight.className == "tt-whitespace") {
545
+ startWordElementForHighlight = startWordElementForHighlight.nextElementSibling;
546
  }
547
 
548
+ // Used for computing the start seconds
549
+ var startWordElementForTime = startWordElementForHighlight;
 
550
 
551
+ // TODO: ......
552
+ while (startWordElementForTime.className == "tt-whitespace") {
553
+ var wordIndex = startWordElementForTime.dataset.ttWord;
554
+ if (wordIndex === undefined) continue;
555
+ startWordElementForTime = startWordElementForTime.nextElementSibling;
556
+ }
557
 
558
+ var startWordIndexForTime = startWordElementForTime.dataset.ttWord;
559
+ var startSeconds = ttLinkedDataByMediaUrl[mediaUrl].wordTimings[startWordIndexForTime].startSeconds;
560
+
561
+ console.log(startWordElement);
562
+ console.log(startWordElementForHighlight);
563
+ console.log(startWordElementForTime);
564
+ console.log(startWordIndexForTime);
565
  console.log(startSeconds);
566
 
567
+ return;
568
+
569
  var endNode = temp.extentNode;
570
 
571
  var wordElement = endNode.parentNode;