88
99import { ElementRef , NgZone } from '@angular/core' ;
1010import { Platform } from '@angular/cdk/platform' ;
11- import { ViewportRuler } from '@angular/cdk/scrolling' ;
1211import { RippleRef , RippleState } from './ripple-ref' ;
1312
1413
@@ -56,11 +55,7 @@ export class RippleRenderer {
5655 /** Whether mouse ripples should be created or not. */
5756 rippleDisabled : boolean = false ;
5857
59- constructor (
60- elementRef : ElementRef ,
61- private _ngZone : NgZone ,
62- private _ruler : ViewportRuler ,
63- platform : Platform ) {
58+ constructor ( elementRef : ElementRef , private _ngZone : NgZone , platform : Platform ) {
6459 // Only do anything if we're on the browser.
6560 if ( platform . isBrowser ) {
6661 this . _containerElement = elementRef . nativeElement ;
@@ -79,27 +74,26 @@ export class RippleRenderer {
7974 }
8075 }
8176
82- /** Fades in a ripple at the given coordinates. */
83- fadeInRipple ( pageX : number , pageY : number , config : RippleConfig = { } ) : RippleRef {
84- let containerRect = this . _containerElement . getBoundingClientRect ( ) ;
77+ /**
78+ * Fades in a ripple at the given coordinates.
79+ * @param x Coordinate within the element, along the X axis at which to start the ripple.
80+ * @param Y Coordinate within the element, along the Y axis at which to start the ripple.
81+ * @param config Extra ripple options.
82+ */
83+ fadeInRipple ( x : number , y : number , config : RippleConfig = { } ) : RippleRef {
84+ const containerRect = this . _containerElement . getBoundingClientRect ( ) ;
8585
8686 if ( config . centered ) {
87- pageX = containerRect . left + containerRect . width / 2 ;
88- pageY = containerRect . top + containerRect . height / 2 ;
89- } else {
90- // Subtract scroll values from the coordinates because calculations below
91- // are always relative to the viewport rectangle.
92- let scrollPosition = this . _ruler . getViewportScrollPosition ( ) ;
93- pageX -= scrollPosition . left ;
94- pageY -= scrollPosition . top ;
87+ x = containerRect . left + containerRect . width / 2 ;
88+ y = containerRect . top + containerRect . height / 2 ;
9589 }
9690
97- let radius = config . radius || distanceToFurthestCorner ( pageX , pageY , containerRect ) ;
98- let duration = RIPPLE_FADE_IN_DURATION * ( 1 / ( config . speedFactor || 1 ) ) ;
99- let offsetX = pageX - containerRect . left ;
100- let offsetY = pageY - containerRect . top ;
91+ const radius = config . radius || distanceToFurthestCorner ( x , y , containerRect ) ;
92+ const duration = RIPPLE_FADE_IN_DURATION * ( 1 / ( config . speedFactor || 1 ) ) ;
93+ const offsetX = x - containerRect . left ;
94+ const offsetY = y - containerRect . top ;
10195
102- let ripple = document . createElement ( 'div' ) ;
96+ const ripple = document . createElement ( 'div' ) ;
10397 ripple . classList . add ( 'mat-ripple-element' ) ;
10498
10599 ripple . style . left = `${ offsetX - radius } px` ;
@@ -189,7 +183,7 @@ export class RippleRenderer {
189183 private onMousedown ( event : MouseEvent ) {
190184 if ( ! this . rippleDisabled ) {
191185 this . _isPointerDown = true ;
192- this . fadeInRipple ( event . pageX , event . pageY , this . rippleConfig ) ;
186+ this . fadeInRipple ( event . clientX , event . clientY , this . rippleConfig ) ;
193187 }
194188 }
195189
@@ -215,9 +209,9 @@ export class RippleRenderer {
215209 /** Function being called whenever the trigger is being touched. */
216210 private onTouchstart ( event : TouchEvent ) {
217211 if ( ! this . rippleDisabled ) {
218- const { pageX , pageY } = event . touches [ 0 ] ;
212+ const { clientX , clientY } = event . touches [ 0 ] ;
219213 this . _isPointerDown = true ;
220- this . fadeInRipple ( pageX , pageY , this . rippleConfig ) ;
214+ this . fadeInRipple ( clientX , clientY , this . rippleConfig ) ;
221215 }
222216 }
223217
0 commit comments