Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

upload: Prevent drag-and-drop of an image onto itself.

Sayam Samal8370268f89f2
diff --git a/web/src/upload.js b/web/src/upload.js
index b2e132c5a44..0701ab8a21a 100644
--- a/web/src/upload.js
+++ b/web/src/upload.js
@@ -16,6 +16,7 @@ import * as message_lists from "./message_lists";
import {page_params} from "./page_params";
import * as rows from "./rows";
+let drag_drop_img = null;
export let compose_upload_object;
export const upload_objects_by_message_edit_row = new Map();
@@ -437,6 +438,14 @@ export function initialize() {
mode: "compose",
});
+ $(".app, #navbar-fixed-container").on("dragstart", (event) => {
+ if (event.target.nodeName === "IMG") {
+ drag_drop_img = event.target;
+ } else {
+ drag_drop_img = null;
+ }
+ });
+
// Allow the app panel to receive drag/drop events.
$(".app, #navbar-fixed-container").on("dragover", (event) => event.preventDefault());
@@ -446,6 +455,11 @@ export function initialize() {
$(".app, #navbar-fixed-container").on("drop", (event) => {
event.preventDefault();
+ if (event.target.nodeName === "IMG" && event.target === drag_drop_img) {
+ drag_drop_img = null;
+ return;
+ }
+
const $drag_drop_edit_containers = $(".message_edit_form form");
const files = event.originalEvent.dataTransfer.files;
const $last_drag_drop_edit_container = $drag_drop_edit_containers.last();