|
1 | 1 | # Tourguide.js
|
2 | 2 |
|
3 |
| -###### Simple, lightweight library for creating guided tours for your web, apps and more. |
| 3 | +###### Library for creating guided tours for your web, apps and more. |
4 | 4 |
|
5 |
| -> A **tour guide** is a person who provides assistance, information on cultural, historical and contemporary heritage to people on organized [tours](https://en.wikipedia.org/wiki/Tourism) and individual clients at educational establishments, religious and historical sites, museums, and at venues of other significant interest, attractions sites. [[https://en.wikipedia.org/wiki/Tour_guide](https://en.wikipedia.org/wiki/Tour_guide)] |
| 5 | +> A **tour guide** is a person who provides assistance, information on cultural, historical and contemporary heritage to people on organized [tours](https://en.wikipedia.org/wiki/Tourism) and individual clients at educational establishments, religious and historical sites, museums, and at venues of other significant interest, attractions sites. [[https://en.wikipedia.org/wiki/Tour_guide](https://en.wikipedia.org/wiki/Tour_guide)] |
6 | 6 |
|
7 | 7 | ## Examples
|
8 | 8 |
|
@@ -63,74 +63,31 @@ Before use, **Tourguide.js** must be instantiated:
|
63 | 63 | ```
|
64 | 64 | var tourguide = new Tourguide({options});
|
65 | 65 | ```
|
66 |
| - |
67 |
| -* `root?<string>`: root element the tour steps will attach to; default is document.body |
68 |
| -* `selector?<string>`: if you want to use content based tour approach you can use this option to specify the common selector for the tour steps; default is `[data-tour]` |
69 |
| -* `animationspeed?<number>`: speed of all tour built-in animations; default is 120 |
70 |
| -* `padding?<number>`: additional padding to add to step highlighter; default is 5(px) |
71 |
| -* `steps?<Array<Step>>`: if you choose to take JSON based tour approach provide use this property to provide the data; default is null |
72 |
| -* `src?<string>`: if you want to load the tour from a remote URL you may specify it here; default is null |
73 |
| -* `preloadimages?<boolean>`: if you want to preload images, you may set this attribute to true; default is false |
74 |
| -* `restoreinitialposition?<boolean>`: if you want to restore the scroll position after the tour ended, you may set this attribute to true; default is true |
75 |
| -* `colors<Object>`: if you want to customize the color schema of this plugin, use the following properties; the object you passed in will be combine with default values. The defaults are: |
76 |
| -``` |
77 |
| -{ |
78 |
| - fontFamily: 'sans-serif', |
79 |
| - fontSize: "14px", |
80 |
| - tooltipWidth: "40vw", |
81 |
| - overlayColor: "rgba(0, 0, 0, 0.5)", |
82 |
| - textColor: "#333", |
83 |
| - accentColor: "#0d6efd", |
84 |
| - focusColor: "auto", |
85 |
| - bulletColor: "auto", |
86 |
| - bulletVisitedColor: "auto", |
87 |
| - bulletCurrentColor: "auto", |
88 |
| - stepButtonCloseColor: "auto", |
89 |
| - stepButtonPrevColor: "auto", |
90 |
| - stepButtonNextColor: "auto", |
91 |
| - stepButtonCompleteColor: "auto", |
92 |
| - backgroundColor: "#fff", |
| 66 | +Tour constructor accepts the following options: |
| 67 | +``` |
| 68 | +const defaultOptions: { |
| 69 | + root?: HTMLElement | string; // Optional, if you don't provide a selector, the tour will be initialized on `document`; |
| 70 | + selector?: string; // Required for DOM steps. The selector used to pick up HTML elements that represent your steps |
| 71 | + selectorSteps?: Array<string>; // If provided, will be used instead of a single selector. Useful if you have multiple steps on the same page |
| 72 | + contentDecorators?: Function[] // An array of functions that are responsible for decorating your step content (optional) |
| 73 | + style?: Object // A styles object applied to the container element (optional) |
| 74 | + actionHandlers?: Array<{name: string, fn: Function}> // An array of custom actions you can define on your tour (optional) |
| 75 | + request?: RequestInit | null; // An object containing various browser settings for the fetch() call if using `src` option. (default is { mode: 'cors' }) |
| 76 | + keyboardNavigation?: Object // Keyboard navigation configuration |
| 77 | + next?: string | undefined; // name of the keyboard shortcut used to navigate to the next step; the default value is 'ArrowRight' |
| 78 | + prev?: string | undefined; // name of the keyboard shortcut used to navigate to the previous step; the default value is 'ArrowLeft' |
| 79 | + first?: string | undefined; // name of the keyboard shortcut used to navigate to the first step; the default value is 'Home' |
| 80 | + last?: string | undefined; // name of the keyboard shortcut used to navigate to the last step; the default value is 'End' |
| 81 | + stop?: string | undefined; // name of the keyboard shortcut used to stop the tour; the default value is 'Escape' |
| 82 | + complete?: string | undefined; // name of the keyboard shortcut used to stop the tour |
| 83 | + stepFactory?: Array<any> // An array of classes for creating your steps. (optional) |
| 84 | + Type?: string; // Defines the type of the step to create, for example "card" |
| 85 | + Style?: string; // Defines the styles applied to the created step |
| 86 | + resumeOnLoad?: boolean; // If true, will start tour from last known position if one is saved. (default false) |
| 87 | + restoreinitialposition?: boolean; // If true, when the tour stops, it will restore the initial scroll position of the page (default false) |
93 | 88 | }
|
94 | 89 | ```
|
95 | 90 |
|
96 |
| -* `keyboardNavigation?<Object>`: if you want to enable keyboard navigation, use this attribute. each attribute can be number, string or object. |
97 |
| - If you want to disable the keyboard navigation, just set this option to `false`. |
98 |
| - |
99 |
| - * number - used as `keyCode` : [DEPRECATED](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode) |
100 |
| - * string - used as `key` |
101 |
| - * object - All KeyboardEvent attribute is accepted including `keyCode`, `altKey`, `metaKey`, `ctrlKey` and etc. |
102 |
| - View This doc for more details about the KeyboardEvent: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent |
103 |
| - The defaults are: |
104 |
| - ```json |
105 |
| - { |
106 |
| - "next": "ArrowRight", |
107 |
| - "prev": "ArrowLeft", |
108 |
| - "first": "Home", |
109 |
| - "last": "End", |
110 |
| - "complete": null, |
111 |
| - "stop": "Escape" |
112 |
| - } |
113 |
| - ``` |
114 |
| -* `request?<Object>`: if you want to load the tour from a remote URL you may provide request headers here |
115 |
| -Defaults are: |
116 |
| -``` |
117 |
| -{ |
118 |
| - options: { |
119 |
| - mode: "cors", |
120 |
| - cache: "no-cache", |
121 |
| - }, |
122 |
| - headers: { |
123 |
| - "Content-Type": "application/json", |
124 |
| - }, |
125 |
| -} |
126 |
| -``` |
127 |
| -* `actionHandlers?<Array<ActionHandler>>`: optional array of custom step action handlers (see **Handling tour actions** for details) |
128 |
| -* `contentDecorators?<Array<ContentDecorator>>`: optional array of custom step decoration handlers (see **Content decorators** for details) |
129 |
| -* `onStart?<Function>`: callback function triggered when the tour starts |
130 |
| -* `onStop?<Function>`: callback function triggered when tour stops |
131 |
| -* `onComplete?<Function>`: callback triggered when tour completes |
132 |
| -* `onStep?<Function>`: callback triggered when a tour step is shown |
133 |
| - |
134 | 91 | Once instantiated you can use tourguide instance a several different ways:
|
135 | 92 |
|
136 | 93 | ### Content based approach
|
@@ -195,31 +152,9 @@ tourguide.start();
|
195 | 152 |
|
196 | 153 | About step details, See [Step](#Step) section.
|
197 | 154 |
|
198 |
| -### Step |
199 |
| - |
200 |
| -* `selector?<string>`: [CSS selector](https://www.w3schools.com/cssref/css_selectors.asp) used to find the target element *(used on JSON based approach and Remote URL approach)* |
201 |
| -* `step?<number>`: tour step sequence number (when using JSON as data source this property may be omitted) |
202 |
| -* `title<string>`: tour step title |
203 |
| -* `content<string>`: write the content |
204 |
| -Both `title` and `content` support [markdown](https://en.wikipedia.org/wiki/Markdown) language and content decorators (see Content decorators for details) |
205 |
| -* `image?<url>`: tour step illustration |
206 |
| -* `width?<number>`: step width in pixels (computed automatically by default) |
207 |
| -* `height?<number>`: step height in pixels (computed automatically by default) |
208 |
| -* `layout?<enum>`: this property can be `horizontal` or `vertical` and causes the tour step to be oriented horizontally or vertically (the default is `vertical`, works only when `image` is defined) |
209 |
| -* `placement?<enum>`: optional hint on where to place a tour step in relation to the step target; may be one of the following: |
210 |
| - * top-start |
211 |
| - * top |
212 |
| - * top-end |
213 |
| - * left |
214 |
| - * right |
215 |
| - * bottom-start |
216 |
| - * bottom |
217 |
| - * bottom-end |
218 |
| -* `overlay?<boolean>`: when set to `false` - hides step overlay (the default is `true`) |
219 |
| -* `navigation?<boolean>`: when set to `false` - hides step control buttons (the default is `true`) |
220 |
| -* `actions<Action>`: an array of step actions to be rendered in step footer (see **Handling tour actions** for details) |
221 |
| - |
222 |
| -> **?*** indicates the property is optional* |
| 155 | +### Step Class Constructor |
| 156 | + |
| 157 | +The **Tourguide.js** library includes two default steps: `PopoverStep` and `CardStep`. Here is the code for these steps: |
223 | 158 |
|
224 | 159 | ## Content decorators
|
225 | 160 |
|
@@ -402,75 +337,25 @@ Causes tour to go to the step specified
|
402 | 337 | ```
|
403 | 338 | tourguide.go(2)
|
404 | 339 | ```
|
405 |
| -### Additional properties |
406 |
| - |
407 |
| -* `tourguide.currentstep`: returns the current [step object](#step_object) |
408 |
| - |
409 |
| -* `tourguide.length`: return the number of steps on the tour |
410 |
| - |
411 |
| -* `tourguide.steps`: returns the tour steps as JSON notation |
412 |
| - |
413 |
| -* `tourguide.hasnext`: return true if there are steps remaining in the tour, otherwise returns false |
414 |
| - |
415 |
| -* `tourguide.options`: returns **Tourguide.js** options object |
416 | 340 |
|
417 | 341 | ## Attaching callbacks
|
418 | 342 |
|
419 | 343 | **Tourguide.js** supports several helpful [callbacks](https://developer.mozilla.org/en-US/docs/Glossary/Callback_function) to help you better control the tour. You may optionally pass the callback functions into the tour instance at initialization time:
|
420 | 344 |
|
421 | 345 | ```
|
422 |
| -var tourguide = new Tourguide({ |
423 |
| - `onStart:function(options){...},` |
424 |
| - `onStop:function(options){...},` |
425 |
| - `onComplete:function(){...},` |
426 |
| - `onStep:function(currentstep, type){...},` |
427 |
| -}); |
| 346 | +var tourguide = new Tourguide({...}); |
| 347 | +tourguide.addEventListener('start', function(options){...}); |
428 | 348 | ```
|
429 |
| -### onStart |
430 |
| - |
431 |
| -Fires when the guided tour is started. The callback function will receive a single param: |
432 |
| - |
433 |
| -* `options`: tour options object |
434 |
| - |
435 |
| -### onStop |
| 349 | +### Available events: |
| 350 | +* start - Fires when the guided tour is started. |
| 351 | +* stop - Fires when the guided tour stops. |
| 352 | +* complete - Fires when the guided tour is complete. |
| 353 | +* step - Fires when tour step is activated. |
| 354 | +* action - Fires when an action is triggered (next/previous/go/custom). |
436 | 355 |
|
437 |
| -Fires when the guided tour stops. The callback function will receive a single param: |
| 356 | +## Detailed documentation: |
| 357 | +For more detailed documentation, please refer to the [documentation markdown file located at /docs/README.md](https://github.com/LikaloLLC/tourguide.js/docs/README.md). |
438 | 358 |
|
439 |
| -* `options`: tour options object |
440 |
| - |
441 |
| -### onComplete |
442 |
| - |
443 |
| -Fires when the guided tour is complete. The callback function will receives no params. |
444 |
| - |
445 |
| -> NOTE: onStop is always fired first, before onComplete is fired |
446 |
| -
|
447 |
| -### onStep |
448 |
| - |
449 |
| -Fires when tour step is activated. The callback function receives two params: |
450 |
| - |
451 |
| -* `currentstep`: tour [step object](#step_object) |
452 |
| - |
453 |
| -* `type`: string representing the current direction of the tor; can be one of: "previous" | "next" |
454 |
| - |
455 |
| -## Step object |
456 |
| - |
457 |
| -Each step of the tour is wrapped into a Step class. This allows you to have a direct access to the individual step properties and actions: |
458 |
| - |
459 |
| -* `target`: returns the target element step is attached to |
460 |
| - |
461 |
| -* `el`: returns the step view element |
462 |
| - |
463 |
| -* `show()`: show step element |
464 |
| - |
465 |
| -* `hide()`: hide step element |
466 |
| - |
467 |
| -You can obtain the current step object an any time during the tour execution by calling `tourguide.currentstep` property: |
468 |
| - |
469 |
| -``` |
470 |
| -var currentstep = tourguide.currentstep; |
471 |
| -var stepTarget = currentstep.target; |
472 |
| -var stepView = currentstep.el; |
473 |
| -``` |
474 | 359 | ## License
|
475 | 360 |
|
476 | 361 | **Tourguide.js** is licensed under BSD 3-Clause "New" or "Revised" License
|
|
0 commit comments