@@ -55,6 +55,7 @@ import { SplitAreaDirective } from '../directive/splitArea.directive'; |
55 | 55 | [imageH]="gutterImageH" |
56 | 56 | [imageV]="gutterImageV" |
57 | 57 | [disabled]="disabled" |
| 58 | + (click)="clickGutter($event, index*2+1, index+1)" |
58 | 59 | (mousedown)="startDragging($event, index*2+1, index+1)" |
59 | 60 | (touchstart)="startDragging($event, index*2+1, index+1)"></as-split-gutter> |
60 | 61 | </ng-template>`, |
@@ -244,8 +245,9 @@ export class SplitComponent implements AfterViewInit, OnDestroy { |
244 | 245 |
|
245 | 246 | public isViewInitialized: boolean = false; |
246 | 247 | private isDragging: boolean = false; |
247 | | - private draggingWithoutMove: boolean = false; |
248 | 248 | private currentGutterNum: number = 0; |
| 249 | + private startPoint: IPoint | null = null; |
| 250 | + private endPoint: IPoint | null = null; |
249 | 251 |
|
250 | 252 | public readonly displayedAreas: Array<IArea> = []; |
251 | 253 | private readonly hidedAreas: Array<IArea> = []; |
@@ -348,7 +350,7 @@ export class SplitComponent implements AfterViewInit, OnDestroy { |
348 | 350 |
|
349 | 351 | // ¤ AREAS ORDER |
350 | 352 |
|
351 | | - if(resetOrders === true) { |
| 353 | + if(resetOrders === true) { |
352 | 354 |
|
353 | 355 | // If user provided 'order' for each area, use it to sort them. |
354 | 356 | if(this.displayedAreas.every(a => a.comp.order !== null)) { |
@@ -438,17 +440,21 @@ export class SplitComponent implements AfterViewInit, OnDestroy { |
438 | 440 | }); |
439 | 441 | } |
440 | 442 |
|
| 443 | + public clickGutter(event: MouseEvent, gutterOrder: number, gutterNum: number): void { |
| 444 | + if(this.startPoint && this.startPoint.x === event.pageX && this.startPoint.y === event.pageY) { |
| 445 | + this.currentGutterNum = gutterNum; |
| 446 | + |
| 447 | + this.notify('click'); |
| 448 | + } |
| 449 | + } |
| 450 | + |
441 | 451 | public startDragging(startEvent: MouseEvent | TouchEvent, gutterOrder: number, gutterNum: number): void { |
442 | 452 | startEvent.preventDefault(); |
443 | 453 |
|
444 | | - // Place code here to allow '(gutterClick)' event even if '[disabled]="true"'. |
445 | | - this.currentGutterNum = gutterNum; |
446 | | - this.draggingWithoutMove = true; |
447 | | - this.ngZone.runOutsideAngular(() => { |
448 | | - this.dragListeners.push( this.renderer.listen('document', 'mouseup', (e: MouseEvent) => this.stopDragging()) ); |
449 | | - this.dragListeners.push( this.renderer.listen('document', 'touchend', (e: TouchEvent) => this.stopDragging()) ); |
450 | | - this.dragListeners.push( this.renderer.listen('document', 'touchcancel', (e: TouchEvent) => this.stopDragging()) ); |
451 | | - }); |
| 454 | + this.startPoint = getPointFromEvent(startEvent); |
| 455 | + if(!this.startPoint) { |
| 456 | + return; |
| 457 | + } |
452 | 458 |
|
453 | 459 | if(this.disabled) { |
454 | 460 | return; |
@@ -461,21 +467,24 @@ export class SplitComponent implements AfterViewInit, OnDestroy { |
461 | 467 | return; |
462 | 468 | } |
463 | 469 |
|
| 470 | + this.ngZone.runOutsideAngular(() => { |
| 471 | + this.dragListeners.push( this.renderer.listen('document', 'mouseup', (e: MouseEvent) => this.stopDragging()) ); |
| 472 | + this.dragListeners.push( this.renderer.listen('document', 'touchend', (e: TouchEvent) => this.stopDragging()) ); |
| 473 | + this.dragListeners.push( this.renderer.listen('document', 'touchcancel', (e: TouchEvent) => this.stopDragging()) ); |
| 474 | + }); |
| 475 | + |
464 | 476 | const prop = (this.direction === 'horizontal') ? 'offsetWidth' : 'offsetHeight'; |
465 | 477 | this.dragStartValues.sizePixelContainer = this.elRef.nativeElement[prop]; |
466 | 478 | this.dragStartValues.sizePixelA = areaA.comp.getSizePixel(prop); |
467 | 479 | this.dragStartValues.sizePixelB = areaB.comp.getSizePixel(prop); |
468 | 480 | this.dragStartValues.sizePercentA = areaA.size; |
469 | 481 | this.dragStartValues.sizePercentB = areaB.size; |
470 | 482 |
|
471 | | - const start: IPoint = this.getPointFromEvent(startEvent); |
472 | | - if(!start) { |
473 | | - return; |
474 | | - } |
| 483 | + this.currentGutterNum = gutterNum; |
475 | 484 |
|
476 | 485 | this.ngZone.runOutsideAngular(() => { |
477 | | - this.dragListeners.push( this.renderer.listen('document', 'mousemove', (e: MouseEvent) => this.dragEvent(e, start, areaA, areaB)) ); |
478 | | - this.dragListeners.push( this.renderer.listen('document', 'touchmove', (e: TouchEvent) => this.dragEvent(e, start, areaA, areaB)) ); |
| 486 | + this.dragListeners.push( this.renderer.listen('document', 'mousemove', (e: MouseEvent) => this.dragEvent(e, areaA, areaB)) ); |
| 487 | + this.dragListeners.push( this.renderer.listen('document', 'touchmove', (e: TouchEvent) => this.dragEvent(e, areaA, areaB)) ); |
479 | 488 | }); |
480 | 489 |
|
481 | 490 | areaA.comp.lockEvents(); |
@@ -486,43 +495,25 @@ export class SplitComponent implements AfterViewInit, OnDestroy { |
486 | 495 | this.notify('start'); |
487 | 496 | } |
488 | 497 |
|
489 | | - private dragEvent(event: MouseEvent | TouchEvent, start: IPoint, areaA: IArea, areaB: IArea): void { |
| 498 | + private dragEvent(event: MouseEvent | TouchEvent, areaA: IArea, areaB: IArea): void { |
490 | 499 | if(!this.isDragging) { |
491 | 500 | return; |
492 | 501 | } |
493 | | - const end: IPoint = this.getPointFromEvent(event); |
494 | | - if(!end) { |
| 502 | + |
| 503 | + this.endPoint = getPointFromEvent(event); |
| 504 | + if(!this.endPoint) { |
495 | 505 | return; |
496 | 506 | } |
497 | 507 |
|
498 | | - this.draggingWithoutMove = false; |
499 | | - this.drag(start, end, areaA, areaB); |
500 | | - } |
501 | | - |
502 | | - private getPointFromEvent(event: MouseEvent | TouchEvent): IPoint { |
503 | | - // TouchEvent |
504 | | - if(event instanceof TouchEvent) { |
505 | | - return { |
506 | | - x: event.touches[0].pageX, |
507 | | - y: event.touches[0].pageY, |
508 | | - }; |
509 | | - } |
510 | | - // MouseEvent |
511 | | - else if(event.pageX !== undefined && event.pageY !== undefined) { |
512 | | - return { |
513 | | - x: event.pageX, |
514 | | - y: event.pageY, |
515 | | - }; |
516 | | - } |
517 | | - return null; |
| 508 | + this.drag(areaA, areaB); |
518 | 509 | } |
519 | 510 |
|
520 | | - private drag(start: IPoint, end: IPoint, areaA: IArea, areaB: IArea): void { |
| 511 | + private drag(areaA: IArea, areaB: IArea): void { |
521 | 512 |
|
522 | 513 | // ¤ AREAS SIZE PIXEL |
523 | 514 |
|
524 | 515 | const devicePixelRatio = /*window.devicePixelRatio ||*/ 1; |
525 | | - let offsetPixel = (this.direction === 'horizontal') ? (start.x - end.x) : (start.y - end.y); |
| 516 | + let offsetPixel = (this.direction === 'horizontal') ? (this.startPoint.x - this.endPoint.x) : (this.startPoint.y - this.endPoint.y); |
526 | 517 | offsetPixel = offsetPixel / devicePixelRatio; |
527 | 518 |
|
528 | 519 | if(this.dir === 'rtl') { |
@@ -572,11 +563,14 @@ export class SplitComponent implements AfterViewInit, OnDestroy { |
572 | 563 | } |
573 | 564 |
|
574 | 565 | this.refreshStyleSizes(); |
575 | | - this.notify('progress'); |
| 566 | + |
| 567 | + if(this.startPoint.x !== this.endPoint.x || this.startPoint.y !== this.endPoint.y) { |
| 568 | + this.notify('progress'); |
| 569 | + } |
576 | 570 | } |
577 | 571 |
|
578 | 572 | private stopDragging(): void { |
579 | | - if(this.isDragging === false && this.draggingWithoutMove === false) { |
| 573 | + if(this.isDragging === false) { |
580 | 574 | return; |
581 | 575 | } |
582 | 576 |
|
@@ -591,15 +585,17 @@ export class SplitComponent implements AfterViewInit, OnDestroy { |
591 | 585 | } |
592 | 586 | } |
593 | 587 |
|
594 | | - if(this.draggingWithoutMove === true) { |
595 | | - this.notify('click'); |
596 | | - } |
597 | | - else { |
| 588 | + if(this.endPoint && (this.startPoint.x !== this.endPoint.x || this.startPoint.y !== this.endPoint.y)) { |
598 | 589 | this.notify('end'); |
599 | 590 | } |
600 | 591 |
|
601 | 592 | this.isDragging = false; |
602 | | - this.draggingWithoutMove = false; |
| 593 | + |
| 594 | + // Needed to let (click)="clickGutter(...)" event run and verify if mouse moved or not |
| 595 | + setTimeout(() => { |
| 596 | + this.startPoint = null; |
| 597 | + this.endPoint = null; |
| 598 | + }) |
603 | 599 | } |
604 | 600 |
|
605 | 601 |
|
@@ -630,3 +626,22 @@ export class SplitComponent implements AfterViewInit, OnDestroy { |
630 | 626 | this.stopDragging(); |
631 | 627 | } |
632 | 628 | } |
| 629 | + |
| 630 | + |
| 631 | +function getPointFromEvent(event: MouseEvent | TouchEvent): IPoint { |
| 632 | + // TouchEvent |
| 633 | + if(event instanceof TouchEvent) { |
| 634 | + return { |
| 635 | + x: event.touches[0].pageX, |
| 636 | + y: event.touches[0].pageY, |
| 637 | + }; |
| 638 | + } |
| 639 | + // MouseEvent |
| 640 | + else if(event.pageX !== undefined && event.pageY !== undefined) { |
| 641 | + return { |
| 642 | + x: event.pageX, |
| 643 | + y: event.pageY, |
| 644 | + }; |
| 645 | + } |
| 646 | + return null; |
| 647 | +} |