Skip to content

Commit

Permalink
fix: resolves #43
Browse files Browse the repository at this point in the history
  • Loading branch information
ObaidUrRehman committed Apr 19, 2017
1 parent 8d96b08 commit 7864d6f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/directives/draggable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export declare class Draggable {
* Event fired when drag ends
*/
onDragEnd: EventEmitter<any>;
/**
* @private
* Keeps track of mouse over element that is used to determine drag handles
*/
mouseOverElement: any;
constructor(el: ElementRef, ng2DragDropService: Ng2DragDropService);
dragStart(e: any): void;
drag(e: any): void;
Expand Down
2 changes: 1 addition & 1 deletion src/directives/draggable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export class Draggable {
@Output() onDragEnd: EventEmitter<any> = new EventEmitter();

/**
* @private
* Keeps track of mouse over element that is used to determine drag handles
* @internal
*/
mouseOverElement: any;

Expand Down
13 changes: 11 additions & 2 deletions src/directives/droppable.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ElementRef, EventEmitter, OnInit } from '@angular/core';
import { ElementRef, EventEmitter, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { DropEvent } from "../shared/drop-event.model";
import { Ng2DragDropService } from "../services/ng2-drag-drop.service";
export declare class Droppable implements OnInit {
export declare class Droppable implements OnInit, OnDestroy {
protected el: ElementRef;
private ng2DragDropService;
/**
Expand Down Expand Up @@ -37,6 +38,14 @@ export declare class Droppable implements OnInit {
* Defines if drop is enabled. `true` by default.
*/
dropEnabled: boolean;
/**
* @private
*/
dragStartSubscription: Subscription;
/**
* @private
*/
dragEndSubscription: Subscription;
constructor(el: ElementRef, ng2DragDropService: Ng2DragDropService);
ngOnInit(): void;
ngOnDestroy(): void;
Expand Down
23 changes: 17 additions & 6 deletions src/directives/droppable.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {Directive, ElementRef, HostListener, Input, Output, EventEmitter, OnInit} from '@angular/core';
import {Directive, ElementRef, HostListener, Input, Output, EventEmitter, OnInit, OnDestroy} from '@angular/core';
import {Subscription} from 'rxjs/Subscription';
import {DropEvent} from "../shared/drop-event.model";
import {Ng2DragDropService} from "../services/ng2-drag-drop.service";
import {Utils} from "../shared/utils";

@Directive({
selector: '[droppable]'
})
export class Droppable implements OnInit {
export class Droppable implements OnInit, OnDestroy {

/**
* Event fired when Drag dragged element enters a valid drop target.
Expand Down Expand Up @@ -49,24 +50,34 @@ export class Droppable implements OnInit {
*/
@Input() dropEnabled: boolean = true;

/**
* @private
*/
dragStartSubscription: Subscription;

/**
* @private
*/
dragEndSubscription: Subscription;

constructor(protected el: ElementRef, private ng2DragDropService: Ng2DragDropService) {
}

ngOnInit() {
this.ng2DragDropService.onDragStart.subscribe(() => {
this.dragStartSubscription = this.ng2DragDropService.onDragStart.subscribe(() => {
if (this.allowDrop()) {
Utils.addClass(this.el, this.dragHintClass);
}
});

this.ng2DragDropService.onDragEnd.subscribe(() => {
this.dragEndSubscription = this.ng2DragDropService.onDragEnd.subscribe(() => {
Utils.removeClass(this.el, this.dragHintClass);
});
}

ngOnDestroy() {
this.ng2DragDropService.onDragStart.unsubscribe();
this.ng2DragDropService.onDragEnd.unsubscribe();
this.dragStartSubscription.unsubscribe();
this.dragEndSubscription.unsubscribe();
}

@HostListener('dragenter', ['$event'])
Expand Down

0 comments on commit 7864d6f

Please sign in to comment.