@@ -200,15 +200,15 @@ export abstract class AbstractComponent {
200
200
//****** Droppable *******//
201
201
private _onDragEnter ( event : Event ) : void {
202
202
// console.log('ondragenter._isDropAllowed', this._isDropAllowed);
203
- if ( this . _isDropAllowed ) {
203
+ if ( this . _isDropAllowed ( event ) ) {
204
204
// event.preventDefault();
205
205
this . _onDragEnterCallback ( event ) ;
206
206
}
207
207
}
208
208
209
209
private _onDragOver ( event : Event ) {
210
210
// // console.log('ondragover._isDropAllowed', this._isDropAllowed);
211
- if ( this . _isDropAllowed ) {
211
+ if ( this . _isDropAllowed ( event ) ) {
212
212
// The element is over the same source element - do nothing
213
213
if ( event . preventDefault ) {
214
214
// Necessary. Allows us to drop.
@@ -218,36 +218,29 @@ export abstract class AbstractComponent {
218
218
this . _onDragOverCallback ( event ) ;
219
219
}
220
220
}
221
-
221
+
222
222
private _onDragLeave ( event : Event ) : void {
223
223
// console.log('ondragleave._isDropAllowed', this._isDropAllowed);
224
- if ( this . _isDropAllowed ) {
224
+ if ( this . _isDropAllowed ( event ) ) {
225
225
// event.preventDefault();
226
226
this . _onDragLeaveCallback ( event ) ;
227
227
}
228
228
}
229
229
230
230
private _onDrop ( event : Event ) : void {
231
+ // Necessary. Allows us to drop.
232
+ this . _preventAndStop ( event ) ;
231
233
// console.log('ondrop._isDropAllowed', this._isDropAllowed);
232
- if ( this . _isDropAllowed ) {
233
- if ( event . preventDefault ) {
234
- // Necessary. Allows us to drop.
235
- event . preventDefault ( ) ;
236
- }
237
-
238
- if ( event . stopPropagation ) {
239
- // Necessary. Allows us to drop.
240
- event . stopPropagation ( ) ;
241
- }
234
+ if ( this . _isDropAllowed ( event ) ) {
242
235
243
236
this . _onDropCallback ( event ) ;
244
237
245
238
this . detectChanges ( ) ;
246
239
}
247
240
}
248
241
249
- private get _isDropAllowed ( ) : boolean {
250
- if ( this . _dragDropService . isDragged && this . dropEnabled ) {
242
+ private _isDropAllowed ( event : any ) : boolean {
243
+ if ( ( this . _dragDropService . isDragged || ( event . dataTransfer && event . dataTransfer . files ) ) && this . dropEnabled ) {
251
244
// First, if `allowDrop` is set, call it to determine whether the
252
245
// dragged element can be dropped here.
253
246
if ( this . allowDrop ) {
@@ -268,6 +261,15 @@ export abstract class AbstractComponent {
268
261
return false ;
269
262
}
270
263
264
+ private _preventAndStop ( event : Event ) : any {
265
+ if ( event . preventDefault ) {
266
+ event . preventDefault ( ) ;
267
+ }
268
+ if ( event . stopPropagation ) {
269
+ event . stopPropagation ( ) ;
270
+ }
271
+ }
272
+
271
273
//*********** Draggable **********//
272
274
273
275
private _onDragStart ( event : Event ) : void {
0 commit comments