File size: 31,683 Bytes
aa3b624 70d8f15 aa3b624 70d8f15 aa3b624 70d8f15 aa3b624 70d8f15 edd7dca 70d8f15 86da344 b0d2931 86da344 70d8f15 86da344 70d8f15 86da344 70d8f15 aa3b624 8480986 70d8f15 8480986 70d8f15 8480986 aa3b624 70d8f15 8480986 70d8f15 aa3b624 70d8f15 aa3b624 70d8f15 aa3b624 70d8f15 aa3b624 70d8f15 aa3b624 8ff0f16 70d8f15 8ff0f16 70d8f15 8ff0f16 8480986 70d8f15 8480986 82a88c5 70d8f15 82a88c5 70d8f15 9a49612 70d8f15 a688e23 847733d 9a49612 93af367 9a49612 fe7906f 9a49612 fe7906f 93af367 6aa2828 b0d2931 9a49612 fe7906f 93af367 28ba7df 9a49612 b0d2931 28ba7df ec183be 70d8f15 6aa2828 e9a1e79 ec183be 6aa2828 70d8f15 847733d 70d8f15 8480986 70d8f15 e9a1e79 ec183be 6aa2828 e9a1e79 6aa2828 fe7906f 9a49612 fe7906f 9a49612 fe7906f 9a49612 fe7906f 9a49612 93af367 d0e0b03 28ba7df 6aa2828 28ba7df 6aa2828 28ba7df 6aa2828 28ba7df ec183be b0d2931 6aa2828 b0d2931 6aa2828 b0d2931 d0e0b03 93af367 70d8f15 66a740c 70d8f15 a688e23 70d8f15 d656141 70d8f15 d656141 70d8f15 edd7dca 70d8f15 847733d 28ba7df 847733d 6aa2828 28ba7df 847733d 6aa2828 28ba7df 847733d 6aa2828 28ba7df 847733d e0443d1 6aa2828 28ba7df 847733d 7fbff02 847733d 9a49612 847733d 9a49612 847733d 70d8f15 e0443d1 215369d eb375ea 70d8f15 fe7906f 70d8f15 66a740c 70d8f15 aa3b624 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans",
"Helvetica Neue", sans-serif;
font-size: 14px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.driver-popover.custom-driver-popover {
min-width: 450px;
background: #2d2d2d;
color: white;
}
.driver-popover.custom-driver-popover .driver-popover-title {
font-size: 26px;
}
.driver-popover.custom-driver-popover .driver-popover-description {
font-size: 14px;
}
.driver-popover.custom-driver-popover button {
background: #454545;
border-color: #454545;
text-shadow: none;
color: white;
font-size: 13px;
padding: 7px 10px;
}
.driver-popover.custom-driver-popover button:hover {
background: #575757;
}
.gif-popover {
display: flex;
flex-direction: column;
text-align: center;
}
.gif-popover img {
width: 100%;
height: auto;
margin-bottom: 10px;
}
.gif-popover p {
font-weight: 500;
margin-bottom: 0;
}
p {
line-height: 1.5;
margin-bottom: 15px;
}
.page-header {
text-align: center;
margin-bottom: 10px;
}
.container {
display: flex;
flex-direction: column;
max-width: 500px;
margin: 0 auto;
text-align: left;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin: 30px 0 10px;
}
h1 {
font-size: 48px;
font-weight: 600;
text-align: center;
}
h1 sup {
font-size: 18px;
font-weight: 400;
}
ul {
list-style: none;
padding: 0;
margin: 20px 10px 0;
line-height: 1.5;
}
ul li:before {
content: "•";
margin-right: 10px;
}
.buttons {
display: flex;
gap: 10px;
max-width: 500px;
flex-wrap: wrap;
}
button {
all: unset;
border: 1px solid #ccc;
padding: 5px 15px;
border-radius: 5px;
display: block;
cursor: pointer;
}
pre {
margin-bottom: 20px;
border: 1px solid #ccc;
background: whitesmoke;
border-radius: 5px;
padding: 10px;
line-height: 1.75;
}
#scrollable-area {
height: 300px;
overflow: auto;
border: 1px solid #ccc;
padding: 10px;
border-radius: 5px;
margin: 50px 0;
}
</style>
</head>
<body>
<div class="container">
<div class="page-header">
<h1>driver.js <sup>next</sup></h1>
<p>Rewritten and enhanced version of driver.js</p>
</div>
<h2>Highlight Feature</h2>
<p>given below are the examples of simple `highlight`</p>
<div class="buttons">
<button id="highlight-btn">Animated Highlight</button>
<button id="simple-highlight-btn">Simple Highlight</button>
<button id="transition-highlight-btn">Transition Highlight</button>
<button id="disallow-close">Disallow Close</button>
<button id="dark-highlight-btn">Super Dark Highlight</button>
<button id="dim-highlight-btn">Super Dim Highlight</button>
<button id="scrollable-area-btn">Scrollable Area</button>
<button id="inner-scroll-area-btn">Inner Scroll Area</button>
<button id="without-element-btn">No Element</button>
<button id="is-active-btn">Is Active?</button>
<button id="activate-check-btn">Activate and Check</button>
<button id="backdrop-color-btn">Backdrop Color</button>
<button id="hooks">Hooks</button>
<button id="destroy-btn" style="border-color: red; background: red; color: white">Destroy</button>
</div>
<br />
<p>given below are the examples of simple `highlight`</p>
<div class="buttons">
<button id="no-buttons">No Buttons</button>
<button id="buttons-from-popover">Selected Buttons</button>
<button id="next-button">Next Button</button>
<button id="previous-button">Previous Buttons</button>
<button id="next-prev-button">Next Previous Buttons</button>
<button id="close-button">Close Buttons</button>
<button id="button-texts">Button Texts</button>
<button id="disabled-buttons">Disabled Buttons</button>
<button id="button-config-events">Button Listeners</button>
</div>
<br />
<p>You can modify the popover as well with custom CSS and JS.</p>
<div class="buttons">
<button id="custom-classes">Custom Classes</button>
<button id="popover-hook">Popover Hook</button>
<button id="padding-change">Padding Change</button>
</div>
<h2>Tour Feature</h2>
<p>Examples below show the tour usage of driver.js.</p>
<div class="buttons">
<button id="basic-tour">Animated Tour</button>
<button id="non-animated-tour">Non-Animated Tour</button>
<button id="async-tour">Asynchronous Tour</button>
</div>
<ul>
<li>Written in TypeScript</li>
<li>Lightweight — only 5kb gzipped</li>
<li>No dependencies</li>
<li>MIT Licensed</li>
</ul>
<ul id="hooks-list">
<li><strong>Hooks Button Demo — </strong>List of hooks fired</li>
</ul>
<h2>Yet another Tour Library?</h2>
<p>
No, it is not. Tours are just one of the many use-cases. Driver.js can be used wherever you need some sort of
overlay for the page; some common usecases could be: e.g. dimming the background when user is interacting with
some component, using it as a focus shifter to bring user's attention to some component on page, or using it to
simulate those "Turn off the Lights" widgets that you might have seen on video players online, etc.
</p>
<p class="second-para">
Driver.js is written in Vanilla JS, has zero dependencies and is highly customizable. It has several options
allowing you to manipulate how it behaves and also provides you the hooks to manipulate the elements as they are
highlighted, about to be highlighted, or deselected.
</p>
<h2 id="installation-head">Installation</h2>
<p>You can install it using yarn or npm, whatever you prefer.</p>
<pre>
yarn add driver.js
npm install driver.js</pre
>
<p>Or include it using CDN — put the version as [email protected] in the name</p>
<pre>https://unpkg.com/driver.js/dist/driver.min.js</pre>
<h2>Usage and Demo</h2>
<p id="large-paragraph-text">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi blanditiis consectetur ea eligendi id in
inventore ipsa iure laudantium libero, minus molestias necessitatibus nesciunt non omnis, quasi recusandae
tempore voluptates! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi blanditiis consectetur ea
eligendi id in inventore ipsa iure laudantium libero, minus molestias necessitatibus nesciunt non omnis, quasi
recusandae tempore voluptates!
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi blanditiis consectetur ea eligendi id in
inventore ipsa iure laudantium libero, minus molestias necessitatibus nesciunt non omnis, quasi recusandae
tempore voluptates!
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi blanditiis consectetur ea eligendi id in
inventore ipsa iure laudantium libero, minus molestias necessitatibus nesciunt non omnis, quasi recusandae
tempore voluptates!
</p>
<div id="scrollable-area">
<p>
First -> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur dicta ipsum labore quod
tempora ullam? Alias consequatur doloremque laborum maxime necessitatibus nostrum odio, officiis quibusdam
veniam! Doloribus eos id quaerat.
</p>
<p>
Second -> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur dicta ipsum labore quod
tempora ullam? Alias consequatur doloremque laborum maxime necessitatibus nostrum odio, officiis quibusdam
veniam! Doloribus eos id quaerat.
</p>
<p id="third-scroll-paragraph">
Third -> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur dicta ipsum labore quod
tempora ullam? Alias consequatur doloremque laborum maxime necessitatibus nostrum odio, officiis quibusdam
veniam! Doloribus eos id quaerat.
</p>
<p>
Fourth -> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur dicta ipsum labore quod
tempora ullam? Alias consequatur doloremque laborum maxime necessitatibus nostrum odio, officiis quibusdam
veniam! Doloribus eos id quaerat.
</p>
<p>
Fifth -> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur dicta ipsum labore quod
tempora ullam? Alias consequatur doloremque laborum maxime necessitatibus nostrum odio, officiis quibusdam
veniam! Doloribus eos id quaerat.
</p>
<p>
Sixth -> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur dicta ipsum labore quod
tempora ullam? Alias consequatur doloremque laborum maxime necessitatibus nostrum odio, officiis quibusdam
veniam! Doloribus eos id quaerat.
</p>
<p>
Seventh -> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur dicta ipsum labore quod
tempora ullam? Alias consequatur doloremque laborum maxime necessitatibus nostrum odio, officiis quibusdam
veniam! Doloribus eos id quaerat.
</p>
<p>
Eighth -> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur dicta ipsum labore quod
tempora ullam? Alias consequatur doloremque laborum maxime necessitatibus nostrum odio, officiis quibusdam
veniam! Doloribus eos id quaerat.
</p>
<p>
Ninth -> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur dicta ipsum labore quod
tempora ullam? Alias consequatur doloremque laborum maxime necessitatibus nostrum odio, officiis quibusdam
veniam! Doloribus eos id quaerat.
</p>
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi blanditiis consectetur ea eligendi id in
inventore ipsa iure laudantium libero, minus molestias necessitatibus nesciunt non omnis, quasi recusandae
tempore voluptates!
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi blanditiis consectetur ea eligendi id in
inventore ipsa iure laudantium libero, minus molestias necessitatibus nesciunt non omnis, quasi recusandae
tempore voluptates!
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi blanditiis consectetur ea eligendi id in
inventore ipsa iure laudantium libero, minus molestias necessitatibus nesciunt non omnis, quasi recusandae
tempore voluptates!
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi blanditiis consectetur ea eligendi id in
inventore ipsa iure laudantium libero, minus molestias necessitatibus nesciunt non omnis, quasi recusandae
tempore voluptates!
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi blanditiis consectetur ea eligendi id in
inventore ipsa iure laudantium libero, minus molestias necessitatibus nesciunt non omnis, quasi recusandae
tempore voluptates!
</p>
</div>
<script type="module">
import { driver } from "./src/driver.ts";
const basicTourSteps = [
{
element: ".page-header",
popover: {
title: "New and Improved Driver.js",
description:
"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.",
side: "bottom",
align: "start",
},
},
{
element: ".page-header h1",
popover: {
title: "No Stacking Issues",
description:
"Unlike the older version, new version doesn't work with z-indexes so no more positional issues.",
side: "left",
align: "start",
},
},
{
element: ".page-header sup",
popover: {
title: "Improved Hooks",
description:
"Unlike the older version, new version doesn't work with z-indexes so no more positional issues.",
side: "bottom",
align: "start",
},
},
{
popover: {
title: "No Element",
description: "You can now have popovers without elements as well",
},
},
{
element: "#scrollable-area",
popover: {
title: "Scrollable Areas",
description: "There are no issues with scrollable element tours as well.",
},
},
{
element: "#third-scroll-paragraph",
popover: {
title: "Nested Scrolls",
description: "Even the nested scrollable elements work now.",
},
},
];
document.getElementById("non-animated-tour").addEventListener("click", () => {
const driverObj = driver({
animate: false,
backdropColor: "blue",
opacity: 0.3,
steps: basicTourSteps,
});
driverObj.drive();
});
document.getElementById("async-tour").addEventListener("click", () => {
const driverObj = driver({
animate: true,
backdropColor: "blue",
opacity: 0.3,
onDeselected: (element => {
if (element?.classList?.contains('dynamic-el')) {
element?.parentElement?.removeChild(element);
}
}),
steps: [
{
element: ".page-header",
popover: {
title: "Async Driver.js",
description:
"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.",
side: "bottom",
align: "start",
},
},
{
element: ".page-header h1",
popover: {
title: "Async Test",
description: "By overriding `onNextClick` you get control over the tour.",
side: "left",
align: "start",
onNextClick: () => {
const newDiv = document.querySelector('.dynamic-el') || document.createElement('div');
newDiv.innerHTML = 'This is a new Element';
newDiv.style.display = 'block';
newDiv.style.padding = '20px';
newDiv.style.backgroundColor = 'black';
newDiv.style.color = 'white';
newDiv.style.fontSize = '14px';
newDiv.style.position = 'fixed';
newDiv.style.top = `${Math.random() * (500 - 30) + 30}px`;
newDiv.style.left = `${Math.random() * (500 - 30) + 30}px`;
newDiv.className = 'dynamic-el';
document.body.appendChild(newDiv);
driverObj.moveNext();
}
},
},
{
element: '.dynamic-el',
popover: {
title: "Dynamic Elements",
description: "This was created before we moved here"
}
},
{
element: ".page-header sup",
popover: {
title: "Improved Hooks",
description:
"Unlike the older version, new version doesn't work with z-indexes so no more positional issues.",
side: "bottom",
align: "start",
},
},
{
popover: {
title: "No Element",
description: "You can now have popovers without elements as well",
},
},
{
element: "#scrollable-area",
popover: {
title: "Scrollable Areas",
description: "There are no issues with scrollable element tours as well.",
},
},
{
element: "#third-scroll-paragraph",
popover: {
title: "Nested Scrolls",
description: "Even the nested scrollable elements work now.",
},
},
],
});
driverObj.drive();
});
document.getElementById("basic-tour").addEventListener("click", () => {
const driverObj = driver({
steps: basicTourSteps,
});
driverObj.drive();
});
document.getElementById("no-buttons").addEventListener("click", () => {
const driverObj = driver({});
driverObj.highlight({
element: "#no-buttons",
popover: {
title: "No Buttons",
description:
"No buttons are shown by default for highlight. You can pass in the option to show the buttons you want.",
},
});
});
document.getElementById("buttons-from-popover").addEventListener("click", () => {
const driverObj = driver();
driverObj.highlight({
element: "#buttons-from-popover",
popover: {
title: "No Buttons",
showButtons: ["close"],
description:
"No buttons are shown by default for highlight. You can pass in the option to show the buttons you want.",
},
});
});
document.getElementById("next-button").addEventListener("click", () => {
const driverObj = driver();
driverObj.highlight({
element: "#next-button",
popover: {
title: "Next and Close",
showButtons: ["close", "next"],
description: "This one only has next and close buttons, nothing else.",
},
});
});
document.getElementById("previous-button").addEventListener("click", () => {
const driverObj = driver();
driverObj.highlight({
element: "#previous-button",
popover: {
title: "Previous and Close",
showButtons: ["close", "previous"],
description: "This one only has previous and close buttons, nothing else.",
},
});
});
document.getElementById("next-prev-button").addEventListener("click", () => {
const driverObj = driver();
driverObj.highlight({
element: "#next-prev-button",
popover: {
title: "Next and Previous Only",
showButtons: ["next", "previous"],
description: "This one only has next and previous buttons.",
},
});
});
document.getElementById("close-button").addEventListener("click", () => {
const driverObj = driver();
driverObj.highlight({
element: "#close-button",
popover: {
title: "Close Only",
showButtons: ["close"],
description: "This one only has close button.",
},
});
});
document.getElementById("button-texts").addEventListener("click", () => {
const driverObj = driver({
prevBtnText: "<——",
nextBtnText: "——>",
closeBtnText: "X",
});
driverObj.highlight({
element: "#button-texts",
popover: {
side: "left",
title: "Button from Config",
showButtons: ["close", "next", "previous"],
closeBtnText: "xx",
nextBtnText: "==>",
prevBtnText: "<==",
description: "These buttons are configured using driver config.",
},
});
});
document.getElementById("popover-hook").addEventListener("click", () => {
const driverObj = driver({
onPopoverRendered: popover => {
popover.title.innerText = "Modified Parent";
},
});
driverObj.highlight({
element: ".page-header",
popover: {
title: "Page Title",
description: "Body of the popover",
side: "bottom",
align: "start",
onPopoverRendered: popover => {
popover.title.innerText = "Modified";
},
},
});
});
document.getElementById("padding-change").addEventListener("click", () => {
const driverObj = driver({
stagePadding: 0,
popoverOffset: 20,
stageRadius: 10
});
driverObj.highlight({
element: "#padding-change",
popover: {
title: "Page Title",
description: "Body of the popover",
side: "bottom",
align: "start",
onPopoverRendered: popover => {
popover.title.innerText = "Modified";
},
},
});
});
document.getElementById("custom-classes").addEventListener("click", () => {
const driverObj = driver({
popoverClass: "custom-driver-popover",
});
driverObj.highlight({
popover: {
popoverClass: "custom-driver-popover",
title: "Custom Classes",
description: "Popover and buttons have custom classes",
showButtons: ["close", "next", "previous"],
},
});
});
document.getElementById("disabled-buttons").addEventListener("click", () => {
const driverObj = driver();
driverObj.highlight({
element: "#disabled-buttons",
popover: {
title: "Disable Buttons",
description: "You can selectively disable buttons as well",
showButtons: ["next", "previous", "close"],
disableButtons: ["next", "previous"],
},
});
});
document.getElementById("button-config-events").addEventListener("click", () => {
const driverObj = driver({
onNextClick: () => alert("Next Clicked"),
onPrevClick: () => alert("Previous Clicked"),
onCloseClick: () => {
driverObj.destroy();
},
});
driverObj.highlight({
popover: {
title: "Global Button Listener",
description: "You can listen to the button clicks globally.",
showButtons: ["close", "next", "previous"],
onPrevClick: () => alert("Overriding — Previous Clicked"),
},
});
});
document.getElementById("is-active-btn").addEventListener("click", () => {
alert(driver().isActive());
});
document.getElementById("backdrop-color-btn").addEventListener("click", () => {
driver({
backdropColor: "blue",
opacity: 0.3,
}).highlight({
element: "#backdrop-color-btn",
});
});
document.getElementById("activate-check-btn").addEventListener("click", () => {
const driverObj = driver({
showButtons: false,
});
driverObj.highlight({
element: "#activate-check-btn",
popover: {
title: "Check if driver is active",
description: "This will alert the status after 2 seconds",
side: "bottom",
align: "start",
},
});
setTimeout(() => {
alert(`Status: ${driverObj.isActive()}. Destroying driver...`);
driverObj.destroy();
setTimeout(() => {
alert(`Status: ${driverObj.isActive()}`);
}, 0);
}, 2000);
});
document.getElementById("highlight-btn").addEventListener("click", () => {
driver({
animate: true,
popoverOffset: 10,
stagePadding: 10,
onDeselected: (element, step) => {
console.log("Deselected element", element, step);
},
onHighlightStarted: (element, step) => {
console.log("Started highlighting element", element, step);
},
onHighlighted: (element, step) => {
console.log("Highlighted element", element, step);
},
}).highlight({
element: "h2",
popover: {
title: "MIT License",
description: "A lightweight, no-dependency JavaScript engine to drive user's focus.",
side: "bottom",
align: "start",
},
});
});
document.getElementById("simple-highlight-btn").addEventListener("click", () => {
driver({ animate: false }).highlight({
element: "#large-paragraph-text",
popover: {
title: "driver.js",
description:
"Highlight anything, anywhere on the page. Yes, literally anything including SVG portions, scrollable items etc.",
align: "start",
side: "top",
},
});
});
document.getElementById("dark-highlight-btn").addEventListener("click", () => {
driver({
animate: true,
opacity: 0.9,
}).highlight({ element: "ul" });
});
document.getElementById("dim-highlight-btn").addEventListener("click", () => {
driver({
animate: true,
opacity: 0.2,
}).highlight({ element: ".buttons" });
});
document.getElementById("transition-highlight-btn").addEventListener("click", () => {
const driverObj = driver({
animate: true,
onDeselected: (element, step) => {
console.log("Deselected element", element, step);
},
onHighlightStarted: (element, step) => {
console.log("Started highlighting element", element, step);
},
onHighlighted: (element, step) => {
console.log("Highlighted element", element, step);
},
});
driverObj.highlight({
popover: {
title: "driver.js",
description: "Highlight anything, anywhere on the page",
},
});
window.setTimeout(() => {
driverObj.highlight({
element: ".buttons button:first-child",
popover: {
title: "driver.js",
description: "Highlight anything, anywhere on the page",
},
});
}, 2000);
window.setTimeout(() => {
driverObj.highlight({
popover: {
title: "driver.js",
description: "Highlight anything, anywhere on the page",
},
});
}, 4000);
window.setTimeout(() => {
driverObj.highlight({
element: "h2",
popover: {
description: "driver.js",
},
});
}, 6000);
});
document.getElementById("hooks").addEventListener("click", () => {
const pageHeader = document.getElementById(".page-header");
const driverObj = driver({
animate: true,
onDeselected: (element, step) => {
const elementText = element?.textContent?.slice(0, 10) || " - N/A -";
console.log(`Deselected: ${elementText}\n${JSON.stringify(step)}`);
},
onHighlightStarted: (element, step) => {
const elementText = element?.textContent?.slice(0, 10) || " - N/A -";
console.log(`Highlight Started: ${elementText}\n${JSON.stringify(step)}`);
},
onHighlighted: (element, step) => {
const elementText = element?.textContent?.slice(0, 10) || " - N/A -";
console.log(`Highlighted: ${elementText}\n${JSON.stringify(step)}`);
},
onDestroyed: (element, step) => {
const elementText = element?.textContent?.slice(0, 10) || " - N/A -";
console.log(`Destroyed: ${elementText}\n${JSON.stringify(step)}`);
},
});
driverObj.highlight({
element: "#hooks",
popover: {
title: "Hooks",
description: "Here are all the hooks",
},
});
window.setTimeout(() => {
driverObj.highlight({
popover: {
title: "Popup Hook",
description: "There is no element below this popover",
},
});
}, 1000);
window.setTimeout(() => {
driverObj.highlight({
element: "#hooks-list",
popover: {
description: "Here are all the hooks",
},
});
}, 2000);
});
document.getElementById("scrollable-area-btn").addEventListener("click", () => {
const driverObj = driver({ animate: true });
driverObj.highlight({ element: "#scrollable-area" });
});
document.getElementById("without-element-btn").addEventListener("click", () => {
const driverObj = driver({
animate: true,
onDestroyed: (element, step) => {
console.log("Close modal", element, step);
},
onDeselected: (element, step) => {
console.log("Deselected element", element, step);
},
onHighlightStarted: (element, step) => {
console.log("Started highlighting element", element, step);
},
onHighlighted: (element, step) => {
console.log("Highlighted element", element, step);
},
});
driverObj.highlight({
popover: {
showButtons: [],
description:
"<div class='gif-popover'><img style='max-width: 100%' src='https://i.imgur.com/EAQhHu5.gif' /><p>Go and build something cool!</p></div>",
},
});
});
document.getElementById("inner-scroll-area-btn").addEventListener("click", () => {
const driverObj = driver({ animate: true });
driverObj.highlight({ element: "#third-scroll-paragraph" });
});
document.getElementById("disallow-close").addEventListener("click", () => {
const driverObj = driver({
animate: true,
allowClose: false,
});
driverObj.highlight({
element: ".buttons",
});
});
document.getElementById("destroy-btn").addEventListener("click", () => {
driver().destroy();
});
</script>
</body>
</html>
|