mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-09 01:16:15 -08:00
refactor: add drag&drop directive
This commit is contained in:
1 parent
3e67c21d6d
commit
1716cd0d8b
2 files changed
+39
-1
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import {
|
||||
Directive,
|
||||
EventEmitter,
|
||||
HostBinding,
|
||||
HostListener,
|
||||
Output,
|
||||
} from '@angular/core';
|
||||
@Directive({
|
||||
selector: '[appDragDropFileUpload]',
|
||||
})
|
||||
export class DragDropFileUploadDirective {
|
||||
defaultColor = 'rgb(255 255 255 / 15%)';
|
||||
@Output() fileDropped = new EventEmitter<any>();
|
||||
@HostBinding('style.background-color') background = this.defaultColor;
|
||||
|
||||
@HostListener('dragover', ['$event']) dragOver(event: any) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
this.background = 'rgb(255 255 255 / 25%)';
|
||||
}
|
||||
|
||||
@HostListener('dragleave', ['$event']) public dragLeave(event: any) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
this.background = this.defaultColor;
|
||||
}
|
||||
|
||||
@HostListener('drop', ['$event']) public drop(event: any) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
this.background = this.defaultColor;
|
||||
const files = event.dataTransfer.files;
|
||||
if (files.length > 0) {
|
||||
this.fileDropped.emit(files);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,17 @@ import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { NgxUploaderModule } from 'ngx-uploader';
|
||||
import { SharedModule } from '../shared/shared.module';
|
||||
import { DragDropFileUploadDirective } from './file-upload/drag-drop-file-upload.directive';
|
||||
import { FileUploadComponent } from './file-upload/file-upload.component';
|
||||
import { HomeComponent } from './home.component';
|
||||
import { HomeRoutingModule } from './home.routing';
|
||||
import { PlaylistInfoComponent } from './recent-playlists/playlist-info/playlist-info.component';
|
||||
import { TextImportComponent } from './text-import/text-import.component';
|
||||
import { UrlUploadComponent } from './url-upload/url-upload.component';
|
||||
|
||||
@NgModule({
|
||||
imports: [CommonModule, HomeRoutingModule, NgxUploaderModule, SharedModule],
|
||||
declarations: [
|
||||
DragDropFileUploadDirective,
|
||||
HomeComponent,
|
||||
FileUploadComponent,
|
||||
PlaylistInfoComponent,
|
||||
|
||||
Reference in new issue
Block a user