From cbbb8dfa24df2a6e8ff4406f49a8ef6f9c54e99e Mon Sep 17 00:00:00 2001 From: OdysseasKr Date: Fri, 4 Dec 2015 00:27:29 +0200 Subject: [PATCH] Add drag and drop for attachments Files can be dragged and dropped on the bottom in order to be added as attachments. Resolves: #260 --- js/views/file_input_view.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/js/views/file_input_view.js b/js/views/file_input_view.js index 817d40ed..38e01010 100644 --- a/js/views/file_input_view.js +++ b/js/views/file_input_view.js @@ -22,7 +22,10 @@ events: { 'change': 'previewImages', 'click .close': 'deleteFiles', - 'click .choose-file': 'open' + 'click .choose-file': 'open', + 'drop': 'openDropped', + 'dragover': 'showArea', + 'dragleave': 'hideArea' }, open: function() { @@ -228,6 +231,26 @@ this.$input.wrap('
').parent('form').trigger('reset'); this.$input.unwrap(); this.file = null; + }, + + openDropped: function(e) { + e.stopPropagation(); + e.preventDefault(); + this.file = e.originalEvent.dataTransfer.files[0]; + this.previewImages(); + this.$el.removeClass("dropoff"); + }, + + showArea: function(e) { + e.stopPropagation(); + e.preventDefault(); + this.$el.addClass("dropoff"); + }, + + hideArea: function(e) { + e.stopPropagation(); + e.preventDefault(); + this.$el.removeClass("dropoff"); } }); })();