refactor(code): Cleaned-up the code base
This commit is contained in:
@@ -15,14 +15,7 @@ const zipOnly = boxPanel && boxPanel.dataset.zipOnly === "true";
|
||||
let contextFile = null;
|
||||
let lastStatusSignature = "";
|
||||
|
||||
function htmlEscape(value) {
|
||||
return String(value || "")
|
||||
.replaceAll("&", "&")
|
||||
.replaceAll("<", "<")
|
||||
.replaceAll(">", ">")
|
||||
.replaceAll('"', """)
|
||||
.replaceAll("'", "'");
|
||||
}
|
||||
const htmlEscape = window.WarpBoxUI.htmlEscape;
|
||||
|
||||
function showToast(message, type = "info") {
|
||||
window.WarpBoxUI.toast(message, type, { target: toast });
|
||||
@@ -302,23 +295,39 @@ function startStagedPolling(baseMS) {
|
||||
window.setTimeout(tick, stages[0].interval);
|
||||
}
|
||||
|
||||
function runBoxAction(action) {
|
||||
const actions = {
|
||||
"fake-close": () => showToast("Close clicked. The download window is emotionally attached.", "warning"),
|
||||
minimize: () => showToast("Minimize clicked. WarpBox refuses to disappear quietly."),
|
||||
"toggle-fit": () => {
|
||||
document.body.classList.toggle("fit-window");
|
||||
showToast("Maximize clicked. The window is doing its best.");
|
||||
},
|
||||
};
|
||||
|
||||
actions[action]?.();
|
||||
}
|
||||
|
||||
function runContextAction(action, item) {
|
||||
const actions = {
|
||||
preview: () => previewFile(item),
|
||||
download: () => downloadFile(item),
|
||||
properties: () => showProperties(item),
|
||||
};
|
||||
|
||||
actions[action]?.();
|
||||
}
|
||||
|
||||
document.addEventListener("click", (event) => {
|
||||
const action = event.target.closest("[data-action]")?.dataset.action;
|
||||
if (action === "fake-close") showToast("Close clicked. The download window is emotionally attached.", "warning");
|
||||
if (action === "minimize") showToast("Minimize clicked. WarpBox refuses to disappear quietly.");
|
||||
if (action === "toggle-fit") {
|
||||
document.body.classList.toggle("fit-window");
|
||||
showToast("Maximize clicked. The window is doing its best.");
|
||||
}
|
||||
if (action) runBoxAction(action);
|
||||
|
||||
const contextAction = event.target.closest("[data-context-action]")?.dataset.contextAction;
|
||||
if (contextAction && contextFile) {
|
||||
event.preventDefault();
|
||||
const item = contextFile;
|
||||
closeContextMenu();
|
||||
if (contextAction === "preview") previewFile(item);
|
||||
if (contextAction === "download") downloadFile(item);
|
||||
if (contextAction === "properties") showProperties(item);
|
||||
runContextAction(contextAction, item);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user