0.0.4 • Published 4 years ago

tourguide v0.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

TourGuide

Build Status npm npm

About

TourGuide is a JavaScript module that helps generate step-by-step instructions and demos in an easy way. It spotlights elements adding small commentary on them. See a demo working on CodePen.

It uses borders and box-shadows to create a spotlight area that will highlight a specific element, displaying commentary text, and animating from one step to another using CSS transitions. It is highly customizable, works on desktop and mobile, and users can opt to use the default controls or create their own using the plugin API.

Initially, it was a CSS-only animation for a Snake & Ladders game. Then it was ported into JavaScript and this module was created.

How to use it

This is a simple 4-step way to start TourGuide:

  1. Download an import the JS library and CSS file into your project. You can do this by:

    1. Downloading/importing the files directly into your project:

    2. Installing the package from npm

      npm i tourguide

    3. Adding the package from yarn

      yarn add tourguide

  2. Add data-sp-next data-attribute to the elements that you want to highlight as part of your instructions.

    There are more data-attributes that can be added, but only the data-sp-next is essential to create the list of steps for the instructions.

  3. Initialize TourGuide with the selector of the initial element of the instructions:

      <script>
      let tour = new TourGuide({
        init: "#step1"
      });
      </script>
  4. With JavaScript, trigger the beginning of the instructions/demo using the start method:

    tour.start();

For more examples on how to start, check the repository demos.

Parameters

ParameterTypeDescription
colorColorString with the color of the shadow. Default: "rgba(0, 0, 0, 0.5)".
initStringSelector of the first element that will be highlighted, and from which the list of steps will be created. This field has no default value. Either this parameter of steps must be specified when starting TourGuide.
initTriggerBooleanIndicates if the first element will also be the trigger of the animation. Default: false.
nextBooleanIndicates if the link to the next step will be displayed. Default: true
nextTextStringSpecifies the text of the next step link. Admits HTML. Default: "Next"
previousBooleanIndicates if the link to the previous step will be displayed. Default: true
previousTextStringSpecifies the text of the previous step link. Admits HTML. Default: "Previous"
shapesquare|roundString that indicates the shape of the spotlight: squared or round/elliptical. Default value: "round".
skipBooleanIndicates if the link to skip the instructions will be displayed. Default: true
skipTextStringSpecifies the text of the link to skip instructions. Default: "Skip presentation"
stepsArrayList with objects that will contain ID, text, and shape of the element to be highlighted (see more below). This field has no default value. Either this parameter of init must be specified when starting TourGuide.

The structure of the steps list will be as follows:

[
  {
    selector: "selector-of-the-element-to-be-highglighted-(mandatory)",
    text: "text-to-be-displayed-(optional)",
    shape: "shape-of-the-element-(optional)"
  },
  ...
]

So, for example, the following ways of initializing SpolightJS would be equivalent:

Method 1:

<div id="step-1" data-sp-next="#step-2" data-sp-text="This is the first step.">Hello!</div>
<div id="step-2" data-sp-next="#step-3" data-sp-text="This is the last steop." data-sp-shape="round">Good Bye!</div>

<script>
let tourguide = new TourGuide({ init: "#step-1" });
</script>

Method 2:

<div id="step-1">Hello!</div>
<div id="step-2">Good Bye!</div>

<script>
let tourguide = new TourGuide({
                      steps:[
                              { selector: "#step-1", text: "This is the first step." },
                              { selector: "#step-2", text: "This is the last step.", shape: "round" }
                            ]
                    });
</script>

API methods

In order to customize the instructions, you could hide all the controls (next, previous, skip) and use your own using the methods from the provided API, or you could also hide the text associated to each step (via CSS) and design your own instruction text. For some examples of the possibilities, see the demos page.

MethodReturnsDescription
getCurrentElement()ObjectReturns the element that is currently highlighted.
getCurrentElementSelector()StringReturns the selector provided for the element that is currently highlighted.
getStep()IntegerReturns the integer value of the current step (from 1 to no).
getText()StringReturns the text associated to the currently highlighted step.
getTotalSteps()IntegerReturns the total number of steps in the presentation.
goToFirstStep()-Animates to the first step.
goToNextStep()-Animates to the following step in the presentation.
goToPreviousStep()-Animates to the previous step in the presentation.
goToStep(n)-Animates directly to step n.
start()-Starts the animation from the first step.
stop()-Stops the current animation.

Browser Support

Edge Logo 32x32IE/EdgeFirefox LogoFirefoxChromeChromeSafari LogoSafariOpera logoOpera
9+12+4+4+11.5+