Skip to content

Commit f6cc337

Browse files
committed
Replace all 4 instances of jBox-style modal dialog boxes with HTML dialog element
Notes: - The Power & Battery (2), OSD, and CLI tabs have been updated accordingly - HTML default control behavior was used whereever possible - HTML indent for the dialog tag is deliberately off to minimize diff noise in GitHub - Layout is not 100% identical, but spiratually the same - in most cases no changes were needed - OSD’s Font Manager dialog didn’t transition cleanly, so includes some slight restyling - OSD Font Manager previously had a green background/color for the graphic - that “just works” now - Specific cleanup (i.e., calling destroy()) does not seem necessary and was removed - Removal of jBox from setup.js and global scope seems not to affect jBox tooltips - Replacement of single quotes with double in main.js was done automatically by Prettier
1 parent f068b1a commit f6cc337

File tree

13 files changed

+144
-121
lines changed

13 files changed

+144
-121
lines changed

locales/en/messages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5320,6 +5320,10 @@
53205320
"message": "Font",
53215321
"description": "Content of the selector for the OSD Font in the preview"
53225322
},
5323+
"osdSetupFontManagerTitle": {
5324+
"message": "OSD Font Manager",
5325+
"description": "Dialog title"
5326+
},
53235327
"osdSetupFontTypeDefault": {
53245328
"message": "Default",
53255329
"description": "Font Default"

src/css/main.less

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ a.disabled {
4141
cursor: default;
4242
color: #999;
4343
}
44+
.html-dialog {
45+
border-color: var(--primary-500);
46+
padding: 0px;
47+
}
48+
.html-dialog-content {
49+
padding: 15px 15px;
50+
}
4451
.background_paper {
4552
background-color: var(--surface-200);
4653
background-image:

src/css/tabs/cli.less

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,17 @@
7575
color: white;
7676
}
7777
}
78-
.jBox-container {
79-
textarea#preview {
80-
background-color: rgba(0, 0, 0, 0.75);
81-
width: 100%;
82-
resize: none;
83-
overflow-y: scroll;
84-
overflow-x: hidden;
85-
font-family: monospace;
86-
color: white;
87-
padding: 5px;
88-
margin-bottom: 5px;
89-
}
78+
textarea#preview {
79+
background-color: rgba(0, 0, 0, 0.75);
80+
width: 100%;
81+
resize: none;
82+
overflow-y: scroll;
83+
overflow-x: hidden;
84+
font-family: monospace;
85+
color: white;
86+
box-sizing: border-box;
87+
padding: 5px;
88+
margin-bottom: 5px;
9089
}
9190
.cli-textcomplete-dropdown {
9291
border: 1px solid var(--surface-500);

src/css/tabs/osd.less

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
--context-menu-z-index: 10001;
33

44
.info {
5-
margin: 10px 0 0 0;
65
position: relative;
76
width: 100%;
87
.progressLabel {
98
position: absolute;
109
width: 100%;
1110
height: 26px;
12-
top: 0;
13-
left: 0;
11+
margin-top: -22px;
1412
text-align: center;
15-
line-height: 24px;
1613
color: white;
1714
font-weight: bold;
1815
a {
@@ -68,12 +65,6 @@
6865
width: 18px;
6966
height: 18px;
7067
}
71-
ul {
72-
li {
73-
list-style: circle;
74-
margin-left: 30px;
75-
}
76-
}
7768
.options {
7869
position: relative;
7970
margin-bottom: 10px;
@@ -382,21 +373,23 @@
382373
font-weight: normal;
383374
}
384375
}
385-
.grid-col {
386-
margin: 0px;
376+
#font-logo {
377+
display: flex;
378+
margin-bottom: 2em;
387379
}
388380
#font-logo-preview-container {
389381
background: rgba(0, 255, 0, 0.4);
390382
margin-bottom: 10px;
391-
box-sizing: border-box;
383+
padding: 10px;
392384
}
393385
#font-logo-preview {
394386
background: rgba(0, 255, 0, 1);
395387
line-height: 0;
396388
margin: auto;
397389
}
398390
#font-logo-info {
399-
font-size: 125%;
391+
flex: 1;
392+
margin-left: 2em;
400393
line-height: 150%;
401394
h3 {
402395
margin-bottom: 0.2em;
@@ -431,11 +424,11 @@
431424
font-size: 9pt !important;
432425
cursor: pointer;
433426
}
427+
.font-preview {
428+
padding-bottom: 1.25rem;
429+
}
434430
.fontpresets_wrapper {
435-
display: inline-block;
436-
position: absolute;
437-
right: 1.2em;
438-
top: 0.8em;
431+
padding: 1rem 0;
439432
}
440433
.fontpresets {
441434
background: var(--surface-200);

src/js/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import "./jqueryPlugins";
22
import $ from "jquery";
3-
import "jbox";
43
import "../components/init.js";
54
import { gui_log } from "./gui_log.js";
65
// same, msp seems to be everywhere used from global scope

src/js/tabs/cli.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import { reinitializeConnection } from "../serial_backend";
88
import CONFIGURATOR from "../data_storage";
99
import CliAutoComplete from "../CliAutoComplete";
1010
import { gui_log } from "../gui_log";
11-
import jBox from "jbox";
1211
import $ from "jquery";
1312
import { serial } from "../serial";
1413
import FileSystem from "../FileSystem";
1514
import { ispConnected } from "../utils/connection";
15+
import { initializeModalDialog } from "../utils/initializeModalDialog";
1616

1717
const cli = {
1818
lineDelayMs: 5,
@@ -151,20 +151,16 @@ cli.initialize = function (callback) {
151151

152152
function previewCommands(result, fileName) {
153153
if (!self.GUI.snippetPreviewWindow) {
154-
self.GUI.snippetPreviewWindow = new jBox("Modal", {
155-
id: "snippetPreviewWindow",
156-
width: "auto",
157-
height: "auto",
158-
closeButton: "title",
159-
animation: false,
160-
isolateScroll: false,
161-
title: i18n.getMessage("cliConfirmSnippetDialogTitle", { fileName: fileName }),
162-
content: $("#snippetpreviewcontent"),
163-
onCreated: () => $("#snippetpreviewcontent a.confirm").click(() => executeSnippet(fileName)),
164-
});
154+
self.GUI.snippetPreviewWindow = initializeModalDialog(
155+
null,
156+
"#snippetpreviewdialog",
157+
"cliConfirmSnippetDialogTitle",
158+
{ fileName: fileName },
159+
);
160+
$("#snippetpreviewcontent a.confirm").click(() => executeSnippet(fileName));
165161
}
166162
previewArea.val(result);
167-
self.GUI.snippetPreviewWindow.open();
163+
self.GUI.snippetPreviewWindow.showModal();
168164
}
169165

170166
const file = await FileSystem.pickOpenFile(i18n.getMessage("fileSystemPickerFiles", { typeof: "TXT" }), ".txt");
@@ -530,10 +526,6 @@ cli.supportWarningDialog = function (onAccept) {
530526
};
531527

532528
cli.cleanup = function (callback) {
533-
if (TABS.cli.GUI.snippetPreviewWindow) {
534-
TABS.cli.GUI.snippetPreviewWindow.destroy();
535-
TABS.cli.GUI.snippetPreviewWindow = null;
536-
}
537529
if (!(CONFIGURATOR.connectionValid && CONFIGURATOR.cliValid && CONFIGURATOR.cliActive)) {
538530
if (callback) {
539531
callback();

src/js/tabs/osd.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import debounce from "lodash.debounce";
1616
import $ from "jquery";
1717
import FileSystem from "../FileSystem";
1818
import { have_sensor } from "../sensor_helpers";
19+
import { initializeModalDialog } from "../utils/initializeModalDialog";
1920

2021
const FONT = {};
2122
const SYM = {};
@@ -3254,16 +3255,8 @@ osd.initialize = function (callback) {
32543255
$(".display-layout .preview").css("zoom", previewZoom);
32553256
}
32563257

3257-
// Open modal window
3258-
OSD.GUI.fontManager = new jBox("Modal", {
3259-
width: 750,
3260-
height: 455,
3261-
closeButton: "title",
3262-
animation: false,
3263-
attach: $("#fontmanager"),
3264-
title: "OSD Font Manager",
3265-
content: $("#fontmanagercontent"),
3266-
});
3258+
// Enable font manager dialog
3259+
OSD.GUI.fontManager = initializeModalDialog("#fontmanager", "#fontmanagerdialog", "osdSetupFontManagerTitle");
32673260

32683261
$(".elements-container div.cf_tip").attr("title", i18n.getMessage("osdSectionHelpElements"));
32693262
$(".videomode-container div.cf_tip").attr("title", i18n.getMessage("osdSectionHelpVideoMode"));
@@ -4093,10 +4086,6 @@ osd.initialize = function (callback) {
40934086
};
40944087

40954088
osd.cleanup = function (callback) {
4096-
if (OSD.GUI.fontManager) {
4097-
OSD.GUI.fontManager.destroy();
4098-
}
4099-
41004089
// unbind "global" events
41014090
$(document).unbind("keypress");
41024091
$(document).off("click", "span.progressLabel a");

src/js/tabs/power.js

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { mspHelper } from "../msp/MSPHelper";
55
import FC from "../fc";
66
import MSP from "../msp";
77
import MSPCodes from "../msp/MSPCodes";
8-
import jBox from "jbox";
98
import $ from "jquery";
9+
import { initializeModalDialog } from "../utils/initializeModalDialog";
1010

1111
const power = {
1212
supported: false,
@@ -20,13 +20,6 @@ power.initialize = function (callback) {
2020
GUI.active_tab = "power";
2121
}
2222

23-
if (GUI.calibrationManager) {
24-
GUI.calibrationManager.destroy();
25-
}
26-
if (GUI.calibrationManagerConfirmation) {
27-
GUI.calibrationManagerConfirmation.destroy();
28-
}
29-
3023
function load_status() {
3124
MSP.send_message(MSPCodes.MSP_STATUS, false, false, load_voltage_meters);
3225
}
@@ -223,9 +216,6 @@ power.initialize = function (callback) {
223216
}
224217
$(".tab-power").addClass("supported");
225218

226-
$("#calibrationmanagercontent").hide();
227-
$("#calibrationmanagerconfirmcontent").hide();
228-
229219
// battery
230220
const templateBatteryState = $("#tab-power-templates .battery-state .battery-state");
231221
const destinationBatteryState = $(".tab-power .battery-state");
@@ -347,33 +337,21 @@ power.initialize = function (callback) {
347337

348338
//calibration manager
349339
let calibrationconfirmed = false;
350-
GUI.calibrationManager = new jBox("Modal", {
351-
width: 400,
352-
height: 230,
353-
closeButton: "title",
354-
animation: false,
355-
attach: $("#calibrationmanager"),
356-
title: i18n.getMessage("powerCalibrationManagerTitle"),
357-
content: $("#calibrationmanagercontent"),
358-
onCloseComplete: function () {
359-
if (!calibrationconfirmed) {
360-
TABS.power.initialize();
361-
}
362-
},
363-
});
364-
365-
GUI.calibrationManagerConfirmation = new jBox("Modal", {
366-
width: 400,
367-
height: 230,
368-
closeButton: "title",
369-
animation: false,
370-
attach: $("#calibrate"),
371-
title: i18n.getMessage("powerCalibrationManagerConfirmationTitle"),
372-
content: $("#calibrationmanagerconfirmcontent"),
373-
onCloseComplete: function () {
374-
GUI.calibrationManager.close();
375-
},
376-
});
340+
GUI.calibrationManager = initializeModalDialog(
341+
"#calibrationmanager",
342+
"#calibrationmanagerdialog",
343+
"powerCalibrationManagerTitle",
344+
null,
345+
() => calibrationconfirmed || TABS.power.initialize(),
346+
);
347+
348+
GUI.calibrationManagerConfirmation = initializeModalDialog(
349+
"#calibrate",
350+
"#calibrationmanagerconfirmdialog",
351+
"powerCalibrationManagerConfirmationTitle",
352+
null,
353+
() => GUI.calibrationManager.close(),
354+
);
377355

378356
$("a.calibrationmanager").click(function () {
379357
if (FC.BATTERY_CONFIG.voltageMeterSource == 1 && FC.BATTERY_STATE.voltage > 0.1) {
@@ -564,13 +542,6 @@ power.initialize = function (callback) {
564542

565543
power.cleanup = function (callback) {
566544
if (callback) callback();
567-
568-
if (GUI.calibrationManager) {
569-
GUI.calibrationManager.destroy();
570-
}
571-
if (GUI.calibrationManagerConfirmation) {
572-
GUI.calibrationManagerConfirmation.destroy();
573-
}
574545
};
575546

576547
TABS.power = power;

src/js/utils/initializeModalDialog.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import $ from "jquery";
2+
import { i18n } from "../localization";
3+
4+
/**
5+
* Gets the title bar for a modal dialog.
6+
* @param {string} messageId Localized message identifier.
7+
* @param {object} [messageParameters] Localized message parameters
8+
* @param {() => void} onClose Function invoked by the close button.
9+
* @returns {JQuery<HTMLElement>} Dialog title bar.
10+
*/
11+
function getDialogTitleBar(messageId, messageParameters, onClose) {
12+
// HTML structure
13+
const dialogTitleBar = $(`
14+
<div style="display: flex; height: 47px; background: var(--surface-300); border-bottom: 1px solid var(--surface-950);">
15+
<div style="flex: 1; display: flex; align-items: center;">
16+
<div style="padding: 15px;">${i18n.getMessage(messageId, messageParameters || undefined)}</div>
17+
</div>
18+
<div id="dialogclose" style="flex: 0 0 47px; display: flex; align-items: center; justify-content: center; cursor: pointer;">
19+
<svg width="10" height="10" version="1.1" xmlns="http://www.w3.org/2000/svg">
20+
<line x1="0" y1="0" x2="10" y2="10" stroke="var(--surface-950)" stroke-width="2"/>
21+
<line x1="0" y1="10" x2="10" y2="0" stroke="var(--surface-950)" stroke-width="2"/>
22+
</svg>
23+
</div>
24+
</div>
25+
`);
26+
// Handle close button
27+
dialogTitleBar.find("#dialogclose").on("click", onClose);
28+
// Return title bar
29+
return dialogTitleBar;
30+
}
31+
32+
/**
33+
* Initializes a modal dialog from an HTML dialog element.
34+
* @param {JQuery.Selector|null} activationSelector JQuery selector for the activation element.
35+
* @param {JQuery.Selector} dialogSelector JQuery selector for the dialog element.
36+
* @param {string} messageId Localized message identifier.
37+
* @param {object} [messageParameters] Localized message parameters
38+
* @param {() => void} [onClose] Function invoked when the dialog is closed.
39+
* @returns {HTMLDialogElement} HTML dialog element.
40+
*/
41+
export function initializeModalDialog(activationSelector, dialogSelector, messageId, messageParameters, onClose) {
42+
// Get dialog references
43+
const dialog = $(dialogSelector);
44+
const dialogElement = dialog.get(0);
45+
const dialogContainerElement = dialog.children().first().get(0);
46+
// Add dialog title bar
47+
dialog.prepend(
48+
getDialogTitleBar(messageId, messageParameters, () => {
49+
dialogElement.close();
50+
}),
51+
);
52+
// Handle close event
53+
dialogElement.addEventListener("close", () => {
54+
onClose && onClose();
55+
});
56+
// Handle activation button click
57+
$(activationSelector).on("click", () => {
58+
dialogElement.showModal();
59+
// Reset any previous scrolling
60+
dialogContainerElement.scroll(0, 0);
61+
});
62+
// Return dialog element
63+
return dialogElement;
64+
}

0 commit comments

Comments
 (0)