Better highlighting/highlighted hooks
Browse files- index.html +9 -0
- src/config.ts +3 -3
- src/driver.ts +1 -1
- src/highlight.ts +6 -6
index.html
CHANGED
|
@@ -419,6 +419,15 @@ npm install driver.js</pre
|
|
| 419 |
document.getElementById("without-element-btn").addEventListener("click", () => {
|
| 420 |
const driverObj = driver({
|
| 421 |
animate: true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
});
|
| 423 |
driverObj.highlight({
|
| 424 |
popover: {
|
|
|
|
| 419 |
document.getElementById("without-element-btn").addEventListener("click", () => {
|
| 420 |
const driverObj = driver({
|
| 421 |
animate: true,
|
| 422 |
+
onDeselected: (element, step) => {
|
| 423 |
+
console.log("Deselected element", element, step);
|
| 424 |
+
},
|
| 425 |
+
onHighlightStarted: (element, step) => {
|
| 426 |
+
console.log("Started highlighting element", element, step);
|
| 427 |
+
},
|
| 428 |
+
onHighlighted: (element, step) => {
|
| 429 |
+
console.log("Highlighted element", element, step);
|
| 430 |
+
},
|
| 431 |
});
|
| 432 |
driverObj.highlight({
|
| 433 |
popover: {
|
src/config.ts
CHANGED
|
@@ -11,10 +11,10 @@ export type Config = {
|
|
| 11 |
popoverOffset?: number;
|
| 12 |
showButtons?: boolean;
|
| 13 |
|
| 14 |
-
onHighlightStarted?: (element: Element, step: DriveStep) => void;
|
| 15 |
-
onHighlighted?: (element: Element, step: DriveStep) => void;
|
| 16 |
|
| 17 |
-
onDeselected?: (element: Element, step: DriveStep) => void;
|
| 18 |
};
|
| 19 |
|
| 20 |
let currentConfig: Config = {};
|
|
|
|
| 11 |
popoverOffset?: number;
|
| 12 |
showButtons?: boolean;
|
| 13 |
|
| 14 |
+
onHighlightStarted?: (element: Element | undefined, step: DriveStep) => void;
|
| 15 |
+
onHighlighted?: (element: Element | undefined, step: DriveStep) => void;
|
| 16 |
|
| 17 |
+
onDeselected?: (element: Element | undefined, step: DriveStep) => void;
|
| 18 |
};
|
| 19 |
|
| 20 |
let currentConfig: Config = {};
|
src/driver.ts
CHANGED
|
@@ -25,7 +25,7 @@ export function driver(options: Config = {}) {
|
|
| 25 |
const activeElement = getState("activeElement");
|
| 26 |
const onDeselected = getConfig("onDeselected");
|
| 27 |
if (activeStep && activeElement && onDeselected) {
|
| 28 |
-
onDeselected(activeElement, activeStep);
|
| 29 |
}
|
| 30 |
|
| 31 |
destroy();
|
|
|
|
| 25 |
const activeElement = getState("activeElement");
|
| 26 |
const onDeselected = getConfig("onDeselected");
|
| 27 |
if (activeStep && activeElement && onDeselected) {
|
| 28 |
+
onDeselected(activeElement.id === "driver-dummy-element" ? undefined : activeElement, activeStep);
|
| 29 |
}
|
| 30 |
|
| 31 |
destroy();
|
src/highlight.ts
CHANGED
|
@@ -74,12 +74,12 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
|
|
| 74 |
const highlightedHook = getConfig("onHighlighted");
|
| 75 |
const deselectedHook = getConfig("onDeselected");
|
| 76 |
|
| 77 |
-
if (!isFirstHighlight &&
|
| 78 |
-
deselectedHook(fromElement, fromStep!);
|
| 79 |
}
|
| 80 |
|
| 81 |
-
if (
|
| 82 |
-
highlightStartedHook(toElement, toStep);
|
| 83 |
}
|
| 84 |
|
| 85 |
const hasDelayedPopover = !isFirstHighlight && (hasNoPreviousPopover || isFromDummyElement || isToDummyElement);
|
|
@@ -111,8 +111,8 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
|
|
| 111 |
} else {
|
| 112 |
trackActiveElement(toElement);
|
| 113 |
|
| 114 |
-
if (
|
| 115 |
-
highlightedHook(toElement, toStep);
|
| 116 |
}
|
| 117 |
|
| 118 |
setState("transitionCallback", undefined);
|
|
|
|
| 74 |
const highlightedHook = getConfig("onHighlighted");
|
| 75 |
const deselectedHook = getConfig("onDeselected");
|
| 76 |
|
| 77 |
+
if (!isFirstHighlight && deselectedHook) {
|
| 78 |
+
deselectedHook(isFromDummyElement ? undefined : fromElement, fromStep!);
|
| 79 |
}
|
| 80 |
|
| 81 |
+
if (highlightStartedHook) {
|
| 82 |
+
highlightStartedHook(isToDummyElement ? undefined : toElement, toStep);
|
| 83 |
}
|
| 84 |
|
| 85 |
const hasDelayedPopover = !isFirstHighlight && (hasNoPreviousPopover || isFromDummyElement || isToDummyElement);
|
|
|
|
| 111 |
} else {
|
| 112 |
trackActiveElement(toElement);
|
| 113 |
|
| 114 |
+
if (highlightedHook) {
|
| 115 |
+
highlightedHook(isToDummyElement ? undefined : toElement, toStep);
|
| 116 |
}
|
| 117 |
|
| 118 |
setState("transitionCallback", undefined);
|