Browse Source

Merge pull request 'Only add drag-drop handlers to dropzone, not the entire document' (#64) from file-drag-dropzone-only into config

Reviewed-on: #64
pull/67/head
discomrade 1 year ago
parent
commit
199f9f5fd0
  1. 66
      js/file-selector.js

66
js/file-selector.js

@ -86,43 +86,39 @@ $(document).on('ajax_after_post', function () {
});
var dragCounter = 0;
var dropHandlers = {
dragenter: function (e) {
e.stopPropagation();
e.preventDefault();
if (dragCounter === 0) $('.dropzone').addClass('dragover');
dragCounter++;
},
dragover: function (e) {
// needed for webkit to work
e.stopPropagation();
e.preventDefault();
},
dragleave: function (e) {
e.stopPropagation();
e.preventDefault();
dragCounter--;
if (dragCounter === 0) $('.dropzone').removeClass('dragover');
},
drop: function (e) {
e.stopPropagation();
e.preventDefault();
$('.dropzone').removeClass('dragover');
dragCounter = 0;
var fileList = e.originalEvent.dataTransfer.files;
for (var i=0; i<fileList.length; i++) {
addFile(fileList[i]);
}
}
};
// attach handlers
$(document).on(dropHandlers);
$(document).on('dragenter', '.dropzone', function (e) {
e.stopPropagation();
e.preventDefault();
if (dragCounter === 0) $('.dropzone').addClass('dragover');
dragCounter++;
});
$(document).on('dragover', '.dropzone', function (e) {
// needed for webkit to work
e.stopPropagation();
e.preventDefault();
});
$(document).on('dragleave', '.dropzone', function (e) {
e.stopPropagation();
e.preventDefault();
dragCounter--;
if (dragCounter === 0) $('.dropzone').removeClass('dragover');
});
$(document).on('drop', '.dropzone', function (e) {
e.stopPropagation();
e.preventDefault();
$('.dropzone').removeClass('dragover');
dragCounter = 0;
var fileList = e.originalEvent.dataTransfer.files;
for (var i=0; i<fileList.length; i++) {
addFile(fileList[i]);
}
});
$(document).on('click', '.dropzone .remove-btn', function (e) {
e.stopPropagation();

Loading…
Cancel
Save