Skip to content

Commit ce6fd73

Browse files
Sticky footer
1 parent ed4ed4d commit ce6fd73

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

runestone/activecode/js/activecode_brython.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ export default class BrythonActiveCode extends ActiveCode {
3030
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/highlight.min.js"></script>
3131
<style>
3232
pre {
33-
position: absolute; font-size: 13px; width: 94%; padding: 9.5px; line-height: 1.42857143; border: 1px solid #ccc; border-radius: 4px;
34-
overflow: auto; height: 200px; clear: both; position: sticky; bottom: 0; resize: both; background: white;
33+
position: sticky; max-height: 200px; width: 94%; overflow: auto; clear: both; resize: both; padding: 12px;
34+
background: white; font-size: 13px; line-height: 1.42857143; border: 1px solid #ccc; border-radius: 4px;
3535
}
3636
code{
3737
border: 1px solid #ccc; border-radius: 4px;
3838
}
39+
html, body{
40+
height: max-content; width: 100%;
41+
}
42+
.container-pre{
43+
position: fixed; bottom: 0px; width: 100%;
44+
}
3945
</style>
4046
</head>
4147
<body onload='brython()'>
@@ -46,8 +52,10 @@ import traceback
4652
4753
preElem = html.PRE()
4854
logger = html.CODE()
55+
container = html.DIV()
56+
container.classList.add("container-pre")
4957
preElem <= logger
50-
58+
container <= preElem
5159
class NewOut:
5260
def write(self, data):
5361
logger.innerHTML += str(data)
@@ -58,12 +66,14 @@ def my_exec(code):
5866
try:
5967
exec(code, locals())
6068
preElem.style.visibility = "visible"
61-
out_header = document.createElement("h4")
69+
out_header = document.createElement("text")
6270
out_header.innerHTML = "Output"
6371
out_header.style.font = "24px 'Arial'"
6472
logger.classList.add("plaintext")
73+
preElem.prepend(document.createElement("br"))
74+
preElem.prepend(document.createElement("br"))
6575
preElem.prepend(out_header)
66-
document <= preElem
76+
document <= container
6777
except SyntaxError as err:
6878
error_class = err.__class__.__name__
6979
detail = err.args[0]
@@ -89,17 +99,17 @@ def my_exec(code):
8999
error_header.style.font = "24px 'Arial'"
90100
preElem.prepend(error_header)
91101
preElem.style.visibility = "visible"
92-
preElem.style.top = "5px"
93102
preElem.style.backgroundColor = "#f2dede"
94103
preElem.style.border = "1px solid #ebccd1"
95104
logger.classList.add("python")
96105
97-
document <= preElem
106+
document <= container
98107
99108
my_exec("""${prog}
100109
""")
101110
102111
document <= html.SCRIPT("hljs.highlightAll();")
112+
document <= html.SCRIPT("let container = document.querySelector('.container-pre'); let height = container.offsetHeight; console.log(height); document.body.style.paddingBottom = String(height)+'px';")
103113
</script>
104114
</body>
105115
</html>

0 commit comments

Comments
 (0)