Skip to content

Commit

Permalink
Fix dataTransfer.types being null crash in Safari
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed May 27, 2015
1 parent 91f4743 commit 050193d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/backends/HTML5.js
Expand Up @@ -84,7 +84,7 @@ function createNativeDragSource(type) {
}

function matchNativeItemType(dataTransfer) {
const dataTransferTypes = Array.prototype.slice.call(dataTransfer.types);
const dataTransferTypes = Array.prototype.slice.call(dataTransfer.types || []);

return Object.keys(nativeTypesConfig).filter(nativeItemType => {
const { matchesTypes } = nativeTypesConfig[nativeItemType];
Expand Down Expand Up @@ -395,6 +395,15 @@ class HTML5Backend {
} else if (nativeType) {
// A native item (such as URL) dragged from inside the document
this.beginDragNativeItem(nativeType);
} else if (
!dataTransfer.types && (
!e.target.hasAttribute ||
!e.target.hasAttribute('draggable')
)
) {
// Looks like a Safari bug: dataTransfer.types is null, but there was no draggable.
// Just let it drag. It's a native type (URL or text) and will be picked up in dragenter handler.
return;
} else {
// If by this time no drag source reacted, tell browser not to drag.
e.preventDefault();
Expand Down

0 comments on commit 050193d

Please sign in to comment.