handle drops from browser

This commit is contained in:
Zuzanna Ludzik 2026-08-24 17:01:18 +02:00
parent 01f5da85a0
commit 36580c14e1
2 changed files with 37 additions and 0 deletions

View File

@ -157,6 +157,8 @@ define(req, function(AppConfig, Default, Language) {
}
};
Messages.oo_blockURLImageDrop = 'Dragging images from a browser is not supported.'; // XXX
return Messages;
});

View File

@ -2207,6 +2207,9 @@ define([
}];
common.checkTrimHistory(channels);
}
APP.handleImageDrop();
console.log("OO ready");
};
@ -2287,6 +2290,7 @@ define([
console.error('updated config', ooconfig);
return ooconfig;
};
var initializeImageUpload = function () {
var fmConfigImages = {
@ -2450,6 +2454,37 @@ define([
});
};
APP.handleImageDrop = function () {
var OOframe = APP.docEditor.getIframe().contentWindow;
OOframe.addEventListener('drop', function (e) {
var files = e.dataTransfer && e.dataTransfer.files;
if (files && files.length) {
return;
}
var url = e.dataTransfer.getData('text/uri-list') ||
e.dataTransfer.getData('URL');
if (!url) {
var html = e.dataTransfer.getData('text/html');
var match = html && html.match(/<img[^>]+src=["']([^"']+)["']/i);
url = match && match[1];
}
if (!url) {
return;
}
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
UI.alert(Messages.oo_blockURLImageDrop);
}, true);
};
APP.UploadImageFiles = function (files, type, id, jwt, cb) {
if (!files || !files.length) { return void cb([]); }