-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(readme): documentation for version 3.0.0
- Loading branch information
Showing
11 changed files
with
276 additions
and
495 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './src/ngx-uploader/module/ngx-uploader.module'; | ||
export * from './src/ngx-uploader/services/ngx-uploader'; | ||
export * from './src/ngx-uploader/directives/ng-file-select'; | ||
export * from './src/ngx-uploader/classes/ngx-uploader.class'; | ||
export * from './src/ngx-uploader/directives/ng-file-select.directive'; | ||
export * from './src/ngx-uploader/directives/ng-file-drop.directive'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { Directive, ElementRef, EventEmitter, Input, Output, OnInit, OnDestroy, PLATFORM_ID, Inject, HostListener } from '@angular/core'; | ||
import { isPlatformServer } from '@angular/common'; | ||
import { NgUploaderService, UploadOutput, UploadInput, UploadFile } from '../classes/ngx-uploader.class'; | ||
|
||
@Directive({ | ||
selector: '[ngFileDrop]' | ||
}) | ||
export class NgFileDropDirective implements OnInit, OnDestroy { | ||
@Input() uploadInput: EventEmitter<UploadInput>; | ||
@Output() uploadOutput: EventEmitter<UploadOutput>; | ||
|
||
upload: NgUploaderService; | ||
isServer: boolean = isPlatformServer(this.platform_id); | ||
el: HTMLInputElement; | ||
|
||
constructor(@Inject(PLATFORM_ID) private platform_id, private elementRef: ElementRef) { | ||
this.upload = new NgUploaderService(); | ||
this.uploadOutput = new EventEmitter<UploadOutput>(); | ||
} | ||
|
||
ngOnInit() { | ||
if (this.isServer) { | ||
return; | ||
} | ||
|
||
this.el = this.elementRef.nativeElement; | ||
|
||
this.upload.serviceEvents.subscribe((event: UploadOutput) => { | ||
this.uploadOutput.emit(event); | ||
}); | ||
|
||
if (this.uploadInput instanceof EventEmitter) { | ||
this.upload.initInputEvents(this.uploadInput); | ||
} | ||
|
||
this.el.addEventListener('drop', this.stopEvent, false); | ||
this.el.addEventListener('dragenter', this.stopEvent, false); | ||
this.el.addEventListener('dragover', this.stopEvent, false); | ||
this.el.addEventListener('dragover', this.stopEvent, false); | ||
} | ||
|
||
ngOnDestroy() { | ||
if (this.isServer) { | ||
return; | ||
} | ||
|
||
this.uploadInput.unsubscribe(); | ||
} | ||
|
||
stopEvent = (e: Event) => { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
} | ||
|
||
@HostListener('drop', ['$event']) | ||
public onDrop(e: any) { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
|
||
const event: UploadOutput = { type: 'drop' }; | ||
this.uploadOutput.emit(event); | ||
this.upload.handleFiles(e.dataTransfer.files); | ||
} | ||
|
||
@HostListener('dragover', ['$event']) | ||
public onDragOver(e: Event) { | ||
if (!e) { | ||
return; | ||
} | ||
|
||
const event: UploadOutput = { type: 'dragOver' }; | ||
this.uploadOutput.emit(event); | ||
} | ||
|
||
@HostListener('dragleave', ['$event']) | ||
public onDragLeave(e: Event) { | ||
if (!e) { | ||
return; | ||
} | ||
|
||
const event: UploadOutput = { type: 'dragOut' }; | ||
this.uploadOutput.emit(event); | ||
} | ||
} |
Oops, something went wrong.