Skip to content

Commit d1b234b

Browse files
authored
Merge pull request #447 from makermelissa/beta
Code and Serial Panels printable
2 parents bc7338f + f92d05f commit d1b234b

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
</ul>
9191
</nav>
9292
</div>
93-
<div id="editor"></div>
93+
<div id="editor" tabindex="0"></div>
9494
</div>
9595
<div id="page-separator" class=""></div>
9696
<div id="serial-page" class="">
@@ -113,7 +113,7 @@
113113
</select>
114114
<canvas id="plotter-canvas"></canvas>
115115
</div>
116-
<div id="terminal"></div>
116+
<div id="terminal" tabindex="1"></div>
117117
</div>
118118
</div>
119119
<div id="footer-bar">

js/layout.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,49 @@ function isSerialVisible() {
2626
return serialPage.classList.contains('active');
2727
}
2828

29+
function setupPanelFocusHandlers() {
30+
// Removing existing handlers to avoid duplicates
31+
serialPage.removeEventListener('click', handleActivePanel);
32+
editorPage.removeEventListener('click', handleActivePanel);
33+
34+
// Adding new handlers
35+
serialPage.addEventListener('click', handleActivePanel);
36+
editorPage.addEventListener('click', handleActivePanel);
37+
}
38+
39+
function handleActivePanel(event) {
40+
const panel = event.currentTarget;
41+
setActivePanel(panel);
42+
}
43+
44+
function setActivePanel(panel) {
45+
editorPage.classList.remove('focused-panel');
46+
serialPage.classList.remove('focused-panel');
47+
48+
if (panel === serialPage && isSerialVisible()) {
49+
// Serial panel requested and visible
50+
serialPage.classList.add('focused-panel');
51+
} else if (panel === editorPage && isEditorVisible()) {
52+
// Editor panel requested and visible
53+
editorPage.classList.add('focused-panel');
54+
} else {
55+
// Requested panel is not visible, set other panel as focused
56+
if (isEditorVisible()) {
57+
editorPage.classList.add('focused-panel');
58+
} else {
59+
serialPage.classList.add('focused-panel');
60+
}
61+
}
62+
}
63+
2964
async function toggleEditor() {
3065
if (isSerialVisible()) {
3166
editorPage.classList.toggle('active');
3267
saveSetting(SETTING_EDITOR_VISIBLE, isEditorVisible());
3368
updatePageLayout(UPDATE_TYPE_EDITOR);
3469
}
70+
setupPanelFocusHandlers();
71+
setActivePanel(editorPage);
3572
}
3673

3774
async function toggleSerial() {
@@ -40,6 +77,8 @@ async function toggleSerial() {
4077
saveSetting(SETTING_TERMINAL_VISIBLE, isSerialVisible());
4178
updatePageLayout(UPDATE_TYPE_SERIAL);
4279
}
80+
setupPanelFocusHandlers();
81+
setActivePanel(serialPage);
4382
}
4483

4584
btnModeEditor.removeEventListener('click', toggleEditor);
@@ -229,4 +268,6 @@ pageSeparator.addEventListener('mousedown', async function (e) {
229268

230269
fixViewportHeight();
231270
window.addEventListener("resize", fixViewportHeight);
232-
loadPanelSettings();
271+
loadPanelSettings();
272+
setupPanelFocusHandlers();
273+
setActivePanel(editorPage);

sass/base/_base.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,23 @@ h5 {
8888
background-color: #d8d8d8;
8989
color: #888;
9090
}
91+
92+
@media print {
93+
body {
94+
visibility: hidden;
95+
}
96+
#editor-page.focused-panel #editor, #serial-page.focused-panel #terminal {
97+
visibility: visible;
98+
position: absolute;
99+
left: 0;
100+
top: 0;
101+
font-size: 2em;
102+
.xterm-rows {
103+
font-size: 1.2em;
104+
&> div {
105+
height: 1.2em !important;
106+
line-height: 1.2em !important;
107+
}
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)