Commit cbc02bb2 authored by git's avatar git Committed by Primsi
Browse files

Issue #2827120 by chr.fritsch, mtodor, Primsi: DropzneJS is cleared on every Ajax response

parent c68ff60c
......@@ -14,6 +14,8 @@
Drupal.behaviors.dropzonejsIntegraion = {
attach: function (context) {
Dropzone.autoDiscover = false;
// @todo Init functionality should support multiple drop zones on page.
var selector = $(".dropzone-enable");
selector.addClass("dropzone");
var input = selector.siblings('input');
......@@ -24,9 +26,20 @@
addRemoveLinks: false
};
var instanceConfig = drupalSettings.dropzonejs.instances[selector.attr('id')];
// If DropzoneJS instance is already registered on Element. There is no
// need to register it again.
if (selector.once('register-dropzonejs').length !== selector.length) {
return;
}
// If instance exists for configuration, but it's detached from element
// then destroy detached instance and create new instance.
if (instanceConfig.instance !== undefined) {
instanceConfig.instance.destroy();
}
// Initialize DropzoneJS instance for element.
var dropzoneInstance = new Dropzone("#" + selector.attr("id"), $.extend({}, instanceConfig, config));
// Other modules might need instances.
......
......@@ -16,10 +16,25 @@
var $submit = $form.find('.is-entity-browser-submit');
$submit.prop("disabled", false);
item.instance.on("queuecomplete", function () {
var autoSubmitDropzone = function() {
var $form = this;
$('#edit-edit', $form).trigger('mousedown');
}.bind($form));
// Trigger generation of IEF form only, when there are new
// accepted files and there are no rejected files.
if (item.instance.getAcceptedFiles().length > 0 && item.instance.getRejectedFiles().length === 0) {
$('#edit-edit', $form).trigger('mousedown');
item.instance.removeAllFiles();
}
}.bind($form);
item.instance.on("queuecomplete", function() {
autoSubmitDropzone();
});
item.instance.on("removedfile", function() {
autoSubmitDropzone();
});
}
});
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment