Skip to content

Commit cc11cae

Browse files
committed
wip - fix core features at page
1 parent d85fc5e commit cc11cae

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

assets/js/main.js

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,23 @@ function renderTerminal() {
1818
const terminal = document.getElementById('terminal');
1919
let html = '';
2020
if (terminalState === 'menu') {
21-
html += '<span style="color:#888">Use ↑/↓ to select, Enter to run, → to view code.</span><br>';
22-
html += '<div class="mobile-menu-btns">';
21+
html += '<span style="color:#888">Use ↑/↓ to select, Enter/double-tap to run, → to view code.</span><br>';
22+
// Terminal printed menu with switch indicator
23+
html += '<div id="terminal-menu-list" style="margin-top:18px;">';
2324
javaFilesList.forEach((file, idx) => {
24-
html += `<button class="mobile-menu-btn${idx===selectedFileIdx?' active':''}" data-idx="${idx}">${file.label}</button><br>`;
25+
html += `<div class="terminal-menu-item${idx===selectedFileIdx?' active':''}" data-idx="${idx}" style="display:flex;align-items:center;gap:8px;cursor:pointer;">`;
26+
html += `<span style="display:inline-block;width:18px;text-align:center;">${idx===selectedFileIdx?'▶':'&nbsp;'}</span>`;
27+
html += `<span>${file.label}</span>`;
28+
html += '</div>';
2529
});
2630
html += '</div>';
31+
html += '<br><span style="color:#ffb86c">' + javaFilesList[selectedFileIdx].brief + '</span>';
32+
// Mobile menu buttons (below for accessibility)
33+
html += '<div class="mobile-menu-btns" style="margin-top:18px;">';
2734
javaFilesList.forEach((file, idx) => {
28-
html += (idx === selectedFileIdx ? '<b style="color:#ff5555">▶ ' : '&nbsp;&nbsp;') + file.label + (idx === selectedFileIdx ? '</b>' : '') + '<br>';
35+
html += `<button class="mobile-menu-btn${idx===selectedFileIdx?' active':''}" data-idx="${idx}">${file.label}</button>\n`;
2936
});
30-
html += '<br><span style="color:#ffb86c">' + javaFilesList[selectedFileIdx].brief + '</span>';
37+
html += '</div>';
3138
} else if (terminalState === 'output') {
3239
html += '<pre style="color:#ff5555;">' + lastOutputText + '</pre>';
3340
html += '<br><span style="color:#888">[→] Check source code | [b] Back to menu</span>';
@@ -41,6 +48,19 @@ function renderTerminal() {
4148
}
4249
terminal.innerHTML = html;
4350

51+
// Terminal menu item click (desktop & mobile)
52+
document.querySelectorAll('.terminal-menu-item').forEach(item => {
53+
item.onclick = function() {
54+
selectedFileIdx = parseInt(item.getAttribute('data-idx'));
55+
renderTerminal();
56+
};
57+
item.ondblclick = function() {
58+
selectedFileIdx = parseInt(item.getAttribute('data-idx'));
59+
terminalState = 'running';
60+
renderTerminal();
61+
window.runJavaFile(javaFilesList[selectedFileIdx].key, showOutput);
62+
};
63+
});
4464
// Mobile menu button logic
4565
document.querySelectorAll('.mobile-menu-btn').forEach(btn => {
4666
btn.onclick = function() {
@@ -51,7 +71,7 @@ function renderTerminal() {
5171
selectedFileIdx = parseInt(btn.getAttribute('data-idx'));
5272
terminalState = 'running';
5373
renderTerminal();
54-
runJavaFile(javaFilesList[selectedFileIdx].key, showOutput);
74+
window.runJavaFile(javaFilesList[selectedFileIdx].key, showOutput);
5575
};
5676
});
5777
// Mobile output/source navigation
@@ -85,7 +105,7 @@ function showSource() {
85105
}
86106

87107
// Keyboard navigation
88-
function listenForKeys(runJavaFile) {
108+
function listenForKeys() {
89109
document.addEventListener('keydown', function(e) {
90110
if (terminalState === 'menu') {
91111
if (e.key === 'ArrowUp') {
@@ -97,7 +117,7 @@ function listenForKeys(runJavaFile) {
97117
} else if (e.key === 'Enter') {
98118
terminalState = 'running';
99119
renderTerminal();
100-
runJavaFile(javaFilesList[selectedFileIdx].key, showOutput);
120+
window.runJavaFile(javaFilesList[selectedFileIdx].key, showOutput);
101121
} else if (e.key === 'ArrowRight') {
102122
showSource();
103123
}
@@ -129,11 +149,11 @@ window.addEventListener('DOMContentLoaded', function() {
129149
btn.onclick = showSource;
130150
document.body.appendChild(btn);
131151
}
132-
});
133152

134-
// Initial render
135-
showMenu();
136-
listenForKeys(runJavaFile);
153+
// Initial render and event setup after DOM is ready
154+
showMenu();
155+
listenForKeys();
156+
});
137157

138158
// Expose for Java runner
139159
window.showOutput = showOutput;

0 commit comments

Comments
 (0)