Skip to content

Commit 18ae200

Browse files
committed
fix mobile buttons
1 parent 3b11e4f commit 18ae200

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

assets/js/main.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Import modules
22
import { runJavaFile } from './wasm-jvm.js';
3+
// --- Add: Import Java source code for source view ---
4+
import { javaFiles } from './source.js';
35

46
// --- State Machine for Terminal UI ---
57
const javaFilesList = [
@@ -17,21 +19,51 @@ function renderTerminal() {
1719
let html = '';
1820
if (terminalState === 'menu') {
1921
html += '<span style="color:#888">Use ↑/↓ to select, Enter to run, → to view code.</span><br>';
22+
html += '<div class="mobile-menu-btns">';
23+
javaFilesList.forEach((file, idx) => {
24+
html += `<button class="mobile-menu-btn${idx===selectedFileIdx?' active':''}" data-idx="${idx}">${file.label}</button><br>`;
25+
});
26+
html += '</div>';
2027
javaFilesList.forEach((file, idx) => {
2128
html += (idx === selectedFileIdx ? '<b style="color:#ff5555">▶ ' : '&nbsp;&nbsp;') + file.label + (idx === selectedFileIdx ? '</b>' : '') + '<br>';
2229
});
2330
html += '<br><span style="color:#ffb86c">' + javaFilesList[selectedFileIdx].brief + '</span>';
2431
} else if (terminalState === 'output') {
2532
html += '<pre style="color:#ff5555;">' + lastOutputText + '</pre>';
2633
html += '<br><span style="color:#888">[→] Check source code | [b] Back to menu</span>';
34+
html += '<div class="mobile-output-btns"><button id="mobile-source-btn">Check Source Code</button> <button id="mobile-back-btn">Back to Menu</button></div>';
2735
} else if (terminalState === 'source') {
2836
html += '<pre style="color:#ff5555;">' + javaFiles[javaFilesList[selectedFileIdx].key] + '</pre>';
2937
html += '<br><span style="color:#888">[←] Back to output | [b] Back to menu</span>';
38+
html += '<div class="mobile-source-btns"><button id="mobile-back-output-btn">Back to Output</button> <button id="mobile-back-menu-btn">Back to Menu</button></div>';
3039
} else if (terminalState === 'running') {
3140
html += '<span style="color:#888">Running Java...</span>';
3241
}
3342
terminal.innerHTML = html;
34-
// Show/hide mobile source button
43+
44+
// Mobile menu button logic
45+
document.querySelectorAll('.mobile-menu-btn').forEach(btn => {
46+
btn.onclick = function() {
47+
selectedFileIdx = parseInt(btn.getAttribute('data-idx'));
48+
renderTerminal();
49+
};
50+
btn.ondblclick = function() {
51+
selectedFileIdx = parseInt(btn.getAttribute('data-idx'));
52+
terminalState = 'running';
53+
renderTerminal();
54+
runJavaFile(javaFilesList[selectedFileIdx].key, showOutput);
55+
};
56+
});
57+
// Mobile output/source navigation
58+
const srcBtn = document.getElementById('mobile-source-btn');
59+
if (srcBtn) srcBtn.onclick = showSource;
60+
const backBtn = document.getElementById('mobile-back-btn');
61+
if (backBtn) backBtn.onclick = showMenu;
62+
const backOutputBtn = document.getElementById('mobile-back-output-btn');
63+
if (backOutputBtn) backOutputBtn.onclick = () => showOutput(lastOutputText);
64+
const backMenuBtn = document.getElementById('mobile-back-menu-btn');
65+
if (backMenuBtn) backMenuBtn.onclick = showMenu;
66+
// Show/hide desktop source button
3567
const btn = document.getElementById('show-source-btn');
3668
if (btn) btn.style.display = (terminalState === 'output') ? 'inline-block' : 'none';
3769
}

0 commit comments

Comments
 (0)