innotec-materials
Version:
Innotec Materials is an UI framework who's desgined for all products of Innotec GmbH. Innotec Materials is based on Angular 2 an bootstrap.
112 lines • 4.57 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);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var file_uploader_class_1 = require("./file-uploader.class");
var FileDropDirective = (function () {
function FileDropDirective(element) {
this.fileOver = new core_1.EventEmitter();
this.onFileDrop = new core_1.EventEmitter();
this.element = element;
}
FileDropDirective.prototype.getOptions = function () {
return this.uploader.options;
};
FileDropDirective.prototype.getFilters = function () {
return {};
};
FileDropDirective.prototype.onDrop = function (event) {
var transfer = this._getTransfer(event);
if (!transfer) {
return;
}
var options = this.getOptions();
var filters = this.getFilters();
this._preventAndStop(event);
this.uploader.addToQueue(transfer.files, options, filters);
this.fileOver.emit(false);
this.onFileDrop.emit(transfer.files);
};
FileDropDirective.prototype.onDragOver = function (event) {
var transfer = this._getTransfer(event);
if (!this._haveFiles(transfer.types)) {
return;
}
transfer.dropEffect = 'copy';
this._preventAndStop(event);
this.fileOver.emit(true);
};
FileDropDirective.prototype.onDragLeave = function (event) {
if (event.currentTarget === this.element[0]) {
return;
}
this._preventAndStop(event);
this.fileOver.emit(false);
};
FileDropDirective.prototype._getTransfer = function (event) {
return event.dataTransfer ? event.dataTransfer : event.originalEvent.dataTransfer;
};
FileDropDirective.prototype._preventAndStop = function (event) {
event.preventDefault();
event.stopPropagation();
};
FileDropDirective.prototype._haveFiles = function (types) {
if (!types) {
return false;
}
if (types.indexOf) {
return types.indexOf('Files') !== -1;
}
else if (types.contains) {
return types.contains('Files');
}
else {
return false;
}
};
__decorate([
core_1.Input(),
__metadata("design:type", file_uploader_class_1.FileUploader)
], FileDropDirective.prototype, "uploader", void 0);
__decorate([
core_1.Output(),
__metadata("design:type", core_1.EventEmitter)
], FileDropDirective.prototype, "fileOver", void 0);
__decorate([
core_1.Output(),
__metadata("design:type", core_1.EventEmitter)
], FileDropDirective.prototype, "onFileDrop", void 0);
__decorate([
core_1.HostListener('drop', ['$event']),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], FileDropDirective.prototype, "onDrop", null);
__decorate([
core_1.HostListener('dragover', ['$event']),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], FileDropDirective.prototype, "onDragOver", null);
__decorate([
core_1.HostListener('dragleave', ['$event']),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Object)
], FileDropDirective.prototype, "onDragLeave", null);
FileDropDirective = __decorate([
core_1.Directive({ selector: '[ng2FileDrop]' }),
__metadata("design:paramtypes", [core_1.ElementRef])
], FileDropDirective);
return FileDropDirective;
}());
exports.FileDropDirective = FileDropDirective;
//# sourceMappingURL=file-drop.directive.js.map