Skip to content

Commit 0276d54

Browse files
authored
Always try to keep the console underneath the website content (#257)
I was reluctant to do this until now, but hey, even if it break your layouts, it's for development error chasing, right? Shouldn't make you that mad to open issues? 🤔
1 parent abc89ae commit 0276d54

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

lib/web_console/templates/index.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66
<% only_on_error_page do %>
77
<%= render_javascript 'error_page' %>
88
<% end %>
9+
10+
<% only_on_regular_page do %>
11+
<%= render_javascript 'regular_page' %>
12+
<% end %>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Push the error page body upwards the size of the console.
2+
document.addEventListener('DOMContentLoaded', function() {
3+
var consoleElement = document.getElementById('console');
4+
var resizerElement = consoleElement.getElementsByClassName('resizer')[0];
5+
var bodyElement = document.body;
6+
7+
function setBodyElementBottomMargin(pixels) {
8+
bodyElement.style.marginBottom = pixels + 'px';
9+
}
10+
11+
var currentConsoleElementHeight = consoleElement.offsetHeight;
12+
setBodyElementBottomMargin(currentConsoleElementHeight);
13+
14+
resizerElement.addEventListener('mousedown', function(event) {
15+
function recordConsoleElementHeight(event) {
16+
resizerElement.removeEventListener('mouseup', recordConsoleElementHeight);
17+
18+
var currentConsoleElementHeight = consoleElement.offsetHeight;
19+
setBodyElementBottomMargin(currentConsoleElementHeight);
20+
}
21+
22+
resizerElement.addEventListener('mouseup', recordConsoleElementHeight);
23+
});
24+
});

lib/web_console/view.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ def only_on_error_page(*args)
1010
yield if Thread.current[:__web_console_exception].present?
1111
end
1212

13+
# Execute a block only on regular, non-error, pages.
14+
def only_on_regular_page(*args)
15+
yield if Thread.current[:__web_console_binding].present?
16+
end
17+
1318
# Render JavaScript inside a script tag and a closure.
1419
#
1520
# This one lets write JavaScript that will automatically get wrapped in a

0 commit comments

Comments
 (0)