diff options
-rw-r--r-- | logfiles-tail-html.lsp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/logfiles-tail-html.lsp b/logfiles-tail-html.lsp index 6bfe26d..72725ad 100644 --- a/logfiles-tail-html.lsp +++ b/logfiles-tail-html.lsp @@ -12,7 +12,28 @@ {name:'<% io.write(form.value.filename.value) if form.value.grep.value ~= "" then io.write("',grep:'"..form.value.grep.value) end %>', offset:currentoffset}, function(data) { data.value.filecontent.value = data.value.filecontent.value.split("\n").join("<br>\n"); - $("#filecontent").append(data.value.filecontent.value).scrollTop(999999999); + + /* Before updating content, determine where we're scrolled to. If we're within 25 pixels of + the bottom, we'll stick to the bottom. */ + var content = $("#filecontent").get(0); + var currentHeight = 0; + var scrollTop = content.scrollTop; + if (content.scrollHeight > 0) + currentHeight = content.scrollHeight; + else + if (content.offsetHeight > 0) + currentHeight = content.offsetHeight; + if (currentHeight - scrollTop - ((content.style.pixelHeight) ? content.style.pixelHeight : content.offsetHeight) < 25) + scrollTop = currentHeight; + + $("#filecontent").append(data.value.filecontent.value); + + /* Now, set the scroll. */ + if (scrollTop < currentHeight) + content.scrollTop = scrollTop; + else + content.scrollTop = content.scrollHeight; + currentoffset = data.value.filesize.value; $("DT:contains('File size')").next().text(currentoffset); } |