ngx-upload-steroids
Version:
Angular 2+ File Uploader
97 lines (96 loc) • 3.93 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Directive, ElementRef, EventEmitter, Input, Output, HostListener } from '@angular/core';
import { NgUploaderService } from '../classes/ngx-uploader.class';
var NgFileDropDirective = (function () {
function NgFileDropDirective(elementRef) {
this.elementRef = elementRef;
this.stopEvent = function (e) {
e.stopPropagation();
e.preventDefault();
};
this.upload = new NgUploaderService();
this.uploadOutput = new EventEmitter();
}
NgFileDropDirective.prototype.ngOnInit = function () {
var _this = this;
this.el = this.elementRef.nativeElement;
this.upload.serviceEvents.subscribe(function (event) {
_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);
};
NgFileDropDirective.prototype.ngOnDestroy = function () {
if (this.uploadInput) {
this.uploadInput.unsubscribe();
}
};
NgFileDropDirective.prototype.onDrop = function (e) {
e.stopPropagation();
e.preventDefault();
var event = { type: 'drop' };
this.uploadOutput.emit(event);
this.upload.handleFiles(e.dataTransfer.files);
};
NgFileDropDirective.prototype.onDragOver = function (e) {
if (!e) {
return;
}
var event = { type: 'dragOver' };
this.uploadOutput.emit(event);
};
NgFileDropDirective.prototype.onDragLeave = function (e) {
if (!e) {
return;
}
var event = { type: 'dragOut' };
this.uploadOutput.emit(event);
};
return NgFileDropDirective;
}());
__decorate([
Input(),
__metadata("design:type", EventEmitter)
], NgFileDropDirective.prototype, "uploadInput", void 0);
__decorate([
Output(),
__metadata("design:type", EventEmitter)
], NgFileDropDirective.prototype, "uploadOutput", void 0);
__decorate([
HostListener('drop', ['$event']),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], NgFileDropDirective.prototype, "onDrop", null);
__decorate([
HostListener('dragover', ['$event']),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Event]),
__metadata("design:returntype", void 0)
], NgFileDropDirective.prototype, "onDragOver", null);
__decorate([
HostListener('dragleave', ['$event']),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Event]),
__metadata("design:returntype", void 0)
], NgFileDropDirective.prototype, "onDragLeave", null);
NgFileDropDirective = __decorate([
Directive({
selector: '[ngFileDrop]'
}),
__metadata("design:paramtypes", [ElementRef])
], NgFileDropDirective);
export { NgFileDropDirective };