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.
This commit is contained in:
Jonathon Fowler 2014-04-15 14:18:55 +10:00
parent 069fe267b6
commit 6b2b72d6f9

View File

@ -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<types.length; i++) {
if (types[i] == 'Files') {
return true;