@@ -335,7 +335,7 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
335335 /**
336336 * Event triggered when the draggable element drag starts.
337337 * ```html
338- * <div igxDrag [animateOnRelease]="'true'" (dragStart)="onDragStart()">
338+ * <div igxDrag (dragStart)="onDragStart()">
339339 * <span>Drag Me!</span>
340340 * </div>
341341 * ```
@@ -349,10 +349,27 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
349349 @Output ( )
350350 public dragStart = new EventEmitter < IDragStartEventArgs > ( ) ;
351351
352+ /**
353+ * Event triggered when the draggable element has been moved.
354+ * ```html
355+ * <div igxDrag (dragMove)="onDragMove()">
356+ * <span>Drag Me!</span>
357+ * </div>
358+ * ```
359+ * ```typescript
360+ * public onDragMove(){
361+ * alert("The element has moved!");
362+ * }
363+ * ```
364+ * @memberof IgxDragDirective
365+ */
366+ @Output ( )
367+ public dragMove = new EventEmitter < IDragBaseEventArgs > ( ) ;
368+
352369 /**
353370 * Event triggered when the draggable element is released.
354371 * ```html
355- * <div igxDrag [animateOnRelease]="'true'" (dragEnd)="onDragEnd()">
372+ * <div igxDrag (dragEnd)="onDragEnd()">
356373 * <span>Drag Me!</span>
357374 * </div>
358375 * ```
@@ -369,7 +386,7 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
369386 /**
370387 * Event triggered when the drag ghost element is created.
371388 * ```html
372- * <div igxDrag (onGhostCreated )="ghostCreated()">
389+ * <div igxDrag (onGhostCreate )="ghostCreated()">
373390 * <span>Drag Me!</span>
374391 * </div>
375392 * ```
@@ -381,7 +398,7 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
381398 * @memberof IgxDragDirective
382399 */
383400 @Output ( )
384- public onGhostCreated = new EventEmitter < any > ( ) ;
401+ public onGhostCreate = new EventEmitter < any > ( ) ;
385402
386403 /**
387404 * Event triggered when the drag ghost element is created.
@@ -733,7 +750,7 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
733750 }
734751
735752 let ghostOffsetX ;
736- if ( this . ghostTemplate && this . ghostOffsetX !== undefined ) {
753+ if ( this . ghostOffsetX !== undefined ) {
737754 ghostOffsetX = this . ghostOffsetX ;
738755 } else {
739756 const marginLeft = parseInt ( document . defaultView . getComputedStyle ( this . element . nativeElement ) [ 'margin-left' ] , 10 ) ;
@@ -742,7 +759,7 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
742759 }
743760
744761 let ghostOffsetY ;
745- if ( this . ghostTemplate && this . ghostOffsetY !== undefined ) {
762+ if ( this . ghostOffsetY !== undefined ) {
746763 ghostOffsetY = this . ghostOffsetY ;
747764 } else {
748765 const marginTop = parseInt ( document . defaultView . getComputedStyle ( this . element . nativeElement ) [ 'margin-top' ] , 10 ) ;
@@ -795,7 +812,7 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
795812 this . _dragStarted = true ;
796813 if ( this . renderGhost ) {
797814 // We moved enough so dragGhost can be rendered and actual dragging to start.
798- this . createDragGhost ( event ) ;
815+ this . createDragGhost ( pageX , pageY ) ;
799816 }
800817 }
801818 return ;
@@ -906,23 +923,27 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
906923 * Create dragGhost element - if a Node object is provided it creates a clone of that node,
907924 * otherwise it clones the host element.
908925 * Bind all needed events.
909- * @param event Pointer event required when the dragGhost is being initialized.
926+ * @param pageX Latest pointer position on the X axis relative to the page.
927+ * @param pageY Latest pointer position on the Y axis relative to the page.
910928 * @param node The Node object to be cloned.
911929 */
912- protected createDragGhost ( event , node : any = null ) {
930+ protected createDragGhost ( pageX , pageY , node : any = null ) {
913931 if ( this . ghostTemplate ) {
914932 const dynamicGhostRef = this . viewContainer . createEmbeddedView ( this . ghostTemplate ) ;
915933 this . dragGhost = dynamicGhostRef . rootNodes [ 0 ] ;
916934 } else {
917935 this . dragGhost = node ? node . cloneNode ( true ) : this . element . nativeElement . cloneNode ( true ) ;
918936 }
919937
920- this . dragGhost . style . transitionDuration = '0.0s' ;
921- this . dragGhost . style . position = 'absolute' ;
938+ const totalMovedX = pageX - this . _startX ;
939+ const totalMovedY = pageY - this . _startY ;
922940 this . _dragGhostHostX = this . dragGhostHost ? this . getdragGhostHostOffsetLeft ( this . dragGhostHost ) : 0 ;
923941 this . _dragGhostHostY = this . dragGhostHost ? this . getdragGhostHostOffsetTop ( this . dragGhostHost ) : 0 ;
924- this . dragGhost . style . left = this . _ghostStartX - this . _dragGhostHostX + 'px' ;
925- this . dragGhost . style . top = this . _ghostStartY - this . _dragGhostHostY + 'px' ;
942+
943+ this . dragGhost . style . transitionDuration = '0.0s' ;
944+ this . dragGhost . style . position = 'absolute' ;
945+ this . dragGhost . style . left = ( this . _ghostStartX + totalMovedX ) - this . _dragGhostHostX + 'px' ;
946+ this . dragGhost . style . top = ( this . _ghostStartY + totalMovedY ) - this . _dragGhostHostY + 'px' ;
926947
927948 if ( this . ghostImageClass ) {
928949 this . renderer . addClass ( this . dragGhost , this . ghostImageClass ) ;
@@ -934,8 +955,8 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
934955 document . body . appendChild ( this . dragGhost ) ;
935956 }
936957
937- if ( this . ghostTemplate ) {
938- this . onGhostCreated . emit ( {
958+ if ( this . renderGhost ) {
959+ this . onGhostCreate . emit ( {
939960 owner : this ,
940961 ghostElement : this . dragGhost
941962 } ) ;
@@ -985,6 +1006,13 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
9851006 originalEvent : originalEvent
9861007 } ;
9871008
1009+ this . zone . run ( ( ) => {
1010+ this . dragMove . emit ( {
1011+ originalEvent : originalEvent ,
1012+ owner : this
1013+ } ) ;
1014+ } ) ;
1015+
9881016 const elementsFromPoint = this . getElementsAtPoint ( pageX , pageY ) ;
9891017 for ( let i = 0 ; i < elementsFromPoint . length ; i ++ ) {
9901018 if ( elementsFromPoint [ i ] . getAttribute ( 'droppable' ) === 'true' && elementsFromPoint [ i ] !== this . dragGhost ) {
@@ -1189,14 +1217,20 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
11891217 }
11901218
11911219 protected getdragGhostHostOffsetLeft ( dragGhostHost : any ) {
1192- if ( dragGhostHost . offsetParent && dragGhostHost . computedStyleMap ( ) . get ( 'position' ) . value === 'static' ) {
1220+ if ( dragGhostHost . computedStyleMap ( ) . get ( 'position' ) . value === 'static' &&
1221+ dragGhostHost . offsetParent && dragGhostHost . offsetParent === document . body ) {
1222+ return 0 ;
1223+ } else if ( dragGhostHost . computedStyleMap ( ) . get ( 'position' ) . value === 'static' && dragGhostHost . offsetParent ) {
11931224 return dragGhostHost . offsetParent . getBoundingClientRect ( ) . left ;
11941225 }
11951226 return dragGhostHost . getBoundingClientRect ( ) . left ;
11961227 }
11971228
11981229 protected getdragGhostHostOffsetTop ( dragGhostHost : any ) {
1199- if ( dragGhostHost . offsetParent && dragGhostHost . computedStyleMap ( ) . get ( 'position' ) . value === 'static' ) {
1230+ if ( dragGhostHost . computedStyleMap ( ) . get ( 'position' ) . value === 'static' &&
1231+ dragGhostHost . offsetParent && dragGhostHost . offsetParent === document . body ) {
1232+ return 0 ;
1233+ } else if ( dragGhostHost . computedStyleMap ( ) . get ( 'position' ) . value === 'static' && dragGhostHost . offsetParent ) {
12001234 return dragGhostHost . offsetParent . getBoundingClientRect ( ) . top ;
12011235 }
12021236 return dragGhostHost . getBoundingClientRect ( ) . top ;
0 commit comments