***Light-weight**: ~4kb in size, vanilla JavaScript and no external dependency
***Highly customizable**: has a powerful API and can be used however you want
***Highlight anything**: highlight any (literally any) element on page
***Feature introductions**: create powerful feature introductions and onboarding strategies
***Feature introductions**: create powerful feature introductions for your web applications
***Focus shifters**: add focus shifters for users
***User friendly**: Everything is controllable by keyboard
***Consistent behavior**: usable across all browsers (including in-famous IE)
...
...
@@ -47,4 +47,221 @@ Or grab the code from `dist` directory and include it directly
```html
<linkrel="stylesheet"href="/dist/driver.min.css">
<script src="/dist/driver.min.js"></script>
```
\ No newline at end of file
```
![](./demo/images/split.png)
## Usage and Demo
Demos and many more usage examples can be found [through the docs page](http://kamranahmed.info/driver).
### Highlighting Single Element – [Demo](http://kamranahmed.info/driver#single-element-no-popover)
If all you want is just highlight a single element, you can do that simply by passing the selector
```javascript
constdriver=newDriver();
driver.highlight('#create-post');
```
A real world usage example for this could be using it to dim the background and highlight the required element e.g. the way facebook does it on creating a post.
### Highlight and Popover – [Demo](http://kamranahmed.info/driver#single-element-with-popover)
You can show additional details beside the highlighted element using the popover
```javascript
constdriver=newDriver();
driver.highlight({
element:'#some-element',
popover:{
title:'Title for the Popover',
description:'Description for it',
}
});
```
Also, `title` and `description` can have HTML as well.
### Positioning the Popover – [Demo](http://kamranahmed.info/driver#single-element-with-popover-position)
By default, driver automatically finds the suitable position for the popover and displays it, you can override it using `position` property
```javascript
constdriver=newDriver();
driver.highlight({
element:'#some-element',
popover:{
title:'Title for the Popover',
description:'Description for it',
position:'left',// can be `top`, `left`, `right`, `bottom`
Feature introductions are helpful in onboarding new users and giving them idea about different parts of the application, you can create them seemlessly with driver. Define the steps and call the `start` when you want to start presenting. User will be able to control the steps using keyboard or using the buttons on popovers.
```javascript
constdriver=newDriver();
// Define the steps for introduction
driver.defineSteps([
{
element:'#first-element-introduction',
popover:{
title:'Title on Popover',
description:'Body of the popover',
position:'left'
}
},
{
element:'#second-element-introduction',
popover:{
title:'Title on Popover',
description:'Body of the popover',
position:'top'
}
},
{
element:'#third-element-introduction',
popover:{
title:'Title on Popover',
description:'Body of the popover',
position:'right'
}
},
]);
// Start the introduction
driver.start();
```
You can also hide the buttons and control the introductions programmatically by using the API methods listed below
![](./demo/images/split.png)
## API
Driver comes with several options that you can manipulate to make driver behave as you may like
### Driver Definition
Here are the options that Driver understands
```javascript
constdriver=newDriver({
animate:true,// Animate while changing highlighted element
opacity:0.75,// Background opacity (0 means only popovers and without overlay)
padding:10,// Distance of element from around the edges
onHighlightStarted:(Element){},// Called when element is about to be highlighted
onHighlighted:(Element){},// Called when element is fully highlighted
onDeselected:(Element){},// Called when element has been deselected
});
```
### Step Definition
Here are the set of options that you can pass while defining steps `defineSteps` or the object that you pass to `highlight` method
```javascript
conststepDefinition={
element:'#some-item',// Query selector for the item to be highlighted
popover:{// There will be no popover if empty or not given
title:'Title',// Title on the popover
description:'Description',// Body of the popover
showButtons:false,// Do not show control buttons in footer
doneBtnText:'Done',// Text on the last button
closeBtnText:'Close',// Text on the close button
nextBtnText:'Next',// Next button text
prevBtnText:'Previous',// Previous button text
}
};
```
For example, here is how it would look when highlighting a single element
```javascript
constdriver=newDriver(driverOptions);
driver.highlight(stepDefinition);
```
And this is how it would look when creating a step by step guide
```javascript
constdriver=newDriver(driverOptions);
driver.defineSteps([
stepDefinition1,
stepDefinition2,
stepDefinition3,
stepDefinition4,
]);
```
### API Methods
Below are the set of methods that are available to you
```javascript
constdriver=newDriver(driverOptions);
// Checks if the driver is active or not
if(driver.isActivated){
console.log('Driver is active');
}
// In case of the steps guide, you can call below methods