Skip to content

Commit daa7c2a

Browse files
Better logic for IDE
1 parent c2cde85 commit daa7c2a

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/js/drop_studio_file.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const target = arguments[0];
2+
const offsetX = arguments[1];
3+
const offsetY = arguments[2];
4+
5+
const document = target.ownerDocument || document;
6+
const window = document.defaultView || window;
7+
8+
const input = document.createElement('INPUT');
9+
input.type = 'file';
10+
input.onchange = function () {
11+
const rect = target.getBoundingClientRect();
12+
const x = rect.left + (offsetX || (rect.width >> 1));
13+
const y = rect.top + (offsetY || (rect.height >> 1));
14+
15+
const dataTransfer = new DataTransfer();
16+
dataTransfer.items.add(input.files[0]);
17+
18+
console.log('Got uploads: ' + dataTransfer.items);
19+
20+
for (let t = 0; t < dataTransfer.items.length; t++) {
21+
const n = dataTransfer.items[t];
22+
console.log("Upload " + t + ": " + n.kind);
23+
if (n.kind === "file") {
24+
const e = n.getAsFile();
25+
if (e) {
26+
console.log("File upload " + t + ": " + e.name);
27+
} else {
28+
console.warn("Cannot get file");
29+
}
30+
} else {
31+
console.warn("Not a file upload");
32+
}
33+
}
34+
35+
['dragenter', 'drop'].forEach(function (name) {
36+
console.log('Dispatching mouse event with file transfer')
37+
const evt = document.createEvent('MouseEvent');
38+
evt.initMouseEvent(name, !0, !0, window, 0, 0, 0, x, y, !1, !1, !1, !1, 0, null);
39+
evt.dataTransfer = dataTransfer;
40+
target.dispatchEvent(evt);
41+
});
42+
43+
// setTimeout(function () {
44+
// document.body.removeChild(input);
45+
// }, 25);
46+
};
47+
target.appendChild(input);
48+
49+
console.log('Created file upload input')
50+
51+
// noinspection JSAnnotator
52+
return input;

0 commit comments

Comments
 (0)