Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine drag and drop events to prevent interference with other drag/drop-sensitive fields in downstream use cases #2

Merged
merged 2 commits into from
Jun 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,35 @@ var classes = require('./classes');
var dragClass = 'wk-dragging';
var dragClassSpecific = 'wk-container-dragging';
var root = document.documentElement;
var dragginCss = 0; // variable to count the enter and leaving numbers.

function uploads (container, droparea, editor, options, remove) {
var op = remove ? 'remove' : 'add';
crossvent[op](root, 'dragenter', dragging);
crossvent[op](root, 'dragend', dragstop);
crossvent[op](root, 'mouseout', dragstop);
crossvent[op](root, 'dragend', dragstopforce);
crossvent[op](root, 'mouseout', dragstopforce);
crossvent[op](container, 'dragover', handleDragOver, false);
crossvent[op](container, 'dragenter', dragging, false); // whenever the drag with components enter the container
crossvent[op](container, 'dragleave', dragstop, false); // whenever the drag with components moves out of container
crossvent[op](droparea, 'drop', handleFileSelect, false);

function dragging () {
dragginCss++;
classes.add(droparea, dragClass);
classes.add(droparea, dragClassSpecific);
}
function dragstop () {
dragginCss--;
if(dragginCss === 0){
dragstopper(droparea);
}
}
function dragstopforce () {
dragstopper(droparea);
}
function handleDragOver (e) {
stop(e);
dragging();
classes.add(droparea, dragClass);
classes.add(droparea, dragClassSpecific);
e.dataTransfer.dropEffect = 'copy';
}
function handleFileSelect (e) {
Expand Down