Skip to content

Commit

Permalink
Add file drag over event emitter on enter and leave (bleenco#90)
Browse files Browse the repository at this point in the history
* Add file drag over event emitter on enter and leave

* Rename event onFileOver, add drag and drop example in readme file

* Fix example directive name
  • Loading branch information
AdrianPasalega authored and jkuri committed Sep 20, 2016
1 parent 8377b69 commit b021ff0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { Component } from '@angular/core';
})
export class DemoApp {
uploadFile: any;
hasBaseDropZoneOver: boolean = false;
options: Object = {
url: 'http://localhost:10050/upload'
};
Expand All @@ -69,6 +70,10 @@ export class DemoApp {
this.uploadFile = data;
}
}

fileOverBase(e:any):void {
this.hasBaseDropZoneOver = e;
}
}
````

Expand All @@ -79,6 +84,17 @@ export class DemoApp {
[options]="options"
(onUpload)="handleUpload($event)">

<!-- drag & drop file example-->
<style>
.file-over { border: dotted 3px red; } /* Default class applied to drop zones on over */
</style>
<div ngFileDrop
[options]="options"
(onUpload)="handleUpload($event)"
[ngClass]="{'file-over': hasBaseDropZoneOver}"
(onFileOver)="fileOverBase($event)">
</div>

<div>
Response: {{ uploadFile | json }}
</div>
Expand Down
14 changes: 13 additions & 1 deletion src/directives/ng-file-drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import {Ng2Uploader} from '../services/ng2-uploader';
selector: '[ngFileDrop]'
})
export class NgFileDropDirective {

@Input() events: EventEmitter<any>;
@Output() onUpload: EventEmitter<any> = new EventEmitter();
@Output() onPreviewData: EventEmitter<any> = new EventEmitter();
@Output() onFileOver:EventEmitter<any> = new EventEmitter();

_options:any;

Expand Down Expand Up @@ -110,4 +111,15 @@ export class NgFileDropDirective {
this.uploader.addFilesToQueue(this.files);
}
}

@HostListener('dragover', ['$event'])
public onDragOver():void {
this.onFileOver.emit(true);
}

@HostListener('dragleave', ['$event'])
public onDragLeave():any {
this.onFileOver.emit(false);
}

}

0 comments on commit b021ff0

Please sign in to comment.