kamrify commited on
Commit
2f7f50d
·
1 Parent(s): 71c61ac

Cancel any pending animations on quick movements

Browse files
Files changed (2) hide show
  1. src/common/constants.js +1 -1
  2. src/core/element.js +9 -4
src/common/constants.js CHANGED
@@ -10,7 +10,7 @@ export const ID_OVERLAY = 'driver-page-overlay';
10
  export const ID_STAGE = 'driver-highlighted-element-stage';
11
  export const ID_POPOVER = 'driver-popover-item';
12
 
13
- export const DRIVER_HIGHLIGHTED_ELEMENT = 'driver-highlighted-element';
14
 
15
  export const CLASS_POPOVER_TIP = 'driver-popover-tip';
16
  export const CLASS_POPOVER_TITLE = 'driver-popover-title';
 
10
  export const ID_STAGE = 'driver-highlighted-element-stage';
11
  export const ID_POPOVER = 'driver-popover-item';
12
 
13
+ export const CLASS_DRIVER_HIGHLIGHTED_ELEMENT = 'driver-highlighted-element';
14
 
15
  export const CLASS_POPOVER_TIP = 'driver-popover-tip';
16
  export const CLASS_POPOVER_TITLE = 'driver-popover-title';
src/core/element.js CHANGED
@@ -1,5 +1,5 @@
1
  import Position from './position';
2
- import { ANIMATION_DURATION_MS, DRIVER_HIGHLIGHTED_ELEMENT } from '../common/constants';
3
 
4
  /**
5
  * Wrapper around DOMElements to enrich them
@@ -23,6 +23,8 @@ export default class Element {
23
  this.overlay = overlay;
24
  this.popover = popover;
25
 
 
 
26
  this.highlightFinished = false; // To track when the element has fully highlighted
27
  }
28
 
@@ -140,7 +142,10 @@ export default class Element {
140
  onDeselected() {
141
  this.hidePopover();
142
 
143
- this.node.classList.remove(DRIVER_HIGHLIGHTED_ELEMENT);
 
 
 
144
 
145
  this.highlightFinished = false;
146
 
@@ -170,7 +175,7 @@ export default class Element {
170
  onHighlighted() {
171
  this.showPopover();
172
 
173
- this.node.classList.add('driver-highlighted-element');
174
 
175
  this.highlightFinished = true;
176
 
@@ -228,7 +233,7 @@ export default class Element {
228
  // For first highlight, show it immediately because there won't be any animation
229
  const animationDuration = !this.overlay.lastHighlightedElement ? 0 : ANIMATION_DURATION_MS * 2;
230
 
231
- window.setTimeout(() => {
232
  this.popover.show(showAtPosition);
233
  }, animationDuration);
234
  }
 
1
  import Position from './position';
2
+ import { ANIMATION_DURATION_MS, CLASS_DRIVER_HIGHLIGHTED_ELEMENT } from '../common/constants';
3
 
4
  /**
5
  * Wrapper around DOMElements to enrich them
 
23
  this.overlay = overlay;
24
  this.popover = popover;
25
 
26
+ this.animationTimeout = null;
27
+
28
  this.highlightFinished = false; // To track when the element has fully highlighted
29
  }
30
 
 
142
  onDeselected() {
143
  this.hidePopover();
144
 
145
+ this.node.classList.remove(CLASS_DRIVER_HIGHLIGHTED_ELEMENT);
146
+
147
+ // If there was any animation in progress, cancel that
148
+ this.window.clearTimeout(this.animationTimeout);
149
 
150
  this.highlightFinished = false;
151
 
 
175
  onHighlighted() {
176
  this.showPopover();
177
 
178
+ this.node.classList.add(CLASS_DRIVER_HIGHLIGHTED_ELEMENT);
179
 
180
  this.highlightFinished = true;
181
 
 
233
  // For first highlight, show it immediately because there won't be any animation
234
  const animationDuration = !this.overlay.lastHighlightedElement ? 0 : ANIMATION_DURATION_MS * 2;
235
 
236
+ this.animationTimeout = this.window.setTimeout(() => {
237
  this.popover.show(showAtPosition);
238
  }, animationDuration);
239
  }