kamrify commited on
Commit
3ba4d39
·
1 Parent(s): ec183be

Fix onDeselected not being called

Browse files
Files changed (4) hide show
  1. index.html +20 -23
  2. src/driver.ts +1 -1
  3. src/highlight.ts +1 -1
  4. src/popover.ts +1 -0
index.html CHANGED
@@ -401,20 +401,14 @@ npm install driver.js</pre
401
  document.getElementById("async-tour").addEventListener("click", () => {
402
  const driverObj = driver({
403
  animate: true,
404
- backdropColor: "blue",
405
  opacity: 0.3,
406
- onDeselected: (element => {
407
- if (element?.classList?.contains('dynamic-el')) {
408
- element?.parentElement?.removeChild(element);
409
- }
410
- }),
411
  steps: [
412
  {
413
  element: ".page-header",
414
  popover: {
415
  title: "Async Driver.js",
416
  description:
417
- "Driver.js has been written from the ground up. The new version is more powerful, has less surprises, more customizable and tons of new features.",
418
  side: "bottom",
419
  align: "start",
420
  },
@@ -427,38 +421,41 @@ npm install driver.js</pre
427
  side: "left",
428
  align: "start",
429
  onNextClick: () => {
430
- const newDiv = document.querySelector('.dynamic-el') || document.createElement('div');
431
-
432
- newDiv.innerHTML = 'This is a new Element';
433
- newDiv.style.display = 'block';
434
- newDiv.style.padding = '20px';
435
- newDiv.style.backgroundColor = 'black';
436
- newDiv.style.color = 'white';
437
- newDiv.style.fontSize = '14px';
438
- newDiv.style.position = 'fixed';
439
  newDiv.style.top = `${Math.random() * (500 - 30) + 30}px`;
440
  newDiv.style.left = `${Math.random() * (500 - 30) + 30}px`;
441
- newDiv.className = 'dynamic-el';
442
 
443
  document.body.appendChild(newDiv);
444
 
445
  driverObj.moveNext();
446
- }
447
  },
448
  },
449
  {
450
- element: '.dynamic-el',
451
  popover: {
452
  title: "Dynamic Elements",
453
- description: "This was created before we moved here"
454
- }
 
 
 
455
  },
456
  {
457
  element: ".page-header sup",
458
  popover: {
459
  title: "Improved Hooks",
460
  description:
461
- "Unlike the older version, new version doesn't work with z-indexes so no more positional issues.",
462
  side: "bottom",
463
  align: "start",
464
  },
@@ -621,7 +618,7 @@ npm install driver.js</pre
621
  const driverObj = driver({
622
  stagePadding: 0,
623
  popoverOffset: 20,
624
- stageRadius: 10
625
  });
626
 
627
  driverObj.highlight({
 
401
  document.getElementById("async-tour").addEventListener("click", () => {
402
  const driverObj = driver({
403
  animate: true,
 
404
  opacity: 0.3,
 
 
 
 
 
405
  steps: [
406
  {
407
  element: ".page-header",
408
  popover: {
409
  title: "Async Driver.js",
410
  description:
411
+ "Driver.js has been written from the ground up. The new version is more powerful, has less surprises, more customizable and tons of new features.",
412
  side: "bottom",
413
  align: "start",
414
  },
 
421
  side: "left",
422
  align: "start",
423
  onNextClick: () => {
424
+ const newDiv = document.querySelector(".dynamic-el") || document.createElement("div");
425
+
426
+ newDiv.innerHTML = "This is a new Element";
427
+ newDiv.style.display = "block";
428
+ newDiv.style.padding = "20px";
429
+ newDiv.style.backgroundColor = "black";
430
+ newDiv.style.color = "white";
431
+ newDiv.style.fontSize = "14px";
432
+ newDiv.style.position = "fixed";
433
  newDiv.style.top = `${Math.random() * (500 - 30) + 30}px`;
434
  newDiv.style.left = `${Math.random() * (500 - 30) + 30}px`;
435
+ newDiv.className = "dynamic-el";
436
 
437
  document.body.appendChild(newDiv);
438
 
439
  driverObj.moveNext();
440
+ },
441
  },
442
  },
443
  {
444
+ element: ".dynamic-el",
445
  popover: {
446
  title: "Dynamic Elements",
447
+ description: "This was created before we moved here",
448
+ onDeselected: element => {
449
+ element?.parentElement?.removeChild(element);
450
+ },
451
+ },
452
  },
453
  {
454
  element: ".page-header sup",
455
  popover: {
456
  title: "Improved Hooks",
457
  description:
458
+ "Unlike the older version, new version doesn't work with z-indexes so no more positional issues.",
459
  side: "bottom",
460
  align: "start",
461
  },
 
618
  const driverObj = driver({
619
  stagePadding: 0,
620
  popoverOffset: 20,
621
+ stageRadius: 10,
622
  });
623
 
624
  driverObj.highlight({
src/driver.ts CHANGED
@@ -149,7 +149,7 @@ export function driver(options: Config = {}) {
149
  const activeElement = getState("activeElement");
150
  const activeStep = getState("activeStep");
151
 
152
- const onDeselected = getConfig("onDeselected");
153
  const onDestroyed = getConfig("onDestroyed");
154
 
155
  document.body.classList.remove("driver-active", "driver-fade", "driver-simple");
 
149
  const activeElement = getState("activeElement");
150
  const activeStep = getState("activeStep");
151
 
152
+ const onDeselected = activeStep?.popover?.onDeselected || getConfig("onDeselected");
153
  const onDestroyed = getConfig("onDestroyed");
154
 
155
  document.body.classList.remove("driver-active", "driver-fade", "driver-simple");
src/highlight.ts CHANGED
@@ -72,7 +72,7 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
72
  const isAnimatedTour = getConfig("animate");
73
  const highlightStartedHook = getConfig("onHighlightStarted");
74
  const highlightedHook = getConfig("onHighlighted");
75
- const deselectedHook = getConfig("onDeselected");
76
 
77
  if (!isFirstHighlight && deselectedHook) {
78
  deselectedHook(isFromDummyElement ? undefined : fromElement, fromStep!);
 
72
  const isAnimatedTour = getConfig("animate");
73
  const highlightStartedHook = getConfig("onHighlightStarted");
74
  const highlightedHook = getConfig("onHighlighted");
75
+ const deselectedHook = fromStep?.popover?.onDeselected || getConfig("onDeselected");
76
 
77
  if (!isFirstHighlight && deselectedHook) {
78
  deselectedHook(isFromDummyElement ? undefined : fromElement, fromStep!);
src/popover.ts CHANGED
@@ -28,6 +28,7 @@ export type Popover = {
28
 
29
  // Called after the popover is rendered
30
  onPopoverRendered?: (popover: PopoverDOM) => void;
 
31
 
32
  // Button callbacks
33
  onNextClick?: (element: Element | undefined, step: DriveStep) => void;
 
28
 
29
  // Called after the popover is rendered
30
  onPopoverRendered?: (popover: PopoverDOM) => void;
31
+ onDeselected?: (element: Element | undefined, step: DriveStep) => void;
32
 
33
  // Button callbacks
34
  onNextClick?: (element: Element | undefined, step: DriveStep) => void;