From 0859a464cb1a64a745e1b8ec82aec01dbf3a2107 Mon Sep 17 00:00:00 2001 From: Jonathon Fowler Date: Tue, 15 Apr 2014 14:18:55 +1000 Subject: [PATCH] MDL-44270 files: handle drag-drop js error when event has null types This can happen when the 'dragover' event fires as has been observed in Safari. When the dataTransfer.types property of the event is null, accessing types.length throws a JavaScript error. --- lib/form/dndupload.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/form/dndupload.js b/lib/form/dndupload.js index 4be065040c7..f93f261c000 100644 --- a/lib/form/dndupload.js +++ b/lib/form/dndupload.js @@ -355,7 +355,10 @@ M.form_dndupload.init = function(Y, options) { * @return boolean true if event has files */ has_files: function(e) { - var types = e._event.dataTransfer.types; + // In some browsers, dataTransfer.types may be null for a + // 'dragover' event, so ensure a valid Array is always + // inspected. + var types = e._event.dataTransfer.types || []; for (var i=0; i