Refactor and animation fixes
Browse files- src/core/overlay.js +37 -29
- src/driver.scss +1 -7
src/core/overlay.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import Position from './position';
|
2 |
-
import { ID_OVERLAY, OVERLAY_HTML } from '../common/constants';
|
3 |
import { createNodeFromString } from '../common/utils';
|
4 |
|
5 |
/**
|
@@ -19,8 +19,7 @@ export default class Overlay {
|
|
19 |
this.positionToHighlight = new Position({}); // position at which layover is to be patched at
|
20 |
this.highlightedElement = null; // currently highlighted dom element (instance of Element)
|
21 |
this.lastHighlightedElement = null; // element that was highlighted before current one
|
22 |
-
|
23 |
-
this.draw = this.draw.bind(this); // To pass the context of class, as it is to be used in redraw animation callback
|
24 |
|
25 |
this.window = window;
|
26 |
this.document = document;
|
@@ -53,6 +52,10 @@ export default class Overlay {
|
|
53 |
return;
|
54 |
}
|
55 |
|
|
|
|
|
|
|
|
|
56 |
// Trigger the hook for highlight started
|
57 |
element.onHighlightStarted();
|
58 |
|
@@ -71,7 +74,34 @@ export default class Overlay {
|
|
71 |
this.highlightedElement = element;
|
72 |
this.positionToHighlight = position;
|
73 |
|
74 |
-
this.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
}
|
76 |
|
77 |
/**
|
@@ -102,42 +132,20 @@ export default class Overlay {
|
|
102 |
this.highlightedElement = null;
|
103 |
this.lastHighlightedElement = null;
|
104 |
|
105 |
-
this.
|
106 |
this.stage.hide();
|
107 |
}
|
108 |
|
109 |
-
/**
|
110 |
-
* `draw` is called for every frame . Puts back the
|
111 |
-
* filled overlay on body (i.e. while removing existing highlight if any) and
|
112 |
-
* Slowly eases towards the item to be selected.
|
113 |
-
*/
|
114 |
-
draw() {
|
115 |
-
if (!this.highlightedElement || !this.positionToHighlight.canHighlight()) {
|
116 |
-
return;
|
117 |
-
}
|
118 |
-
|
119 |
-
// Show the overlay
|
120 |
-
this.node.style.opacity = `${this.options.opacity}`;
|
121 |
-
|
122 |
-
// Show the stage
|
123 |
-
this.stage.show(this.positionToHighlight);
|
124 |
-
|
125 |
-
// Element has been highlighted
|
126 |
-
this.highlightedElement.onHighlighted();
|
127 |
-
}
|
128 |
-
|
129 |
/**
|
130 |
* Refreshes the overlay i.e. sets the size according to current window size
|
131 |
* And moves the highlight around if necessary
|
132 |
-
*
|
133 |
-
* @param {boolean} animate
|
134 |
*/
|
135 |
-
refresh(
|
136 |
// If the highlighted element was there Cancel the
|
137 |
// existing animation frame if any and highlight it again
|
138 |
// as its position might have been changed
|
139 |
if (this.highlightedElement) {
|
140 |
-
this.highlight(this.highlightedElement
|
141 |
this.highlightedElement.onHighlighted();
|
142 |
}
|
143 |
}
|
|
|
1 |
import Position from './position';
|
2 |
+
import { ANIMATION_DURATION_MS, ID_OVERLAY, OVERLAY_HTML } from '../common/constants';
|
3 |
import { createNodeFromString } from '../common/utils';
|
4 |
|
5 |
/**
|
|
|
19 |
this.positionToHighlight = new Position({}); // position at which layover is to be patched at
|
20 |
this.highlightedElement = null; // currently highlighted dom element (instance of Element)
|
21 |
this.lastHighlightedElement = null; // element that was highlighted before current one
|
22 |
+
this.hideTimer = null;
|
|
|
23 |
|
24 |
this.window = window;
|
25 |
this.document = document;
|
|
|
52 |
return;
|
53 |
}
|
54 |
|
55 |
+
// There might be hide timer from last time
|
56 |
+
// which might be getting triggered
|
57 |
+
this.window.clearTimeout(this.hideTimer);
|
58 |
+
|
59 |
// Trigger the hook for highlight started
|
60 |
element.onHighlightStarted();
|
61 |
|
|
|
74 |
this.highlightedElement = element;
|
75 |
this.positionToHighlight = position;
|
76 |
|
77 |
+
this.showOverlay();
|
78 |
+
|
79 |
+
// Show the stage
|
80 |
+
this.stage.show(this.positionToHighlight);
|
81 |
+
|
82 |
+
// Element has been highlighted
|
83 |
+
this.highlightedElement.onHighlighted();
|
84 |
+
}
|
85 |
+
|
86 |
+
showOverlay() {
|
87 |
+
this.node.style.opacity = `${this.options.opacity}`;
|
88 |
+
this.node.style.position = 'fixed';
|
89 |
+
this.node.style.left = '0';
|
90 |
+
this.node.style.top = '0';
|
91 |
+
this.node.style.bottom = '0';
|
92 |
+
this.node.style.right = '0';
|
93 |
+
}
|
94 |
+
|
95 |
+
hideOverlay() {
|
96 |
+
this.node.style.opacity = '0';
|
97 |
+
|
98 |
+
this.hideTimer = window.setTimeout(() => {
|
99 |
+
this.node.style.position = 'absolute';
|
100 |
+
this.node.style.left = '';
|
101 |
+
this.node.style.top = '';
|
102 |
+
this.node.style.bottom = '';
|
103 |
+
this.node.style.right = '';
|
104 |
+
}, ANIMATION_DURATION_MS);
|
105 |
}
|
106 |
|
107 |
/**
|
|
|
132 |
this.highlightedElement = null;
|
133 |
this.lastHighlightedElement = null;
|
134 |
|
135 |
+
this.hideOverlay();
|
136 |
this.stage.hide();
|
137 |
}
|
138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
/**
|
140 |
* Refreshes the overlay i.e. sets the size according to current window size
|
141 |
* And moves the highlight around if necessary
|
|
|
|
|
142 |
*/
|
143 |
+
refresh() {
|
144 |
// If the highlighted element was there Cancel the
|
145 |
// existing animation frame if any and highlight it again
|
146 |
// as its position might have been changed
|
147 |
if (this.highlightedElement) {
|
148 |
+
this.highlight(this.highlightedElement);
|
149 |
this.highlightedElement.onHighlighted();
|
150 |
}
|
151 |
}
|
src/driver.scss
CHANGED
@@ -108,15 +108,9 @@ div#driver-popover-item {
|
|
108 |
}
|
109 |
|
110 |
div#driver-page-overlay {
|
111 |
-
display: block;
|
112 |
-
width: 100%;
|
113 |
-
height: 100%;
|
114 |
background: black;
|
115 |
-
|
116 |
-
left: 0;
|
117 |
-
position: fixed;
|
118 |
opacity: 0;
|
119 |
-
pointer-events: none;
|
120 |
z-index: 100002 !important;
|
121 |
|
122 |
// If you update this duration, make sure to update `ANIMATION_DURATION_MS` constant
|
|
|
108 |
}
|
109 |
|
110 |
div#driver-page-overlay {
|
|
|
|
|
|
|
111 |
background: black;
|
112 |
+
position: absolute;
|
|
|
|
|
113 |
opacity: 0;
|
|
|
114 |
z-index: 100002 !important;
|
115 |
|
116 |
// If you update this duration, make sure to update `ANIMATION_DURATION_MS` constant
|