/* © 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();