Document the asyncronous usage
Browse files- index.html +4 -0
- readme.md +57 -14
index.html
CHANGED
|
@@ -324,6 +324,10 @@ driver.hasHighlightedElement(); // Checks if there is any highlighted element
|
|
| 324 |
driver.hasNextStep(); // Checks if there is next step to move to
|
| 325 |
driver.hasPreviousStep(); // Checks if there is previous step to move to
|
| 326 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
// Gets the currently highlighted element on screen
|
| 328 |
const activeElement = driver.getHighlightedElement();
|
| 329 |
const lastActiveElement = driver.getLastHighlightedElement();
|
|
|
|
| 324 |
driver.hasNextStep(); // Checks if there is next step to move to
|
| 325 |
driver.hasPreviousStep(); // Checks if there is previous step to move to
|
| 326 |
|
| 327 |
+
// Prevents the current move. Useful in `onNext` or `onPrevious` if you want to
|
| 328 |
+
// perform some asynchronous task and manually move to next step
|
| 329 |
+
driver.preventMove();
|
| 330 |
+
|
| 331 |
// Gets the currently highlighted element on screen
|
| 332 |
const activeElement = driver.getHighlightedElement();
|
| 333 |
const lastActiveElement = driver.getLastHighlightedElement();
|
readme.md
CHANGED
|
@@ -148,6 +148,57 @@ You can also hide the buttons and control the introductions programmatically by
|
|
| 148 |
|
| 149 |

|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
## API
|
| 152 |
|
| 153 |
Driver comes with several options that you can manipulate to make Driver behave as you like
|
|
@@ -175,8 +226,8 @@ const driver = new Driver({
|
|
| 175 |
onHighlighted: (Element) => {}, // Called when element is fully highlighted
|
| 176 |
onDeselected: (Element) => {}, // Called when element has been deselected
|
| 177 |
onReset: (Element) => {}, // Called when overlay is about to be cleared
|
| 178 |
-
onNext: () => {}, // Called when moving to next step on any step
|
| 179 |
-
onPrevious: () => {}, // Called when moving to next step on any step
|
| 180 |
});
|
| 181 |
```
|
| 182 |
Note that all the button options that you provide in the driver definition can be overridden for a specific step by giving them in the step definition
|
|
@@ -242,6 +293,10 @@ driver.movePrevious(); // Moves to previous step in the steps list
|
|
| 242 |
driver.hasNextStep(); // Checks if there is next step to move to
|
| 243 |
driver.hasPreviousStep(); // Checks if there is previous step to move to
|
| 244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
// Highlights the element using query selector or the step definition
|
| 246 |
driver.highlight(string|stepDefinition);
|
| 247 |
|
|
@@ -276,18 +331,6 @@ activeElement.getNode(); // Gets the DOM Element behind this element
|
|
| 276 |
|
| 277 |

|
| 278 |
|
| 279 |
-
## Todo
|
| 280 |
-
|
| 281 |
-
- [X] Single element highlighting
|
| 282 |
-
- [X] Popovers on the highlighted elements
|
| 283 |
-
- [X] Add smooth transition on changing highlighted elements
|
| 284 |
-
- [X] Multi-step Journey Definitions
|
| 285 |
-
- [X] Make it controllable by keyboard
|
| 286 |
-
- [X] Bring highlighted element to viewport
|
| 287 |
-
- [X] Add type definitions
|
| 288 |
-
- [ ] Create wrappers for Angular, Vue and React
|
| 289 |
-
- [ ] Write tests
|
| 290 |
-
|
| 291 |
## Contributions
|
| 292 |
|
| 293 |
Feel free to submit pull requests, create issues or spread the word.
|
|
|
|
| 148 |
|
| 149 |

|
| 150 |
|
| 151 |
+
### Asynchronous Actions – [Demo](http://kamranahmed.info/driver)
|
| 152 |
+
|
| 153 |
+
During the feature introductions, to delay the move to next step, you may handle that in `onNext` or `onPrevious` callbacks
|
| 154 |
+
|
| 155 |
+
```javascript
|
| 156 |
+
const driver = new Driver();
|
| 157 |
+
|
| 158 |
+
// Define the steps for introduction
|
| 159 |
+
driver.defineSteps([
|
| 160 |
+
{
|
| 161 |
+
element: '#first-element-introduction',
|
| 162 |
+
popover: {
|
| 163 |
+
title: 'Title on Popover',
|
| 164 |
+
description: 'Body of the popover',
|
| 165 |
+
position: 'left'
|
| 166 |
+
}
|
| 167 |
+
},
|
| 168 |
+
{
|
| 169 |
+
element: '#second-element-introduction',
|
| 170 |
+
popover: {
|
| 171 |
+
title: 'Title on Popover',
|
| 172 |
+
description: 'Body of the popover',
|
| 173 |
+
position: 'top'
|
| 174 |
+
},
|
| 175 |
+
onNext: () => {
|
| 176 |
+
// Do not move to the next step yet
|
| 177 |
+
driver.preventMove();
|
| 178 |
+
// Perform some action and manually call `moveNext`
|
| 179 |
+
someAction()
|
| 180 |
+
.then(() => {
|
| 181 |
+
driver.moveNext();
|
| 182 |
+
});
|
| 183 |
+
}
|
| 184 |
+
},
|
| 185 |
+
{
|
| 186 |
+
element: '#third-element-introduction',
|
| 187 |
+
popover: {
|
| 188 |
+
title: 'Title on Popover',
|
| 189 |
+
description: 'Body of the popover',
|
| 190 |
+
position: 'right'
|
| 191 |
+
}
|
| 192 |
+
},
|
| 193 |
+
]);
|
| 194 |
+
|
| 195 |
+
// Start the introduction
|
| 196 |
+
driver.start();
|
| 197 |
+
```
|
| 198 |
+
You can also hide the buttons and control the introductions programmatically by using the API methods listed below.
|
| 199 |
+
|
| 200 |
+

|
| 201 |
+
|
| 202 |
## API
|
| 203 |
|
| 204 |
Driver comes with several options that you can manipulate to make Driver behave as you like
|
|
|
|
| 226 |
onHighlighted: (Element) => {}, // Called when element is fully highlighted
|
| 227 |
onDeselected: (Element) => {}, // Called when element has been deselected
|
| 228 |
onReset: (Element) => {}, // Called when overlay is about to be cleared
|
| 229 |
+
onNext: (Element) => {}, // Called when moving to next step on any step
|
| 230 |
+
onPrevious: (Element) => {}, // Called when moving to next step on any step
|
| 231 |
});
|
| 232 |
```
|
| 233 |
Note that all the button options that you provide in the driver definition can be overridden for a specific step by giving them in the step definition
|
|
|
|
| 293 |
driver.hasNextStep(); // Checks if there is next step to move to
|
| 294 |
driver.hasPreviousStep(); // Checks if there is previous step to move to
|
| 295 |
|
| 296 |
+
// Prevents the current move. Useful in `onNext` or `onPrevious` if you want to
|
| 297 |
+
// perform some asynchronous task and manually move to next step
|
| 298 |
+
driver.preventMove();
|
| 299 |
+
|
| 300 |
// Highlights the element using query selector or the step definition
|
| 301 |
driver.highlight(string|stepDefinition);
|
| 302 |
|
|
|
|
| 331 |
|
| 332 |

|
| 333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
## Contributions
|
| 335 |
|
| 336 |
Feel free to submit pull requests, create issues or spread the word.
|