Add ability to disable animation and perf
Browse files- demo/scripts/demo.js +1 -1
- src/common/constants.js +1 -0
- src/core/element.js +6 -2
- src/core/overlay.js +13 -3
- src/core/stage.js +8 -4
- src/driver.scss +13 -1
- src/index.js +0 -1
demo/scripts/demo.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
/* eslint-disable */
|
2 |
document.addEventListener("DOMContentLoaded", function () {
|
3 |
const tourDriver = new Driver({
|
4 |
-
animate:
|
5 |
opacity: 0.8,
|
6 |
padding: 5,
|
7 |
showButtons: true,
|
|
|
1 |
/* eslint-disable */
|
2 |
document.addEventListener("DOMContentLoaded", function () {
|
3 |
const tourDriver = new Driver({
|
4 |
+
animate: false,
|
5 |
opacity: 0.8,
|
6 |
padding: 5,
|
7 |
showButtons: true,
|
src/common/constants.js
CHANGED
@@ -12,6 +12,7 @@ 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';
|
17 |
export const CLASS_POPOVER_DESCRIPTION = 'driver-popover-description';
|
|
|
12 |
|
13 |
export const CLASS_DRIVER_HIGHLIGHTED_ELEMENT = 'driver-highlighted-element';
|
14 |
|
15 |
+
export const CLASS_NO_ANIMATION = 'sholo-no-animation';
|
16 |
export const CLASS_POPOVER_TIP = 'driver-popover-tip';
|
17 |
export const CLASS_POPOVER_TITLE = 'driver-popover-title';
|
18 |
export const CLASS_POPOVER_DESCRIPTION = 'driver-popover-description';
|
src/core/element.js
CHANGED
@@ -251,11 +251,15 @@ export default class Element {
|
|
251 |
const showAtPosition = this.getCalculatedPosition();
|
252 |
|
253 |
// For first highlight, show it immediately because there won't be any animation
|
254 |
-
|
|
|
|
|
|
|
|
|
255 |
|
256 |
this.animationTimeout = this.window.setTimeout(() => {
|
257 |
this.popover.show(showAtPosition);
|
258 |
-
},
|
259 |
}
|
260 |
|
261 |
/**
|
|
|
251 |
const showAtPosition = this.getCalculatedPosition();
|
252 |
|
253 |
// For first highlight, show it immediately because there won't be any animation
|
254 |
+
let showAfterMs = ANIMATION_DURATION_MS;
|
255 |
+
// If animation is disabled or if it is the first display, show it immediately
|
256 |
+
if (!this.options.animate || !this.overlay.lastHighlightedElement) {
|
257 |
+
showAfterMs = 0;
|
258 |
+
}
|
259 |
|
260 |
this.animationTimeout = this.window.setTimeout(() => {
|
261 |
this.popover.show(showAtPosition);
|
262 |
+
}, showAfterMs);
|
263 |
}
|
264 |
|
265 |
/**
|
src/core/overlay.js
CHANGED
@@ -1,5 +1,5 @@
|
|
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 |
/**
|
@@ -36,6 +36,12 @@ export default class Overlay {
|
|
36 |
|
37 |
this.node = pageOverlay;
|
38 |
this.node.style.opacity = '0';
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
}
|
40 |
|
41 |
/**
|
@@ -75,13 +81,17 @@ export default class Overlay {
|
|
75 |
this.highlightedElement = element;
|
76 |
this.positionToHighlight = position;
|
77 |
|
78 |
-
this.
|
79 |
|
80 |
// Element has been highlighted
|
81 |
this.highlightedElement.onHighlighted();
|
82 |
}
|
83 |
|
84 |
-
|
|
|
|
|
|
|
|
|
85 |
this.makeNode();
|
86 |
|
87 |
window.setTimeout(() => {
|
|
|
1 |
import Position from './position';
|
2 |
+
import { ANIMATION_DURATION_MS, CLASS_NO_ANIMATION, ID_OVERLAY, OVERLAY_HTML } from '../common/constants';
|
3 |
import { createNodeFromString } from '../common/utils';
|
4 |
|
5 |
/**
|
|
|
36 |
|
37 |
this.node = pageOverlay;
|
38 |
this.node.style.opacity = '0';
|
39 |
+
|
40 |
+
if (!this.options.animate) {
|
41 |
+
this.node.classList.add(CLASS_NO_ANIMATION);
|
42 |
+
} else {
|
43 |
+
this.node.classList.remove(CLASS_NO_ANIMATION);
|
44 |
+
}
|
45 |
}
|
46 |
|
47 |
/**
|
|
|
81 |
this.highlightedElement = element;
|
82 |
this.positionToHighlight = position;
|
83 |
|
84 |
+
this.show();
|
85 |
|
86 |
// Element has been highlighted
|
87 |
this.highlightedElement.onHighlighted();
|
88 |
}
|
89 |
|
90 |
+
show() {
|
91 |
+
if (this.node && this.node.parentElement) {
|
92 |
+
return;
|
93 |
+
}
|
94 |
+
|
95 |
this.makeNode();
|
96 |
|
97 |
window.setTimeout(() => {
|
src/core/stage.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import { ID_STAGE, STAGE_HTML } from '../common/constants';
|
2 |
import { createNodeFromString } from '../common/utils';
|
3 |
import Element from './element';
|
4 |
|
@@ -18,9 +18,6 @@ export default class Stage extends Element {
|
|
18 |
this.options = options;
|
19 |
this.window = window;
|
20 |
this.document = document;
|
21 |
-
|
22 |
-
this.makeNode();
|
23 |
-
this.hide();
|
24 |
}
|
25 |
|
26 |
/**
|
@@ -34,6 +31,12 @@ export default class Stage extends Element {
|
|
34 |
}
|
35 |
|
36 |
this.node = stage;
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
}
|
38 |
|
39 |
removeNode() {
|
@@ -49,6 +52,7 @@ export default class Stage extends Element {
|
|
49 |
*/
|
50 |
hide() {
|
51 |
this.node.style.display = 'none';
|
|
|
52 |
this.removeNode();
|
53 |
}
|
54 |
|
|
|
1 |
+
import { CLASS_NO_ANIMATION, ID_STAGE, STAGE_HTML } from '../common/constants';
|
2 |
import { createNodeFromString } from '../common/utils';
|
3 |
import Element from './element';
|
4 |
|
|
|
18 |
this.options = options;
|
19 |
this.window = window;
|
20 |
this.document = document;
|
|
|
|
|
|
|
21 |
}
|
22 |
|
23 |
/**
|
|
|
31 |
}
|
32 |
|
33 |
this.node = stage;
|
34 |
+
|
35 |
+
if (!this.options.animate) {
|
36 |
+
this.node.classList.add(CLASS_NO_ANIMATION);
|
37 |
+
} else {
|
38 |
+
this.node.classList.remove(CLASS_NO_ANIMATION);
|
39 |
+
}
|
40 |
}
|
41 |
|
42 |
removeNode() {
|
|
|
52 |
*/
|
53 |
hide() {
|
54 |
this.node.style.display = 'none';
|
55 |
+
|
56 |
this.removeNode();
|
57 |
}
|
58 |
|
src/driver.scss
CHANGED
@@ -107,9 +107,21 @@ div#driver-popover-item {
|
|
107 |
}
|
108 |
}
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
div#driver-page-overlay {
|
111 |
background: black;
|
112 |
-
position:
|
|
|
|
|
|
|
|
|
113 |
display: block;
|
114 |
width: 100%;
|
115 |
height: 100%;
|
|
|
107 |
}
|
108 |
}
|
109 |
|
110 |
+
.sholo-no-animation {
|
111 |
+
-webkit-transition: none !important;
|
112 |
+
-moz-transition: none !important;
|
113 |
+
-ms-transition: none !important;
|
114 |
+
-o-transition: none !important;
|
115 |
+
transition: none !important;
|
116 |
+
}
|
117 |
+
|
118 |
div#driver-page-overlay {
|
119 |
background: black;
|
120 |
+
position: fixed;
|
121 |
+
top: 0;
|
122 |
+
left: 0;
|
123 |
+
bottom: 0;
|
124 |
+
right: 0;
|
125 |
display: block;
|
126 |
width: 100%;
|
127 |
height: 100%;
|
src/index.js
CHANGED
@@ -184,7 +184,6 @@ export default class Driver {
|
|
184 |
return;
|
185 |
}
|
186 |
|
187 |
-
// Refresh with animation
|
188 |
this.overlay.refresh();
|
189 |
}
|
190 |
|
|
|
184 |
return;
|
185 |
}
|
186 |
|
|
|
187 |
this.overlay.refresh();
|
188 |
}
|
189 |
|