Skip to content

Commit

Permalink
Fix code regression on mouse behavior (text selection) #229
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Lafarie committed Jan 29, 2020
1 parent 033952b commit a5b330f
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/ngx-smart-modal/src/components/ngx-smart-modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,25 @@ export class NgxSmartModalComponent implements OnInit, OnDestroy, AfterViewInit
* @param posX position X
* @param posY position Y
*/
public setPosition(posX: number, posY: number) {
public setPosition(posX: number, posY: number): NgxSmartModalComponent {
this.positionX = posX;
this.positionY = posY;

return this;
}

/**
* Moves dialog by changing top and left style of modal dialog by offset
* @param offsetX modal's left offset
* @param offsetY modal's top offset
*/
public moveDialog(offsetX: number, offsetY: number) {
if (!this.nsmDialog.length) {
return false;
public moveDialog(offsetX: number, offsetY: number): NgxSmartModalComponent {
if (this.nsmDialog.length) {
this.nsmDialog.last.nativeElement.style.top = (this.nsmDialog.last.nativeElement.offsetTop - offsetY) + 'px';
this.nsmDialog.last.nativeElement.style.left = (this.nsmDialog.last.nativeElement.offsetLeft - offsetX) + 'px';
}
this.nsmDialog.last.nativeElement.style.top = (this.nsmDialog.last.nativeElement.offsetTop - offsetY) + 'px';
this.nsmDialog.last.nativeElement.style.left = (this.nsmDialog.last.nativeElement.offsetLeft - offsetX) + 'px';
return true;

return this;
}

/**
Expand All @@ -171,7 +173,7 @@ export class NgxSmartModalComponent implements OnInit, OnDestroy, AfterViewInit
@HostListener('document:mousedown', ['$event'])
private startDrag(e: MouseEvent) {
if (!this.nsmContent.length || !this.draggable) {
return false;
return;
}

const src = e.srcElement as HTMLElement;
Expand All @@ -182,11 +184,9 @@ export class NgxSmartModalComponent implements OnInit, OnDestroy, AfterViewInit
this.dragging = true;
this.setPosition(e.clientX, e.clientY);

return true;
return;
}
}

return false;
}

/**
Expand All @@ -196,8 +196,9 @@ export class NgxSmartModalComponent implements OnInit, OnDestroy, AfterViewInit
@HostListener('document:mousemove', ['$event'])
private elementDrag(e: MouseEvent) {
if (!this.dragging || !this.nsmDialog.length) {
return false;
return;
}

e.preventDefault();

const offsetX = this.positionX - e.clientX;
Expand All @@ -206,8 +207,6 @@ export class NgxSmartModalComponent implements OnInit, OnDestroy, AfterViewInit
this.moveDialog(offsetX, offsetY);

this.setPosition(e.clientX, e.clientY);

return true;
}

/**
Expand Down

0 comments on commit a5b330f

Please sign in to comment.