mirror of https://github.com/ghostfolio/ghostfolio
committed by
Thomas
5 changed files with 182 additions and 6 deletions
@ -0,0 +1,29 @@ |
|||||
|
import { Directive, HostListener, Output, EventEmitter } from '@angular/core'; |
||||
|
|
||||
|
@Directive({ |
||||
|
selector: '[appFileDrop]' |
||||
|
}) |
||||
|
export class FileDropDirective { |
||||
|
@Output() filesDropped = new EventEmitter<FileList>(); |
||||
|
|
||||
|
@HostListener('dragenter', ['$event']) onDragEnter(event: DragEvent) { |
||||
|
event.preventDefault(); |
||||
|
event.stopPropagation(); |
||||
|
} |
||||
|
|
||||
|
@HostListener('dragover', ['$event']) onDragOver(event: DragEvent) { |
||||
|
event.preventDefault(); |
||||
|
event.stopPropagation(); |
||||
|
} |
||||
|
|
||||
|
@HostListener('drop', ['$event']) onDrop(event: DragEvent) { |
||||
|
event.preventDefault(); |
||||
|
event.stopPropagation(); |
||||
|
|
||||
|
// Prevent the browser's default behavior for handling the file drop
|
||||
|
event.dataTransfer.dropEffect = 'copy'; |
||||
|
|
||||
|
const files = event.dataTransfer.files; |
||||
|
this.filesDropped.emit(files); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue