8
8
9
9
import { ElementRef , NgZone } from '@angular/core' ;
10
10
import { Platform } from '@angular/cdk/platform' ;
11
- import { ViewportRuler } from '@angular/cdk/scrolling' ;
12
11
import { RippleRef , RippleState } from './ripple-ref' ;
13
12
14
13
@@ -56,11 +55,7 @@ export class RippleRenderer {
56
55
/** Whether mouse ripples should be created or not. */
57
56
rippleDisabled : boolean = false ;
58
57
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 ) {
64
59
// Only do anything if we're on the browser.
65
60
if ( platform . isBrowser ) {
66
61
this . _containerElement = elementRef . nativeElement ;
@@ -79,27 +74,26 @@ export class RippleRenderer {
79
74
}
80
75
}
81
76
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 ( ) ;
85
85
86
86
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 ;
95
89
}
96
90
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 ;
101
95
102
- let ripple = document . createElement ( 'div' ) ;
96
+ const ripple = document . createElement ( 'div' ) ;
103
97
ripple . classList . add ( 'mat-ripple-element' ) ;
104
98
105
99
ripple . style . left = `${ offsetX - radius } px` ;
@@ -189,7 +183,7 @@ export class RippleRenderer {
189
183
private onMousedown ( event : MouseEvent ) {
190
184
if ( ! this . rippleDisabled ) {
191
185
this . _isPointerDown = true ;
192
- this . fadeInRipple ( event . pageX , event . pageY , this . rippleConfig ) ;
186
+ this . fadeInRipple ( event . clientX , event . clientY , this . rippleConfig ) ;
193
187
}
194
188
}
195
189
@@ -215,9 +209,9 @@ export class RippleRenderer {
215
209
/** Function being called whenever the trigger is being touched. */
216
210
private onTouchstart ( event : TouchEvent ) {
217
211
if ( ! this . rippleDisabled ) {
218
- const { pageX , pageY } = event . touches [ 0 ] ;
212
+ const { clientX , clientY } = event . touches [ 0 ] ;
219
213
this . _isPointerDown = true ;
220
- this . fadeInRipple ( pageX , pageY , this . rippleConfig ) ;
214
+ this . fadeInRipple ( clientX , clientY , this . rippleConfig ) ;
221
215
}
222
216
}
223
217
0 commit comments