Skip to content

Commit 137ab1f

Browse files
SuperMaxusacopy
authored andcommitted
refactor: extract code into functions
1 parent a25e718 commit 137ab1f

File tree

1 file changed

+52
-28
lines changed

1 file changed

+52
-28
lines changed

src/browser/main.js

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,30 +2348,62 @@ function init_ui(profile, settings, emulator)
23482348
emulator.screen_set_scale(n, n);
23492349
}
23502350

2351-
$("toggle_ui").onclick = function()
2351+
/**
2352+
* @param {boolean} enabled
2353+
*/
2354+
function enable_theatre_ui(enabled)
23522355
{
2353-
theatre_ui = !theatre_ui;
2356+
theatre_ui = enabled;
23542357

23552358
$("runtime_options").style.display = theatre_ui ? "block" : "none";
23562359
$("runtime_infos").style.display = theatre_ui ? "block" : "none";
23572360
$("filesystem_panel").style.display = (filesystem_is_enabled && theatre_ui) ? "block" : "none";
23582361

23592362
$("toggle_ui").value = (theatre_ui ? "Hide" : "Show") + " UI";
2360-
$("toggle_ui").blur();
2361-
};
2363+
}
23622364

2363-
$("toggle_theatre").onclick = function()
2365+
/**
2366+
* @param {boolean} enabled
2367+
*/
2368+
function enable_zoom_to_fit(enabled)
23642369
{
2365-
theatre_mode = !theatre_mode;
2370+
theatre_zoom_to_fit = enabled;
2371+
$("scale").disabled = theatre_zoom_to_fit;
2372+
2373+
if(theatre_zoom_to_fit)
2374+
{
2375+
window.addEventListener("resize", zoom_to_fit, true);
2376+
emulator.add_listener("screen-set-size", zoom_to_fit);
2377+
2378+
zoom_to_fit();
2379+
}
2380+
else
2381+
{
2382+
window.removeEventListener("resize", zoom_to_fit, true);
2383+
emulator.remove_listener("screen-set-size", zoom_to_fit);
2384+
2385+
const n = parseFloat($("scale").value) || 1;
2386+
emulator.screen_set_scale(n, n);
2387+
}
2388+
2389+
$("toggle_zoom_to_fit").value = (theatre_zoom_to_fit ? "Dis" : "En") + "able zoom to fit";
2390+
}
2391+
2392+
/**
2393+
* @param {boolean} enabled
2394+
*/
2395+
function enable_theatre_mode(enabled)
2396+
{
2397+
theatre_mode = enabled;
23662398

23672399
if(!theatre_ui)
23682400
{
2369-
$("toggle_ui").click();
2401+
enable_theatre_ui(true);
23702402
}
23712403

23722404
if(!theatre_mode && theatre_zoom_to_fit)
23732405
{
2374-
$("toggle_zoom_to_fit").click();
2406+
enable_zoom_to_fit(false);
23752407
}
23762408

23772409
for(const el of ["screen_container", "runtime_options", "runtime_infos", "filesystem_panel"])
@@ -2387,31 +2419,23 @@ function init_ui(profile, settings, emulator)
23872419
document.body.style.overflow = theatre_mode ? "hidden" : "visible";
23882420

23892421
$("toggle_theatre").value = (theatre_mode ? "Dis" : "En") + "able theatre mode";
2422+
}
2423+
2424+
$("toggle_ui").onclick = function()
2425+
{
2426+
enable_theatre_ui(!theatre_ui);
2427+
$("toggle_ui").blur();
2428+
};
2429+
2430+
$("toggle_theatre").onclick = function()
2431+
{
2432+
enable_theatre_mode(!theatre_mode);
23902433
$("toggle_theatre").blur();
23912434
};
23922435

23932436
$("toggle_zoom_to_fit").onclick = function()
23942437
{
2395-
theatre_zoom_to_fit = !theatre_zoom_to_fit;
2396-
$("scale").disabled = theatre_zoom_to_fit;
2397-
2398-
if(theatre_zoom_to_fit)
2399-
{
2400-
window.addEventListener("resize", zoom_to_fit, true);
2401-
emulator.add_listener("screen-set-size", zoom_to_fit);
2402-
2403-
zoom_to_fit();
2404-
}
2405-
else
2406-
{
2407-
window.removeEventListener("resize", zoom_to_fit, true);
2408-
emulator.remove_listener("screen-set-size", zoom_to_fit);
2409-
2410-
const n = parseFloat($("scale").value) || 1;
2411-
emulator.screen_set_scale(n, n);
2412-
}
2413-
2414-
$("toggle_zoom_to_fit").value = (theatre_zoom_to_fit ? "Dis" : "En") + "able zoom to fit";
2438+
enable_zoom_to_fit(!theatre_zoom_to_fit);
24152439
$("toggle_zoom_to_fit").blur();
24162440
};
24172441

0 commit comments

Comments
 (0)