Skip to content

Commit

Permalink
Fixed #632
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici committed Nov 24, 2016
1 parent b3210b6 commit b2810a2
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions components/dragdrop/dragdrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class Draggable {
if(this.dragEffect) {
event.dataTransfer.effectAllowed = this.dragEffect;
}
event.dataTransfer.setData(this.scope, this.scope);
event.dataTransfer.setData('text', this.scope);

this.onDragStart.emit(event);
}
else {
Expand Down Expand Up @@ -93,8 +93,10 @@ export class Droppable {

@HostListener('drop', ['$event'])
drop(event) {
event.preventDefault();
this.onDrop.emit(event);
if(this.allowDrop(event)) {
event.preventDefault();
this.onDrop.emit(event);
}
}

@HostListener('dragenter', ['$event'])
Expand All @@ -117,26 +119,20 @@ export class Droppable {

@HostListener('dragover', ['$event'])
dragOver(event) {
if(this.allowDrop(event)) {
event.preventDefault();
this.onDragOver.emit(event);
}
event.preventDefault();
this.onDragOver.emit(event);
}

allowDrop(event): boolean {
let types = event.dataTransfer.types;
if(types && types.length) {
for(let i = 0; i < types.length; i++) {
if(typeof (this.scope) == "string" && types[i] == this.scope) {
let dragScope = event.dataTransfer.getData('text');
if(typeof (this.scope) == "string" && dragScope == this.scope) {
return true;
}
else if(this.scope instanceof Array) {
for(let j = 0; j < this.scope.length; j++) {
if(dragScope == this.scope[j]) {
return true;
}
else if(this.scope instanceof Array) {
for(let j = 0; j < this.scope.length; j++) {
if(types[i] == this.scope[j]) {
return true;
}
}
}
}
}
return false;
Expand Down

0 comments on commit b2810a2

Please sign in to comment.