Skip to content

Commit f77b5cd

Browse files
committed
Address comments
1 parent 01ec7a3 commit f77b5cd

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

src/demo-app/ripple/ripple-demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class RippleDemo {
2323

2424
doManualRipple() {
2525
if (this.ripple) {
26-
this.ripple.createRipple(0, 0, { centered: true });
26+
this.ripple.launch(0, 0, { centered: true });
2727
}
2828
}
2929

src/lib/core/ripple/ripple-renderer.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ export type RippleConfig = {
3131
export class RippleRenderer {
3232

3333
/** Element where the ripples are being added to. */
34-
private _targetElement: HTMLElement;
34+
private _containerElement: HTMLElement;
3535

3636
/** Element which triggers the ripple elements on mouse events. */
3737
private _triggerElement: HTMLElement;
3838

3939
/** Whether the mouse is currently down or not. */
4040
private _isMousedown: boolean = false;
4141

42-
/** Currently showing ripples that will be closed on mouseup. */
43-
private _showingRipples: HTMLElement[] = [];
42+
/** Currently active ripples that will be closed on mouseup. */
43+
private _activeRipples: HTMLElement[] = [];
4444

4545
/** Events to be registered on the trigger element. */
4646
private _triggerEvents = new Map<string, any>();
@@ -52,24 +52,24 @@ export class RippleRenderer {
5252
rippleDisabled: boolean = false;
5353

5454
constructor(_elementRef: ElementRef, private _ngZone: NgZone, private _ruler: ViewportRuler) {
55-
this._targetElement = _elementRef.nativeElement;
55+
this._containerElement = _elementRef.nativeElement;
5656

5757
// Specify events which need to be registered on the trigger.
5858
this._triggerEvents.set('mousedown', this.onMousedown.bind(this));
5959
this._triggerEvents.set('mouseup', this.onMouseup.bind(this));
6060
this._triggerEvents.set('mouseleave', this.onMouseLeave.bind(this));
6161

6262
// By default use the host element as trigger element.
63-
this.setTriggerElement(this._targetElement);
63+
this.setTriggerElement(this._containerElement);
6464
}
6565

6666
/** Fades in a ripple at the given coordinates. */
6767
fadeInRipple(pageX: number, pageY: number, config: RippleConfig = {}) {
68-
let targetRect = this._targetElement.getBoundingClientRect();
68+
let containerRect = this._containerElement.getBoundingClientRect();
6969

7070
if (config.centered) {
71-
pageX = targetRect.left + targetRect.width / 2;
72-
pageY = targetRect.top + targetRect.height / 2;
71+
pageX = containerRect.left + containerRect.width / 2;
72+
pageY = containerRect.top + containerRect.height / 2;
7373
} else {
7474
// Subtract scroll values from the coordinates because calculations below
7575
// are always relative to the viewport rectangle.
@@ -78,10 +78,10 @@ export class RippleRenderer {
7878
pageY -= scrollPosition.top;
7979
}
8080

81-
let radius = config.radius || distanceToFurthestCorner(pageX, pageY, targetRect);
81+
let radius = config.radius || distanceToFurthestCorner(pageX, pageY, containerRect);
8282
let duration = 1 / (config.speedFactor || 1) * (radius / RIPPLE_SPEED_PX_PER_SECOND);
83-
let offsetX = pageX - targetRect.left;
84-
let offsetY = pageY - targetRect.top;
83+
let offsetX = pageX - containerRect.left;
84+
let offsetY = pageY - containerRect.top;
8585

8686
let ripple = document.createElement('div');
8787
ripple.classList.add('md-ripple-element');
@@ -95,7 +95,7 @@ export class RippleRenderer {
9595
ripple.style.backgroundColor = config.color;
9696
ripple.style.transitionDuration = `${duration}s`;
9797

98-
this._targetElement.appendChild(ripple);
98+
this._containerElement.appendChild(ripple);
9999

100100
// By default the browser does not recalculate the styles of dynamically created
101101
// ripple elements. This is critical because then the `scale` would not animate properly.
@@ -108,7 +108,7 @@ export class RippleRenderer {
108108
// Wait for the ripple to be faded in. Once faded in the ripple can be hided if the mouse is
109109
// released.
110110
this.runTimeoutOutsideZone(() => {
111-
this._isMousedown ? this._showingRipples.push(ripple) : this.fadeOutRipple(ripple);
111+
this._isMousedown ? this._activeRipples.push(ripple) : this.fadeOutRipple(ripple);
112112
}, duration * 1000);
113113
}
114114

@@ -151,8 +151,8 @@ export class RippleRenderer {
151151
/** Listener being called on mouseup event. */
152152
private onMouseup() {
153153
this._isMousedown = false;
154-
this._showingRipples.forEach(ripple => this.fadeOutRipple(ripple));
155-
this._showingRipples = [];
154+
this._activeRipples.forEach(ripple => this.fadeOutRipple(ripple));
155+
this._activeRipples = [];
156156
}
157157

158158
/** Listener being called on mouseleave event. */

src/lib/core/ripple/ripple.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe('MdRipple', () => {
118118

119119
expect(rippleTarget.querySelectorAll('.md-ripple-element').length).toBe(0);
120120

121-
rippleComponent.createRipple(0, 0);
121+
rippleComponent.launch(0, 0);
122122

123123
expect(rippleTarget.querySelectorAll('.md-ripple-element').length).toBe(1);
124124
});

src/lib/core/ripple/ripple.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ export class MdRipple implements OnChanges, OnDestroy {
2727
* The element that triggers the ripple when click events are received. Defaults to the
2828
* directive's host element.
2929
*/
30-
@Input('mdRippleTrigger') trigger: any;
30+
// Prevent TS metadata emit from referencing HTMLElement in ripple.js
31+
// Otherwise running this code in a Node environment (e.g Universal) will not work.
32+
@Input('mdRippleTrigger') trigger: HTMLElement|HTMLElement;
3133

3234
/**
3335
* Whether the ripple always originates from the center of the host element's bounds, rather
@@ -81,8 +83,8 @@ export class MdRipple implements OnChanges, OnDestroy {
8183
this._rippleRenderer.setTriggerElement(null);
8284
}
8385

84-
/** Creates a manual ripple at the specified position. */
85-
createRipple(pageX: number, pageY: number, config?: RippleConfig) {
86+
/** Launches a manual ripple at the specified position. */
87+
launch(pageX: number, pageY: number, config?: RippleConfig) {
8688
this._rippleRenderer.fadeInRipple(pageX, pageY, config);
8789
}
8890

0 commit comments

Comments
 (0)