| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- "use strict";
- 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 common_1 = require("@angular/common");
- var domhandler_1 = require("../dom/domhandler");
- var Draggable = /** @class */ (function () {
- function Draggable(el, zone) {
- this.el = el;
- this.zone = zone;
- this.onDragStart = new core_1.EventEmitter();
- this.onDragEnd = new core_1.EventEmitter();
- this.onDrag = new core_1.EventEmitter();
- }
- Object.defineProperty(Draggable.prototype, "pDraggableDisabled", {
- get: function () {
- return this._pDraggableDisabled;
- },
- set: function (_pDraggableDisabled) {
- this._pDraggableDisabled = _pDraggableDisabled;
- if (this._pDraggableDisabled) {
- this.unbindMouseListeners();
- }
- else {
- this.el.nativeElement.draggable = true;
- this.bindMouseListeners();
- }
- },
- enumerable: true,
- configurable: true
- });
- Draggable.prototype.ngAfterViewInit = function () {
- if (!this.pDraggableDisabled) {
- this.el.nativeElement.draggable = true;
- this.bindMouseListeners();
- }
- };
- Draggable.prototype.bindDragListener = function () {
- var _this = this;
- if (!this.dragListener) {
- this.zone.runOutsideAngular(function () {
- _this.dragListener = _this.drag.bind(_this);
- _this.el.nativeElement.addEventListener('drag', _this.dragListener);
- });
- }
- };
- Draggable.prototype.unbindDragListener = function () {
- var _this = this;
- if (this.dragListener) {
- this.zone.runOutsideAngular(function () {
- _this.el.nativeElement.removeEventListener('drag', _this.dragListener);
- _this.dragListener = null;
- });
- }
- };
- Draggable.prototype.bindMouseListeners = function () {
- var _this = this;
- if (!this.mouseDownListener && !this.mouseUpListener) {
- this.zone.runOutsideAngular(function () {
- _this.mouseDownListener = _this.mousedown.bind(_this);
- _this.mouseUpListener = _this.mouseup.bind(_this);
- _this.el.nativeElement.addEventListener('mousedown', _this.mouseDownListener);
- _this.el.nativeElement.addEventListener('mouseup', _this.mouseUpListener);
- });
- }
- };
- Draggable.prototype.unbindMouseListeners = function () {
- var _this = this;
- if (this.mouseDownListener && this.mouseUpListener) {
- this.zone.runOutsideAngular(function () {
- _this.el.nativeElement.removeEventListener('mousedown', _this.mouseDownListener);
- _this.el.nativeElement.removeEventListener('mouseup', _this.mouseUpListener);
- _this.mouseDownListener = null;
- _this.mouseUpListener = null;
- });
- }
- };
- Draggable.prototype.drag = function (event) {
- this.onDrag.emit(event);
- };
- Draggable.prototype.dragStart = function (event) {
- if (this.allowDrag() && !this.pDraggableDisabled) {
- if (this.dragEffect) {
- event.dataTransfer.effectAllowed = this.dragEffect;
- }
- event.dataTransfer.setData('text', this.scope);
- this.onDragStart.emit(event);
- this.bindDragListener();
- }
- else {
- event.preventDefault();
- }
- };
- Draggable.prototype.dragEnd = function (event) {
- this.onDragEnd.emit(event);
- this.unbindDragListener();
- };
- Draggable.prototype.mousedown = function (event) {
- this.handle = event.target;
- };
- Draggable.prototype.mouseup = function (event) {
- this.handle = null;
- };
- Draggable.prototype.allowDrag = function () {
- if (this.dragHandle && this.handle)
- return domhandler_1.DomHandler.matches(this.handle, this.dragHandle);
- else
- return true;
- };
- Draggable.prototype.ngOnDestroy = function () {
- this.unbindDragListener();
- this.unbindMouseListeners();
- };
- __decorate([
- core_1.Input('pDraggable'),
- __metadata("design:type", String)
- ], Draggable.prototype, "scope", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Draggable.prototype, "dragEffect", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Draggable.prototype, "dragHandle", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Draggable.prototype, "onDragStart", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Draggable.prototype, "onDragEnd", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Draggable.prototype, "onDrag", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean),
- __metadata("design:paramtypes", [Boolean])
- ], Draggable.prototype, "pDraggableDisabled", null);
- __decorate([
- core_1.HostListener('dragstart', ['$event']),
- __metadata("design:type", Function),
- __metadata("design:paramtypes", [Object]),
- __metadata("design:returntype", void 0)
- ], Draggable.prototype, "dragStart", null);
- __decorate([
- core_1.HostListener('dragend', ['$event']),
- __metadata("design:type", Function),
- __metadata("design:paramtypes", [Object]),
- __metadata("design:returntype", void 0)
- ], Draggable.prototype, "dragEnd", null);
- Draggable = __decorate([
- core_1.Directive({
- selector: '[pDraggable]'
- }),
- __metadata("design:paramtypes", [core_1.ElementRef, core_1.NgZone])
- ], Draggable);
- return Draggable;
- }());
- exports.Draggable = Draggable;
- var Droppable = /** @class */ (function () {
- function Droppable(el, zone) {
- this.el = el;
- this.zone = zone;
- this.onDragEnter = new core_1.EventEmitter();
- this.onDragLeave = new core_1.EventEmitter();
- this.onDrop = new core_1.EventEmitter();
- }
- Droppable.prototype.ngAfterViewInit = function () {
- if (!this.pDroppableDisabled) {
- this.bindDragOverListener();
- }
- };
- Droppable.prototype.bindDragOverListener = function () {
- var _this = this;
- if (!this.dragOverListener) {
- this.zone.runOutsideAngular(function () {
- _this.dragOverListener = _this.dragOver.bind(_this);
- _this.el.nativeElement.addEventListener('dragover', _this.dragOverListener);
- });
- }
- };
- Droppable.prototype.unbindDragOverListener = function () {
- var _this = this;
- if (this.dragOverListener) {
- this.zone.runOutsideAngular(function () {
- _this.el.nativeElement.removeEventListener('dragover', _this.dragOverListener);
- _this.dragOverListener = null;
- });
- }
- };
- Droppable.prototype.dragOver = function (event) {
- event.preventDefault();
- };
- Droppable.prototype.drop = function (event) {
- if (this.allowDrop(event)) {
- event.preventDefault();
- this.onDrop.emit(event);
- }
- };
- Droppable.prototype.dragEnter = function (event) {
- event.preventDefault();
- if (this.dropEffect) {
- event.dataTransfer.dropEffect = this.dropEffect;
- }
- this.onDragEnter.emit(event);
- };
- Droppable.prototype.dragLeave = function (event) {
- event.preventDefault();
- this.onDragLeave.emit(event);
- };
- Droppable.prototype.allowDrop = function (event) {
- var dragScope = event.dataTransfer.getData('text');
- if (typeof (this.scope) == "string" && dragScope == this.scope) {
- return true;
- }
- else if (this.scope instanceof Array) {
- for (var j = 0; j < this.scope.length; j++) {
- if (dragScope == this.scope[j]) {
- return true;
- }
- }
- }
- return false;
- };
- Droppable.prototype.ngOnDestroy = function () {
- this.unbindDragOverListener();
- };
- __decorate([
- core_1.Input('pDroppable'),
- __metadata("design:type", Object)
- ], Droppable.prototype, "scope", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Droppable.prototype, "pDroppableDisabled", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Droppable.prototype, "dropEffect", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Droppable.prototype, "onDragEnter", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Droppable.prototype, "onDragLeave", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Droppable.prototype, "onDrop", void 0);
- __decorate([
- core_1.HostListener('drop', ['$event']),
- __metadata("design:type", Function),
- __metadata("design:paramtypes", [Object]),
- __metadata("design:returntype", void 0)
- ], Droppable.prototype, "drop", null);
- __decorate([
- core_1.HostListener('dragenter', ['$event']),
- __metadata("design:type", Function),
- __metadata("design:paramtypes", [Object]),
- __metadata("design:returntype", void 0)
- ], Droppable.prototype, "dragEnter", null);
- __decorate([
- core_1.HostListener('dragleave', ['$event']),
- __metadata("design:type", Function),
- __metadata("design:paramtypes", [Object]),
- __metadata("design:returntype", void 0)
- ], Droppable.prototype, "dragLeave", null);
- Droppable = __decorate([
- core_1.Directive({
- selector: '[pDroppable]'
- }),
- __metadata("design:paramtypes", [core_1.ElementRef, core_1.NgZone])
- ], Droppable);
- return Droppable;
- }());
- exports.Droppable = Droppable;
- var DragDropModule = /** @class */ (function () {
- function DragDropModule() {
- }
- DragDropModule = __decorate([
- core_1.NgModule({
- imports: [common_1.CommonModule],
- exports: [Draggable, Droppable],
- declarations: [Draggable, Droppable]
- })
- ], DragDropModule);
- return DragDropModule;
- }());
- exports.DragDropModule = DragDropModule;
- //# sourceMappingURL=dragdrop.js.map
|