From 75c905a985327d06a99214817aa38530d075caa2 Mon Sep 17 00:00:00 2001 From: Jakob Date: Wed, 18 Oct 2017 06:24:14 +0200 Subject: [PATCH] Feature/fix terminal notification (#681) * show terminal notification on top * show notification only when not scrolled down and new output available * terminal: move scrolled down check outside of push loop --- public/themes/pterodactyl/css/terminal.css | 1 + .../themes/pterodactyl/js/frontend/console.js | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/public/themes/pterodactyl/css/terminal.css b/public/themes/pterodactyl/css/terminal.css index 222639a1d..ecdd10ffc 100644 --- a/public/themes/pterodactyl/css/terminal.css +++ b/public/themes/pterodactyl/css/terminal.css @@ -61,6 +61,7 @@ opacity: .5; font-size: 16px; cursor: pointer; + z-index: 10; } .terminal-notify:hover { diff --git a/public/themes/pterodactyl/js/frontend/console.js b/public/themes/pterodactyl/js/frontend/console.js index 88ceb1196..3b6d90f42 100644 --- a/public/themes/pterodactyl/js/frontend/console.js +++ b/public/themes/pterodactyl/js/frontend/console.js @@ -116,13 +116,15 @@ $(document).ready(function () { }); $terminal.on('scroll', function () { - if ($(this).scrollTop() + $(this).innerHeight() + 50 < $(this)[0].scrollHeight) { - $scrollNotify.removeClass('hidden'); - } else { + if (isTerminalScrolledDown()) { $scrollNotify.addClass('hidden'); } }); +function isTerminalScrolledDown() { + return $terminal.scrollTop() + $terminal.innerHeight() + 50 > $terminal[0].scrollHeight; +} + window.scrollToBottom = function () { $terminal.scrollTop($terminal[0].scrollHeight); }; @@ -148,16 +150,20 @@ function pushToTerminal(string) { } if (TerminalQueue.length > 0) { + var scrolledDown = isTerminalScrolledDown(); + for (var i = 0; i < CONSOLE_PUSH_COUNT && TerminalQueue.length > 0; i++) { pushToTerminal(TerminalQueue[0]); - if (! $scrollNotify.is(':visible')) { - window.scrollToBottom(); - } - window.ConsoleElements++; TerminalQueue.shift(); } + + if (scrolledDown) { + window.scrollToBottom(); + } else if ($scrollNotify.hasClass('hidden')) { + $scrollNotify.removeClass('hidden'); + } var removeElements = window.ConsoleElements - CONSOLE_OUTPUT_LIMIT; if (removeElements > 0) {