refactoring

This commit is contained in:
Maxim Devaev 2025-06-02 23:08:42 +03:00
parent 86f73844dd
commit 517e79fd65

View File

@ -230,7 +230,6 @@ function __WindowManager() {
self.info = (html, ...args) => __modalCodeDialog("Info", html, args.join("\n"), true, false); self.info = (html, ...args) => __modalCodeDialog("Info", html, args.join("\n"), true, false);
self.error = (html, ...args) => __modalCodeDialog("Error", html, args.join("\n"), true, false); self.error = (html, ...args) => __modalCodeDialog("Error", html, args.join("\n"), true, false);
self.confirm = (html, ...args) => __modalCodeDialog("Question", html, args.join("\n"), true, true); self.confirm = (html, ...args) => __modalCodeDialog("Question", html, args.join("\n"), true, true);
self.modal = (header, html, ok, cancel) => __modalDialog(header, html, ok, cancel);
var __modalCodeDialog = function(header, html, code, ok, cancel) { var __modalCodeDialog = function(header, html, code, ok, cancel) {
let create_content = function(el_content) { let create_content = function(el_content) {
@ -244,10 +243,10 @@ function __WindowManager() {
} }
el_content.innerHTML = html; el_content.innerHTML = html;
}; };
return __modalDialog(header, create_content, ok, cancel); return self.modal(header, create_content, ok, cancel);
}; };
var __modalDialog = function(header, html, ok, cancel, el_parent=null) { self.modal = function(header, html, ok, cancel) {
let el_active_menu = (document.activeElement && document.activeElement.closest(".menu")); let el_active_menu = (document.activeElement && document.activeElement.closest(".menu"));
let el_modal = document.createElement("div"); let el_modal = document.createElement("div");
@ -329,7 +328,7 @@ function __WindowManager() {
} }
__windows.push(el_modal); __windows.push(el_modal);
(el_parent || document.fullscreenElement || document.body).appendChild(el_modal); (document.fullscreenElement || document.body).appendChild(el_modal);
if (typeof html === "function") { if (typeof html === "function") {
// Это должно быть здесь, потому что элемент должен иметь родителя чтобы существовать // Это должно быть здесь, потому что элемент должен иметь родителя чтобы существовать
html(el_content, el_ok_bt); html(el_content, el_ok_bt);
@ -752,21 +751,23 @@ function __WindowManager() {
var __setFullScreenWindow = function(el_win) { var __setFullScreenWindow = function(el_win) {
el_win.__before_full_screen_rect = el_win.getBoundingClientRect(); el_win.__before_full_screen_rect = el_win.getBoundingClientRect();
el_win.requestFullscreen(); el_win.requestFullscreen().then(function() {
if (navigator.keyboard && navigator.keyboard.lock) { el_win.focus(el_win); // Почему-то теряется фокус
navigator.keyboard.lock(); if (navigator.keyboard && navigator.keyboard.lock) {
} else { navigator.keyboard.lock();
let msg = ( } else {
"Shortcuts like Alt+Tab, Ctrl+W, Ctrl+N might not be captured.<br>" let msg = (
+ "For best keyboard handling use any browser with<br><a target=\"_blank\"" "The Keyboard Lock API is not supported by this browser.<br><br>"
+ " href=\"https://developer.mozilla.org/en-US/docs/Web" + "It means that shortcuts like Alt+Tab and Ctrl+W might not be captured.<br>"
+ "/API/Keyboard_API#Browser_compatibility\">keyboard lock support from this list</a>.<br><br>" + "For best keyboard handling use any browser with<br><a target=\"_blank\""
+ "In Chrome use HTTPS and enable <i>system-keyboard-lock</i><br>" + " href=\"https://developer.mozilla.org/en-US/docs/Web"
+ "by putting at URL <i>chrome://flags/#system-keyboard-lock</i>" + "/API/Keyboard_API#Browser_compatibility\">keyboard lock support from this list</a>.<br><br>"
); + "In Chrome use HTTPS and enable <i>system-keyboard-lock</i><br>"
__modalDialog("Keyboard lock is unsupported", msg, true, false, el_win); + "by putting at URL <i>chrome://flags/#system-keyboard-lock</i>"
} );
el_win.focus(el_win); // Почему-то теряется фокус self.info(msg);
}
});
}; };
__init__(); __init__();