From ca33fef877e0fca6ee87d4b74116bcefa1a20544 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Thu, 19 Jul 2018 14:52:15 +0200 Subject: [PATCH] [IMP] Make web_drop_target IE11 compliant --- .../static/src/js/web_drop_target.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/web_drop_target/static/src/js/web_drop_target.js b/web_drop_target/static/src/js/web_drop_target.js index c343ef1b..1a624580 100644 --- a/web_drop_target/static/src/js/web_drop_target.js +++ b/web_drop_target/static/src/js/web_drop_target.js @@ -29,20 +29,18 @@ odoo.define('web_drop_target', function(require) { _on_drop: function(e) { var drop_items = this._get_drop_items(e); + e.preventDefault(); + this._remove_overlay(); if(!drop_items) { return; } - this._remove_overlay(); - e.preventDefault(); this._handle_drop_items(drop_items, e) }, _on_dragenter: function(e) { - if(this._get_drop_items(e)) { - e.preventDefault(); - this._add_overlay(); - return false; - } + e.preventDefault(); + this._add_overlay(); + return false; }, _on_dragleave: function(e) { @@ -54,7 +52,7 @@ odoo.define('web_drop_target', function(require) { var self = this, dataTransfer = e.originalEvent.dataTransfer, drop_items = []; - _.each(dataTransfer.items, function(item) { + _.each(dataTransfer.files, function(item) { if( _.contains(self._drop_allowed_types, item.type) || _.isEmpty(self._drop_allowed_types) @@ -108,7 +106,7 @@ odoo.define('web_drop_target', function(require) { item, e, res_model, res_id, extra_data ) { var self = this; - var file = item.getAsFile(); + var file = item; var reader = new FileReader(); reader.onloadend = self.proxy( _.partial(self._create_attachment, file, reader, e, res_model, res_id, extra_data) @@ -135,9 +133,11 @@ odoo.define('web_drop_target', function(require) { }, _remove_overlay: function() { - this._drop_overlay.remove(); - this._drop_overlay = null; - }, + if (this._drop_overlay) { + this._drop_overlay.remove(); + this._drop_overlay = null; + } + } }; // and here we apply the mixin to form views, allowing any files and