File size: 4,043 Bytes
3a6bdbe
 
 
 
 
 
 
48cf9d5
3a6bdbe
48cf9d5
3a6bdbe
 
 
 
 
 
 
863f2c8
 
3a6bdbe
 
 
766271a
04b67a1
b07d8cd
024bddf
f40c6b1
 
71f1442
ef74aaa
62f33d2
2ac7fd1
 
3a6bdbe
2ac7fd1
9562792
2ac7fd1
 
f40c6b1
2ac7fd1
 
 
85ffc78
7c0a097
b26733c
1d503b3
 
 
 
2ac7fd1
 
 
 
3a6bdbe
 
 
 
 
2ac7fd1
3a6bdbe
 
 
 
 
 
 
d901a31
3a6bdbe
 
 
 
 
 
 
 
 
07d713d
3a6bdbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41c463c
dd7b253
3a6bdbe
 
 
 
 
 
 
 
eec3eb9
41c463c
 
b29da53
3a6bdbe
 
 
 
 
 
 
3ebffdf
 
5af4e8b
54f954e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

/*
© 2023 Samuel Bradshaw
https://github.com/samuelbradshaw/transcript-tracer-js
*/


if (window.addEventListener) {
    window.addEventListener("resize", browserResize);
} else if (window.attachEvent) {
    window.attachEvent("onresize", browserResize);
}

function browserResize() {
    fixDragBtn();
}

var added = false;

var dragging = false;
var stack;
function fixDragBtn() {

    var gradio_container = document.getElementsByClassName("gradio-container")[0];
    var pb = w3_getStyleValue(gradio_container, "padding-bottom");
    pb = Number(pb.replace("px", ""));

    var show_api = document.getElementsByClassName("show-api")[0];
    var api = w3_getStyleValue(show_api, "height");
    apih = Number(api.replace("px", ""));

    // This is the actual value of the already updated document!
    var doc = document.documentElement.getBoundingClientRect();

    var hello = document.getElementById("hello");
    if (hello == null) return;
    var rect = hello.getBoundingClientRect();

    var h = window.visualViewport.height - (rect.top - doc.top) - pb  - apih;
    hello.style.height = `${h}px`;

    var wrapper = document.getElementById("right-area-wrapper");
    // var transcript = document.querySelector(`[data-tt-transcript="0"]`);
    var transcript = document.getElementById("transcript");

    var wrapper_rec = wrapper.getBoundingClientRect();
    var transcript_rec= transcript.getBoundingClientRect();
    h = wrapper_rec.height - (transcript_rec.top - wrapper_rec.top);
    transcript.style.height = `${h}px`;

    var leftpadding, dragleft, buttonwidth

    var containertop = Number(w3_getStyleValue(document.getElementById("container"), "top").replace("px", ""));

    leftareasize = Number(w3_getStyleValue(document.getElementById("left-area-wrapper"), "width").replace("px", ""));
    leftpadding = Number(w3_getStyleValue(document.getElementById("left-area"), "padding-left").replace("px", ""));
    buttonwidth = Number(w3_getStyleValue(document.getElementById("dragbar"), "width").replace("px", ""));
    leftareaheight = w3_getStyleValue(document.getElementById("left-area-wrapper"), "height");

    dragleft = leftareasize + leftpadding + (leftpadding / 2) - (buttonwidth / 2);

    document.getElementById("dragbar").style.width = "5px";
    document.getElementById("dragbar").style.top = containertop + "px";
    document.getElementById("dragbar").style.left = dragleft + "px";
    document.getElementById("dragbar").style.height = leftareaheight;
    document.getElementById("dragbar").style.cursor = "col-resize";
  
}

function dragstart(e) {
  e.preventDefault();
  dragging = true;
}

function dragmove(e) {
  if (dragging)
  { 
    document.getElementById("shield").style.display = "block";

      var percentage = (e.pageX / window.innerWidth) * 100;
      if (percentage > 5 && percentage < 98) {
        var mainPercentage = 100-percentage;
        document.getElementById("left-area-container").style.width = percentage + "%";
        document.getElementById("right-area-container").style.width = mainPercentage + "%";
        fixDragBtn();
      }
  }
}

function dragend() {
  document.getElementById("shield").style.display = "none";
  dragging = false;
}

function initfn() {
if (window.addEventListener && document.getElementById("container") != null) {
  document.getElementById("dragbar").addEventListener("mousedown", function(e) {dragstart(e);});
  document.getElementById("dragbar").addEventListener("touchstart", function(e) {dragstart(e);});
  window.addEventListener("mousemove", function(e) {dragmove(e);});
  window.addEventListener("touchmove", function(e) {dragmove(e);});
  window.addEventListener("mouseup", dragend);
  window.addEventListener("touchend", dragend);
  window.addEventListener("load", fixDragBtn);
}
  fixDragBtn();
}

initfn();

function w3_getStyleValue(elmnt,style) {
    if (window.getComputedStyle) {
        return window.getComputedStyle(elmnt,null).getPropertyValue(style);
    } else {
        return elmnt.currentStyle[style];
    }
}

fixDragBtn();