Skip to content

Commit

Permalink
Use Date.now() for better browser compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
devversion committed Oct 21, 2017
1 parent f479940 commit 62109ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/demo-app/ripple/ripple-demo.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '../../lib/core/style/vendor-prefixes';

.demo-ripple {
button, a {
margin: 8px;
Expand All @@ -15,10 +17,9 @@
transition: all 200ms linear;
width: 200px;

// Disable the blue overlay on touch and disable user text selection.
// This makes it easier to see ripples fading in.
// Disable the blue overlay on touch. This makes it easier to see ripples fading in.
-webkit-tap-highlight-color: transparent;
user-select: none;
@include user-select(none);

&.demo-ripple-disabled {
color: rgba(32, 32, 32, 0.4);
Expand Down
6 changes: 3 additions & 3 deletions src/lib/core/ripple/ripple-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const RIPPLE_FADE_OUT_DURATION = 400;
* Timeout for ignoring mouse events. Mouse events will be temporary ignored after touch
* events to avoid synthetic mouse events.
*/
const ignoreMouseEventsTimeout = 800;
const IGNORE_MOUSE_EVENTS_TIMEOUT = 800;

export type RippleConfig = {
color?: string;
Expand Down Expand Up @@ -190,7 +190,7 @@ export class RippleRenderer {
/** Function being called whenever the trigger is being pressed using mouse. */
private onMousedown(event: MouseEvent) {
const isSyntheticEvent = this._lastTouchStartEvent &&
event.timeStamp < this._lastTouchStartEvent + ignoreMouseEventsTimeout;
Date.now() < this._lastTouchStartEvent + IGNORE_MOUSE_EVENTS_TIMEOUT;

if (!this.rippleDisabled && !isSyntheticEvent) {
this._isPointerDown = true;
Expand All @@ -204,7 +204,7 @@ export class RippleRenderer {
// Some browsers fire mouse events after a `touchstart` event. Those synthetic mouse
// events will launch a second ripple if we don't ignore mouse events for a specific
// time after a touchstart event.
this._lastTouchStartEvent = event.timeStamp;
this._lastTouchStartEvent = Date.now();
this._isPointerDown = true;

this.fadeInRipple(event.touches[0].clientX, event.touches[0].clientY, this.rippleConfig);
Expand Down

0 comments on commit 62109ab

Please sign in to comment.