@@ -35,19 +35,31 @@ export class HXDropZoneElement extends HXElement {
3535 return this . getAttribute ( 'drag' ) ;
3636 }
3737
38- /** @private */
38+ /**
39+ * @private
40+ * @see https://goo.gl/zaoexR
41+ */
3942 _isFileDrag ( evt ) {
40- return ( evt . dataTransfer . types . indexOf ( 'Files' ) !== - 1 ) ;
43+ if ( evt . dataTransfer . types ) {
44+ if ( evt . dataTransfer . types . indexOf ) {
45+ return ( evt . dataTransfer . types . indexOf ( 'Files' ) !== - 1 ) ;
46+ } else {
47+ return evt . dataTransfer . types . contains ( 'Files' ) ;
48+ }
49+ } else {
50+ return false ;
51+ }
4152 }
4253
4354 // #2 this gets called when the dragged item leaves the document (leaves to a child element or window altogether)
4455 /** @private */
4556 _onDocDragLeave ( ) {
57+ window . clearTimeout ( this . _docDragLeaveTimeout ) ;
4658 // callback must be an arrow function to preserve "this"
4759 this . _docDragLeaveTimeout = window . setTimeout ( ( ) => {
4860 this . _isDragging = false ;
4961 this . removeAttribute ( 'drag' ) ;
50- } , 0 ) ;
62+ } , 250 ) ;
5163 }
5264
5365 // #1 this handler fires continuously as long as the user is dragging on the page
@@ -65,7 +77,8 @@ export class HXDropZoneElement extends HXElement {
6577 // #4 this gets called when the dragged item leaves the zone (leaves to a child element or zone altogether)
6678 /** @private */
6779 _onDragLeave ( evt ) {
68- evt . preventDefault ( ) ;
80+ //evt.preventDefault();
81+ window . clearTimeout ( this . _zoneDragLeaveTimeout ) ;
6982 // callback must be an arrow function to preserve "this"
7083 this . _zoneDragLeaveTimeout = window . setTimeout ( ( ) => {
7184 this . _isZoneDragging = false ;
@@ -76,19 +89,20 @@ export class HXDropZoneElement extends HXElement {
7689 // #3 this handler fires continuously as long as the user is dragging on the zone
7790 /** @private */
7891 _onDragOver ( evt ) {
92+ // needed for onDrop to work
7993 evt . preventDefault ( ) ;
8094 if ( ! this . _isZoneDragging ) {
8195 this . _isZoneDragging = true ;
8296 if ( this . _isFileDrag ( evt ) ) {
8397 this . setAttribute ( 'drag' , 'over' ) ;
8498 }
8599 }
100+ window . clearTimeout ( this . _docDragLeaveTimeout ) ;
86101 window . clearTimeout ( this . _zoneDragLeaveTimeout ) ;
87102 }
88103
89104 /** @private */
90105 _onDrop ( evt ) {
91- //evt.preventDefault();
92106 this . removeAttribute ( 'drag' ) ;
93107 this . _isDragging = false ;
94108 this . _isZoneDragging = false ;
0 commit comments