-
Notifications
You must be signed in to change notification settings - Fork 267
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
Remove stopPropagation from drag&drop event handlers #144
base: master
Are you sure you want to change the base?
Conversation
Ok so the preventDefault actually needs to be called. I'm not sure why you added stopPropagation as well though - that's what causing my problems. When I remove the stopPropagation calles everything works fine. |
In my use case the stopPropagation needs to be removed only from dragover and drop. I removed it from dragenter just to be consistent. |
@enumag What browsers have you tested that in? https://msdn.microsoft.com/library/hh673539(v=vs.85).aspx From their example: function init()
{
// Set the drop-event handlers.
var dropArea = document.getElementById("dropspot");
dropArea.addEventListener("drop", dropHandler, false);
dropArea.addEventListener("dragover", doNothing, false);
}
// Prevents the event from continuing so our handlers can process the event.
function doNothing(event)
{
event.stopPropagation();
event.preventDefault();
} This example shows the same thing: https://msdn.microsoft.com/en-us/library/hh580307(v=vs.85).aspx |
I've tested in Firefox, Chrome and IE11. Oh so you just copied it without knowing why? Well preventDefault stops the browser from doing its default operation - in this case opening the dragged file in the current tab - we need to do that for sure. StopPropagation halts bubbling of the event to make sure no other scripts will interfere with your own handler - I believe we don't actually need that. |
First of all, the SO link you posted is a bad solution if you're trying to add a CSS class to a drop zone. That's because it uses What you want instead is an event that fires once at the moment the drag enters the target. That would be the Using So, to answer your question, no, I did not just copy that without knowing why. Btw, the plugin's |
I'm aware but dragenter doesn't really work in this case. Trust me, I've tried to get it working without dragover. It can't be done. The solution is bad but it's the only solution possible. Letting the dragover event bubble isn't really a problem. JS constantly bubbles a lot of mouse-related events. Stopping propagation of one doesn't really make any difference. It doesn't make your code worse. And no |
I misread your first comment. You're right, you can only use However, I disagree that letting I submit that removing On balance, the value of accommodating this specific use case doesn't justify losing that. For that reason, I am opposed to merging this change. I would be happy to consider any evidence that my opinion is wrong. |
I do agree with yout that with the For now I managed to fix it by hacking your library without actually changing it. I still would prefer if this was merged though. Here is my code for anyone who might need it: (function (ss) {
// Fixes issue with dropzone highlighting.
// @link https://github.com/LPology/Simple-Ajax-Uploader/pull/144
var original = ss.SimpleUpload.prototype.addDropZone;
ss.SimpleUpload.prototype.addDropZone = function (elem) {
var self = this;
original.call(self, elem);
elem.ondragover = function(e) {
e.preventDefault();
return false;
};
elem.ondrop = function(e) {
e.preventDefault();
ss.removeClass(this, self._opts.dragClass);
if (!self._dragFileCheck(e)) {
return;
}
if (false !== self._addFiles(e.dataTransfer.files)) {
self._cycleQueue();
}
};
};
})(ss); Thanks for your time. |
I was trying to highlight the dropzone when a file is dragged but before he hovers the dropzone itself. Basically to show him where he should drag the files to.
I tried to solve it using this aproach.
It didn't work correctly because simple-ajax-uploader stopped propagation of the dragover event. After I removed it everything works fine.
Why was this event handler added? I presume there was some reason behind it.