@@ -18,12 +18,14 @@ import {
1818 QueryList ,
1919 RendererStyleFlags2 ,
2020 booleanAttribute ,
21- EmbeddedViewRef
21+ EmbeddedViewRef ,
22+ inject
2223} from '@angular/core' ;
2324import { animationFrameScheduler , fromEvent , interval , Subject } from 'rxjs' ;
2425import { takeUntil , throttle } from 'rxjs/operators' ;
2526import { IBaseEventArgs , PlatformUtil } from '../../core/utils' ;
2627import { IDropStrategy , IgxDefaultDropStrategy } from './drag-drop.strategy' ;
28+ import { DOCUMENT } from '@angular/common' ;
2729
2830enum DragScrollDirection {
2931 UP ,
@@ -551,7 +553,7 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
551553 protected set ghostLeft ( pageX : number ) {
552554 if ( this . ghostElement ) {
553555 // We need to take into account marginLeft, since top style does not include margin, but pageX includes the margin.
554- const ghostMarginLeft = parseInt ( document . defaultView . getComputedStyle ( this . ghostElement ) [ 'margin-left' ] , 10 ) ;
556+ const ghostMarginLeft = parseInt ( this . document . defaultView . getComputedStyle ( this . ghostElement ) [ 'margin-left' ] , 10 ) ;
555557 // If ghost host is defined it needs to be taken into account.
556558 this . ghostElement . style . left = ( pageX - ghostMarginLeft - this . _ghostHostX ) + 'px' ;
557559 }
@@ -566,7 +568,7 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
566568 protected set ghostTop ( pageY : number ) {
567569 if ( this . ghostElement ) {
568570 // We need to take into account marginTop, since top style does not include margin, but pageY includes the margin.
569- const ghostMarginTop = parseInt ( document . defaultView . getComputedStyle ( this . ghostElement ) [ 'margin-top' ] , 10 ) ;
571+ const ghostMarginTop = parseInt ( this . document . defaultView . getComputedStyle ( this . ghostElement ) [ 'margin-top' ] , 10 ) ;
570572 // If ghost host is defined it needs to be taken into account.
571573 this . ghostElement . style . top = ( pageY - ghostMarginTop - this . _ghostHostY ) + 'px' ;
572574 }
@@ -579,19 +581,19 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
579581 }
580582
581583 protected get windowScrollTop ( ) {
582- return document . documentElement . scrollTop || window . scrollY ;
584+ return this . document . documentElement . scrollTop || window . scrollY ;
583585 }
584586
585587 protected get windowScrollLeft ( ) {
586- return document . documentElement . scrollLeft || window . scrollX ;
588+ return this . document . documentElement . scrollLeft || window . scrollX ;
587589 }
588590
589591 protected get windowScrollHeight ( ) {
590- return document . documentElement . scrollHeight ;
592+ return this . document . documentElement . scrollHeight ;
591593 }
592594
593595 protected get windowScrollWidth ( ) {
594- return document . documentElement . scrollWidth ;
596+ return this . document . documentElement . scrollWidth ;
595597 }
596598
597599 /**
@@ -641,6 +643,7 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
641643 protected _scrollContainerStepMs = 10 ;
642644 protected _scrollContainerThreshold = 25 ;
643645 protected _containerScrollIntervalId = null ;
646+ private document = inject ( DOCUMENT ) ;
644647
645648 /**
646649 * Sets the offset of the dragged element relative to the mouse in pixels.
@@ -690,7 +693,7 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
690693 public viewContainer : ViewContainerRef ,
691694 public zone : NgZone ,
692695 public renderer : Renderer2 ,
693- protected platformUtil : PlatformUtil ,
696+ protected platformUtil : PlatformUtil
694697 ) {
695698 }
696699
@@ -746,20 +749,20 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
746749
747750 // We should bind to document events only once when there are no pointer events.
748751 if ( ! this . pointerEventsEnabled && this . touchEventsEnabled ) {
749- fromEvent ( document . defaultView , 'touchmove' ) . pipe (
752+ fromEvent ( this . document . defaultView , 'touchmove' ) . pipe (
750753 throttle ( ( ) => interval ( 0 , animationFrameScheduler ) ) ,
751754 takeUntil ( this . _destroy )
752755 ) . subscribe ( ( res ) => this . onPointerMove ( res ) ) ;
753756
754- fromEvent ( document . defaultView , 'touchend' ) . pipe ( takeUntil ( this . _destroy ) )
757+ fromEvent ( this . document . defaultView , 'touchend' ) . pipe ( takeUntil ( this . _destroy ) )
755758 . subscribe ( ( res ) => this . onPointerUp ( res ) ) ;
756759 } else if ( ! this . pointerEventsEnabled ) {
757- fromEvent ( document . defaultView , 'mousemove' ) . pipe (
760+ fromEvent ( this . document . defaultView , 'mousemove' ) . pipe (
758761 throttle ( ( ) => interval ( 0 , animationFrameScheduler ) ) ,
759762 takeUntil ( this . _destroy )
760763 ) . subscribe ( ( res ) => this . onPointerMove ( res ) ) ;
761764
762- fromEvent ( document . defaultView , 'mouseup' ) . pipe ( takeUntil ( this . _destroy ) )
765+ fromEvent ( this . document . defaultView , 'mouseup' ) . pipe ( takeUntil ( this . _destroy ) )
763766 . subscribe ( ( res ) => this . onPointerUp ( res ) ) ;
764767 }
765768 this . element . nativeElement . addEventListener ( 'transitionend' , this . onTransitionEnd . bind ( this ) ) ;
@@ -1140,9 +1143,9 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
11401143 if ( this . ghostHost && ! Array . from ( this . ghostHost . children ) . includes ( this . ghostElement ) ) {
11411144 ghostReattached = true ;
11421145 this . ghostHost . appendChild ( this . ghostElement ) ;
1143- } else if ( ! this . ghostHost && ! Array . from ( document . body . children ) . includes ( this . ghostElement ) ) {
1146+ } else if ( ! this . ghostHost && ! Array . from ( this . document . body . children ) . includes ( this . ghostElement ) ) {
11441147 ghostReattached = true ;
1145- document . body . appendChild ( this . ghostElement ) ;
1148+ this . document . body . appendChild ( this . ghostElement ) ;
11461149 }
11471150
11481151 if ( ghostReattached ) {
@@ -1293,11 +1296,11 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
12931296 if ( this . ghostHost ) {
12941297 this . ghostHost . appendChild ( this . ghostElement ) ;
12951298 } else {
1296- document . body . appendChild ( this . ghostElement ) ;
1299+ this . document . body . appendChild ( this . ghostElement ) ;
12971300 }
12981301
1299- const ghostMarginLeft = parseInt ( document . defaultView . getComputedStyle ( this . ghostElement ) [ 'margin-left' ] , 10 ) ;
1300- const ghostMarginTop = parseInt ( document . defaultView . getComputedStyle ( this . ghostElement ) [ 'margin-top' ] , 10 ) ;
1302+ const ghostMarginLeft = parseInt ( this . document . defaultView . getComputedStyle ( this . ghostElement ) [ 'margin-left' ] , 10 ) ;
1303+ const ghostMarginTop = parseInt ( this . document . defaultView . getComputedStyle ( this . ghostElement ) [ 'margin-top' ] , 10 ) ;
13011304 this . ghostElement . style . left = ( this . _ghostStartX - ghostMarginLeft + totalMovedX - this . _ghostHostX ) + 'px' ;
13021305 this . ghostElement . style . top = ( this . _ghostStartY - ghostMarginTop + totalMovedY - this . _ghostHostY ) + 'px' ;
13031306
@@ -1417,13 +1420,13 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
14171420 // using window.pageXOffset for IE9 compatibility
14181421 const viewPortX = pageX - window . pageXOffset ;
14191422 const viewPortY = pageY - window . pageYOffset ;
1420- if ( document [ 'msElementsFromPoint' ] ) {
1423+ if ( this . document [ 'msElementsFromPoint' ] ) {
14211424 // Edge and IE special snowflakes
1422- const elements = document [ 'msElementsFromPoint' ] ( viewPortX , viewPortY ) ;
1425+ const elements = this . document [ 'msElementsFromPoint' ] ( viewPortX , viewPortY ) ;
14231426 return elements === null ? [ ] : elements ;
14241427 } else {
14251428 // Other browsers like Chrome, Firefox, Opera
1426- return document . elementsFromPoint ( viewPortX , viewPortY ) ;
1429+ return this . document . elementsFromPoint ( viewPortX , viewPortY ) ;
14271430 }
14281431 }
14291432
@@ -1483,8 +1486,8 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
14831486 protected getGhostHostBaseOffsetX ( ) {
14841487 if ( ! this . ghostHost ) return 0 ;
14851488
1486- const ghostPosition = document . defaultView . getComputedStyle ( this . ghostHost ) . getPropertyValue ( 'position' ) ;
1487- if ( ghostPosition === 'static' && this . ghostHost . offsetParent && this . ghostHost . offsetParent === document . body ) {
1489+ const ghostPosition = this . document . defaultView . getComputedStyle ( this . ghostHost ) . getPropertyValue ( 'position' ) ;
1490+ if ( ghostPosition === 'static' && this . ghostHost . offsetParent && this . ghostHost . offsetParent === this . document . body ) {
14881491 return 0 ;
14891492 } else if ( ghostPosition === 'static' && this . ghostHost . offsetParent ) {
14901493 return this . ghostHost . offsetParent . getBoundingClientRect ( ) . left + this . windowScrollLeft ;
@@ -1495,8 +1498,8 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
14951498 protected getGhostHostBaseOffsetY ( ) {
14961499 if ( ! this . ghostHost ) return 0 ;
14971500
1498- const ghostPosition = document . defaultView . getComputedStyle ( this . ghostHost ) . getPropertyValue ( 'position' ) ;
1499- if ( ghostPosition === 'static' && this . ghostHost . offsetParent && this . ghostHost . offsetParent === document . body ) {
1501+ const ghostPosition = this . document . defaultView . getComputedStyle ( this . ghostHost ) . getPropertyValue ( 'position' ) ;
1502+ if ( ghostPosition === 'static' && this . ghostHost . offsetParent && this . ghostHost . offsetParent === this . document . body ) {
15001503 return 0 ;
15011504 } else if ( ghostPosition === 'static' && this . ghostHost . offsetParent ) {
15021505 return this . ghostHost . offsetParent . getBoundingClientRect ( ) . top + this . windowScrollTop ;
@@ -1540,8 +1543,8 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
15401543 let yDir = scrollDir == DragScrollDirection . UP ? - 1 : ( scrollDir == DragScrollDirection . DOWN ? 1 : 0 ) ;
15411544 if ( ! this . scrollContainer ) {
15421545 // Cap scrolling so we don't scroll past the window max scroll position.
1543- const maxScrollX = this . _originalScrollContainerWidth - document . documentElement . clientWidth ;
1544- const maxScrollY = this . _originalScrollContainerHeight - document . documentElement . clientHeight ;
1546+ const maxScrollX = this . _originalScrollContainerWidth - this . document . documentElement . clientWidth ;
1547+ const maxScrollY = this . _originalScrollContainerHeight - this . document . documentElement . clientHeight ;
15451548 xDir = ( this . windowScrollLeft <= 0 && xDir < 0 ) || ( this . windowScrollLeft >= maxScrollX && xDir > 0 ) ? 0 : xDir ;
15461549 yDir = ( this . windowScrollTop <= 0 && yDir < 0 ) || ( this . windowScrollTop >= maxScrollY && yDir > 0 ) ? 0 : yDir ;
15471550 } else {
0 commit comments