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
This commit is contained in:
Jakob 2017-10-18 06:24:14 +02:00 committed by Dane Everitt
parent 2b80de03df
commit 75c905a985
2 changed files with 14 additions and 7 deletions

View file

@ -61,6 +61,7 @@
opacity: .5; opacity: .5;
font-size: 16px; font-size: 16px;
cursor: pointer; cursor: pointer;
z-index: 10;
} }
.terminal-notify:hover { .terminal-notify:hover {

View file

@ -116,13 +116,15 @@ $(document).ready(function () {
}); });
$terminal.on('scroll', function () { $terminal.on('scroll', function () {
if ($(this).scrollTop() + $(this).innerHeight() + 50 < $(this)[0].scrollHeight) { if (isTerminalScrolledDown()) {
$scrollNotify.removeClass('hidden');
} else {
$scrollNotify.addClass('hidden'); $scrollNotify.addClass('hidden');
} }
}); });
function isTerminalScrolledDown() {
return $terminal.scrollTop() + $terminal.innerHeight() + 50 > $terminal[0].scrollHeight;
}
window.scrollToBottom = function () { window.scrollToBottom = function () {
$terminal.scrollTop($terminal[0].scrollHeight); $terminal.scrollTop($terminal[0].scrollHeight);
}; };
@ -148,16 +150,20 @@ function pushToTerminal(string) {
} }
if (TerminalQueue.length > 0) { if (TerminalQueue.length > 0) {
var scrolledDown = isTerminalScrolledDown();
for (var i = 0; i < CONSOLE_PUSH_COUNT && TerminalQueue.length > 0; i++) { for (var i = 0; i < CONSOLE_PUSH_COUNT && TerminalQueue.length > 0; i++) {
pushToTerminal(TerminalQueue[0]); pushToTerminal(TerminalQueue[0]);
if (! $scrollNotify.is(':visible')) {
window.scrollToBottom();
}
window.ConsoleElements++; window.ConsoleElements++;
TerminalQueue.shift(); TerminalQueue.shift();
} }
if (scrolledDown) {
window.scrollToBottom();
} else if ($scrollNotify.hasClass('hidden')) {
$scrollNotify.removeClass('hidden');
}
var removeElements = window.ConsoleElements - CONSOLE_OUTPUT_LIMIT; var removeElements = window.ConsoleElements - CONSOLE_OUTPUT_LIMIT;
if (removeElements > 0) { if (removeElements > 0) {