]> prime8.dev >> repos - ttyd.git/commitdiff
Ony fire resize event when it ends
authorShuanglei Tao <tsl0922@gmail.com>
Sat, 10 Jun 2017 00:22:06 +0000 (08:22 +0800)
committerShuanglei Tao <tsl0922@gmail.com>
Sat, 10 Jun 2017 00:22:06 +0000 (08:22 +0800)
html/js/app.js
src/index.html

index 2b5a0fbd6f23177cc1c1b9edf97825e6fe0a8b5a..47a732ce8bef2c0fce049424f6dd1e720108ec6d 100644 (file)
@@ -1,6 +1,6 @@
 (function() {
     var terminalContainer = document.getElementById('terminal-container'),
-        httpsEnabled = window.location.protocol == "https:",
+        httpsEnabled = window.location.protocol === "https:",
         url = (httpsEnabled ? 'wss://' : 'ws://') + window.location.host + window.location.pathname + 'ws',
         authToken = (typeof tty_auth_token !== 'undefined') ? tty_auth_token : null,
         protocols = ["tty"],
             });
 
             term.on('open', function() {
-                window.addEventListener('resize', function(event) {
-                    term.fit();
+                // https://stackoverflow.com/a/27923937/1727928
+                window.addEventListener('resize', function() {
+                    clearTimeout(window.resizedFinished);
+                    window.resizedFinished = setTimeout(function () {
+                        term.fit();
+                    }, 250);
                 });
                 window.addEventListener('beforeunload', unloadCallback);
                 term.fit();
index 65331d715fe04c86804805ae9074f65224a0f539..bbf180338310d39511e602bd630e57d828f9822b 100644 (file)
@@ -17,6 +17,6 @@ break;case"mouseup":e=3;break;case"DOMMouseScroll":e=t.detail<0?64:65;break;case
 <body>
        <div id="terminal-container"></div>
        <script src="auth_token.js"></script>
-       <script>!function(){var e,n,o,t=document.getElementById("terminal-container"),i="https:"==window.location.protocol,s=(i?"wss://":"ws://")+window.location.host+window.location.pathname+"ws",a="undefined"!=typeof tty_auth_token?tty_auth_token:null,c=["tty"],r=-1,l=function(){var i=new WebSocket(s,c),f=function(e){var n="Close terminal? this will also terminate the command.";return(e||window.event).returnValue=n,n};i.onopen=function(s){for(console.log("Websocket connection opened"),o=!1,i.send(JSON.stringify({AuthToken:a})),n=setInterval(d,3e4,i),"undefined"!=typeof e&&e.destroy(),e=new Terminal,e.on("resize",function(n){i.readyState===WebSocket.OPEN&&i.send("2"+JSON.stringify({columns:n.cols,rows:n.rows})),setTimeout(function(){e.showOverlay(n.cols+"x"+n.rows)},500)}),e.on("data",function(e){i.readyState===WebSocket.OPEN&&i.send("0"+e)}),e.on("open",function(){window.addEventListener("resize",function(n){e.fit()}),window.addEventListener("beforeunload",f),e.fit()});t.firstChild;)t.removeChild(t.firstChild);e.open(t,!0)},i.onmessage=function(n){var o=n.data.slice(1);switch(n.data[0]){case"0":e.writeUTF8(window.atob(o));break;case"1":break;case"2":document.title=o;break;case"3":var t=JSON.parse(o);Object.keys(t).forEach(function(n){console.log("Setting "+n+": "+t[n]),e.setOption(n,t[n])});break;case"4":r=JSON.parse(o),console.log("Enabling reconnect: "+r+" seconds")}},i.onclose=function(t){console.log("Websocket connection closed with code: "+t.code),e&&(e.off("data"),e.off("resize"),o||e.showOverlay("Connection Closed",null)),window.removeEventListener("beforeunload",f),clearInterval(n),1e3!==t.code&&r>0&&setTimeout(l,1e3*r)}},d=function(e){e.send("1")};l()}();</script>
+       <script>!function(){var e,n,o,t=document.getElementById("terminal-container"),i="https:"===window.location.protocol,s=(i?"wss://":"ws://")+window.location.host+window.location.pathname+"ws",c="undefined"!=typeof tty_auth_token?tty_auth_token:null,a=["tty"],r=-1,d=function(){var i=new WebSocket(s,a),w=function(e){var n="Close terminal? this will also terminate the command.";return(e||window.event).returnValue=n,n};i.onopen=function(s){for(console.log("Websocket connection opened"),o=!1,i.send(JSON.stringify({AuthToken:c})),n=setInterval(l,3e4,i),"undefined"!=typeof e&&e.destroy(),e=new Terminal,e.on("resize",function(n){i.readyState===WebSocket.OPEN&&i.send("2"+JSON.stringify({columns:n.cols,rows:n.rows})),setTimeout(function(){e.showOverlay(n.cols+"x"+n.rows)},500)}),e.on("data",function(e){i.readyState===WebSocket.OPEN&&i.send("0"+e)}),e.on("open",function(){window.addEventListener("resize",function(){clearTimeout(window.resizedFinished),window.resizedFinished=setTimeout(function(){e.fit()},250)}),window.addEventListener("beforeunload",w),e.fit()});t.firstChild;)t.removeChild(t.firstChild);e.open(t,!0)},i.onmessage=function(n){var o=n.data.slice(1);switch(n.data[0]){case"0":e.writeUTF8(window.atob(o));break;case"1":break;case"2":document.title=o;break;case"3":var t=JSON.parse(o);Object.keys(t).forEach(function(n){console.log("Setting "+n+": "+t[n]),e.setOption(n,t[n])});break;case"4":r=JSON.parse(o),console.log("Enabling reconnect: "+r+" seconds")}},i.onclose=function(t){console.log("Websocket connection closed with code: "+t.code),e&&(e.off("data"),e.off("resize"),o||e.showOverlay("Connection Closed",null)),window.removeEventListener("beforeunload",w),clearInterval(n),1e3!==t.code&&r>0&&setTimeout(d,1e3*r)}},l=function(e){e.send("1")};d()}();</script>
 </body>
 </html>