From 415253dc1e96ef058db69c7386dc38243d406a31 Mon Sep 17 00:00:00 2001 From: Gabriel Del Nero <43073074+Gabixel@users.noreply.github.com> Date: Mon, 8 Jan 2024 15:27:23 +0100 Subject: [PATCH 1/3] Re-arrange event propagation stop logic on grid file drop --- src/ts/grid/events/GridEvents.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ts/grid/events/GridEvents.ts b/src/ts/grid/events/GridEvents.ts index 8f9482b4..46a6cafb 100644 --- a/src/ts/grid/events/GridEvents.ts +++ b/src/ts/grid/events/GridEvents.ts @@ -196,13 +196,13 @@ class GridEvents extends EventTarget { if (notSuccesful) return; + e.preventDefault(); + e.stopPropagation(); + let $button = getTarget(e); $button.trigger("dragleave"); - e.preventDefault(); - e.stopPropagation(); - $button.removeClass("file-dragover"); const file = e.originalEvent.dataTransfer.files[0]; From 83e0cb29f636b7aade17847d41d007c3a7dc6943 Mon Sep 17 00:00:00 2001 From: Gabriel Del Nero <43073074+Gabixel@users.noreply.github.com> Date: Mon, 8 Jan 2024 15:28:43 +0100 Subject: [PATCH 2/3] Prevent default behavior when dropping a file on the page I also added a `preventDefault()` on the context menu event while I'm here, just in case --- src/ts/start/MainWindow.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ts/start/MainWindow.ts b/src/ts/start/MainWindow.ts index f8a62eb3..c245ca66 100644 --- a/src/ts/start/MainWindow.ts +++ b/src/ts/start/MainWindow.ts @@ -116,10 +116,11 @@ abstract class MainWindow extends Main { // Setup context menu // TODO: class? - $(document).on("contextmenu", () => { + $(document).on("contextmenu", (e) => { + e.preventDefault(); SoundboardApi.mainWindow.openContextMenu(); }); - + $(document).on("keydown", (e) => { if (e.ctrlKey && e.key == "Tab") { let ev = "tabchange" + (e.shiftKey ? "prev" : "next"); @@ -137,6 +138,11 @@ abstract class MainWindow extends Main { return false; } }); + + // This prevents a new window from opening when a file is randomly dropped on the page + $(document).on("drop", (e) => { + e.preventDefault(); + }); } // TODO: include with future loader event From 726d114d0fef2ca77b0eeeae4d03bfd924880a11 Mon Sep 17 00:00:00 2001 From: Gabriel Del Nero <43073074+Gabixel@users.noreply.github.com> Date: Mon, 8 Jan 2024 15:33:32 +0100 Subject: [PATCH 3/3] Move `preventDefault()` in Main --- src/ts/start/Main.ts | 5 +++++ src/ts/start/MainWindow.ts | 7 +------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ts/start/Main.ts b/src/ts/start/Main.ts index 92cdaa5d..7b0de6e9 100644 --- a/src/ts/start/Main.ts +++ b/src/ts/start/Main.ts @@ -48,6 +48,11 @@ abstract class Main { } else { throw new TypeError("JQueryFixes is not available"); } + + // This prevents a new window from opening when a file is randomly dropped on the page + $(document).on("drop", (e) => { + e.preventDefault(); + }); if (appPathRequest) { await appPathRequest; diff --git a/src/ts/start/MainWindow.ts b/src/ts/start/MainWindow.ts index c245ca66..f3986d7d 100644 --- a/src/ts/start/MainWindow.ts +++ b/src/ts/start/MainWindow.ts @@ -120,7 +120,7 @@ abstract class MainWindow extends Main { e.preventDefault(); SoundboardApi.mainWindow.openContextMenu(); }); - + $(document).on("keydown", (e) => { if (e.ctrlKey && e.key == "Tab") { let ev = "tabchange" + (e.shiftKey ? "prev" : "next"); @@ -138,11 +138,6 @@ abstract class MainWindow extends Main { return false; } }); - - // This prevents a new window from opening when a file is randomly dropped on the page - $(document).on("drop", (e) => { - e.preventDefault(); - }); } // TODO: include with future loader event