Run prettier on markdown
Browse files
readme.md
CHANGED
@@ -19,14 +19,14 @@
|
|
19 |
|
20 |
<br />
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |

|
32 |
|
@@ -46,16 +46,18 @@ You can install it using `yarn` or `npm`, whatever you prefer.
|
|
46 |
yarn add driver.js
|
47 |
npm install driver.js
|
48 |
```
|
|
|
49 |
Or include it using CDN. If you want a specific version, put it as `[email protected]` in the name
|
|
|
50 |
```html
|
51 |
<script src="https://unpkg.com/driver.js/dist/driver.min.js"></script>
|
52 |
-
<link rel="stylesheet" href="https://unpkg.com/driver.js/dist/driver.min.css"
|
53 |
```
|
54 |
|
55 |
Or grab the code from `dist` directory and include it directly.
|
56 |
|
57 |
```html
|
58 |
-
<link rel="stylesheet" href="/dist/driver.min.css"
|
59 |
<script src="/dist/driver.min.js"></script>
|
60 |
```
|
61 |
|
@@ -66,9 +68,10 @@ Or grab the code from `dist` directory and include it directly.
|
|
66 |
If you are using some sort of module bundler, import the library and the CSS file
|
67 |
|
68 |
```javascript
|
69 |
-
import Driver from
|
70 |
-
import
|
71 |
```
|
|
|
72 |
otherwise use the `script` and `link` tags to import the JavaScript and CSS files.
|
73 |
|
74 |
Demos and many more usage examples can be found [in the docs page](http://kamranahmed.info/driver.js).
|
@@ -79,8 +82,9 @@ You can highlight a single element by simply passing the selector.
|
|
79 |
|
80 |
```javascript
|
81 |
const driver = new Driver();
|
82 |
-
driver.highlight(
|
83 |
```
|
|
|
84 |
A real world usage example for this is: using it to dim the background and highlight the required element e.g. the way Facebook does it when creating a post.
|
85 |
|
86 |
### Highlight and Popover – [Demo](http://kamranahmed.info/driver.js#single-element-with-popover)
|
@@ -90,11 +94,11 @@ You can show additional details beside the highlighted element using the popover
|
|
90 |
```javascript
|
91 |
const driver = new Driver();
|
92 |
driver.highlight({
|
93 |
-
element:
|
94 |
popover: {
|
95 |
-
title:
|
96 |
-
description:
|
97 |
-
}
|
98 |
});
|
99 |
```
|
100 |
|
@@ -107,15 +111,15 @@ By default, driver automatically finds the suitable position for the popover and
|
|
107 |
```javascript
|
108 |
const driver = new Driver();
|
109 |
driver.highlight({
|
110 |
-
element:
|
111 |
popover: {
|
112 |
-
title:
|
113 |
-
description:
|
114 |
// position can be left, left-center, left-bottom, top,
|
115 |
// top-center, top-right, right, right-center, right-bottom,
|
116 |
// bottom, bottom-center, bottom-right, mid-center
|
117 |
-
position:
|
118 |
-
}
|
119 |
});
|
120 |
```
|
121 |
|
@@ -124,15 +128,15 @@ You can also add offset to the popover position by using the `offset` property
|
|
124 |
```javascript
|
125 |
const driver = new Driver();
|
126 |
driver.highlight({
|
127 |
-
element:
|
128 |
popover: {
|
129 |
-
title:
|
130 |
-
description:
|
131 |
-
position:
|
132 |
// Will show it 20 pixels away from the actual position of popover
|
133 |
// You may also provide the negative values
|
134 |
offset: 20,
|
135 |
-
}
|
136 |
});
|
137 |
```
|
138 |
|
@@ -146,35 +150,36 @@ const driver = new Driver();
|
|
146 |
// Define the steps for introduction
|
147 |
driver.defineSteps([
|
148 |
{
|
149 |
-
element:
|
150 |
popover: {
|
151 |
-
className:
|
152 |
-
title:
|
153 |
-
description:
|
154 |
-
position:
|
155 |
-
}
|
156 |
},
|
157 |
{
|
158 |
-
element:
|
159 |
popover: {
|
160 |
-
title:
|
161 |
-
description:
|
162 |
-
position:
|
163 |
-
}
|
164 |
},
|
165 |
{
|
166 |
-
element:
|
167 |
popover: {
|
168 |
-
title:
|
169 |
-
description:
|
170 |
-
position:
|
171 |
-
}
|
172 |
},
|
173 |
]);
|
174 |
|
175 |
// Start the introduction
|
176 |
driver.start();
|
177 |
```
|
|
|
178 |
You can also hide the buttons and control the introductions programmatically by using the API methods listed below.
|
179 |
|
180 |

|
@@ -189,44 +194,45 @@ const driver = new Driver();
|
|
189 |
// Define the steps for introduction
|
190 |
driver.defineSteps([
|
191 |
{
|
192 |
-
element:
|
193 |
popover: {
|
194 |
-
title:
|
195 |
-
description:
|
196 |
-
position:
|
197 |
-
}
|
198 |
},
|
199 |
{
|
200 |
-
element:
|
201 |
popover: {
|
202 |
-
title:
|
203 |
-
description:
|
204 |
-
position:
|
205 |
},
|
206 |
onNext: () => {
|
207 |
// Prevent moving to the next step
|
208 |
driver.preventMove();
|
209 |
-
|
210 |
// Perform some action or create the element to move to
|
211 |
// And then move to that element
|
212 |
setTimeout(() => {
|
213 |
driver.moveNext();
|
214 |
}, 4000);
|
215 |
-
}
|
216 |
},
|
217 |
{
|
218 |
-
element:
|
219 |
popover: {
|
220 |
-
title:
|
221 |
-
description:
|
222 |
-
position:
|
223 |
-
}
|
224 |
},
|
225 |
]);
|
226 |
|
227 |
// Start the introduction
|
228 |
driver.start();
|
229 |
```
|
|
|
230 |
You can also hide the buttons and control the introductions programmatically by using the API methods listed below.
|
231 |
|
232 |

|
@@ -241,28 +247,29 @@ Here are the options that Driver understands:
|
|
241 |
|
242 |
```javascript
|
243 |
const driver = new Driver({
|
244 |
-
className:
|
245 |
-
animate: true,
|
246 |
-
opacity: 0.75,
|
247 |
-
padding: 10,
|
248 |
-
allowClose: true,
|
249 |
-
overlayClickNext: false,
|
250 |
-
doneBtnText:
|
251 |
-
closeBtnText:
|
252 |
-
stageBackground:
|
253 |
-
nextBtnText:
|
254 |
-
prevBtnText:
|
255 |
-
showButtons: false,
|
256 |
-
keyboardControl: true,
|
257 |
-
scrollIntoViewOptions: {},
|
258 |
-
onHighlightStarted:
|
259 |
-
onHighlighted:
|
260 |
-
onDeselected:
|
261 |
-
onReset:
|
262 |
-
onNext:
|
263 |
-
onPrevious:
|
264 |
});
|
265 |
```
|
|
|
266 |
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
|
267 |
|
268 |
### Step Definition
|
@@ -271,20 +278,21 @@ Here are the set of options that you can pass while defining steps `defineSteps`
|
|
271 |
|
272 |
```javascript
|
273 |
const stepDefinition = {
|
274 |
-
element:
|
275 |
-
stageBackground:
|
276 |
-
popover: {
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
|
|
285 |
},
|
286 |
-
onNext: () => {},
|
287 |
-
onPrevious: () => {},
|
288 |
};
|
289 |
```
|
290 |
|
@@ -300,10 +308,10 @@ And this is how it would look when creating a step by step guide:
|
|
300 |
```javascript
|
301 |
const driver = new Driver(driverOptions);
|
302 |
driver.defineSteps([
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
]);
|
308 |
```
|
309 |
|
@@ -316,23 +324,23 @@ const driver = new Driver(driverOptions);
|
|
316 |
|
317 |
// Checks if the driver is active or not
|
318 |
if (driver.isActivated) {
|
319 |
-
|
320 |
}
|
321 |
|
322 |
// In case of the steps guide, you can call below methods
|
323 |
-
driver.defineSteps([
|
324 |
-
driver.start(stepNumber = 0);
|
325 |
-
driver.moveNext();
|
326 |
-
driver.movePrevious();
|
327 |
-
driver.hasNextStep();
|
328 |
-
driver.hasPreviousStep();
|
329 |
|
330 |
// Prevents the current move. Useful in `onNext` or `onPrevious` if you want to
|
331 |
// perform some asynchronous task and manually move to next step
|
332 |
driver.preventMove();
|
333 |
|
334 |
// Highlights the element using query selector or the step definition
|
335 |
-
driver.highlight(string|stepDefinition);
|
336 |
|
337 |
// Reposition the popover and highlighted element
|
338 |
driver.refresh();
|
@@ -344,11 +352,11 @@ driver.reset();
|
|
344 |
// to clear immediately and not do the animations etc
|
345 |
// Could be useful when you, let's say, want to run
|
346 |
// a different instance of driver while one was running
|
347 |
-
driver.reset(clearImmediately = false);
|
348 |
|
349 |
// Checks if there is any highlighted element
|
350 |
-
if(driver.hasHighlightedElement()) {
|
351 |
-
|
352 |
}
|
353 |
|
354 |
// Gets the currently highlighted element on screen
|
@@ -359,10 +367,10 @@ const activeElement = driver.getHighlightedElement();
|
|
359 |
const lastActiveElement = driver.getLastHighlightedElement();
|
360 |
|
361 |
activeElement.getCalculatedPosition(); // Gets screen co-ordinates of the active element
|
362 |
-
activeElement.hidePopover();
|
363 |
-
activeElement.showPopover();
|
364 |
|
365 |
-
activeElement.getNode();
|
366 |
```
|
367 |
|
368 |

|
@@ -384,5 +392,3 @@ Thanks to [BrowserStack](https://browserstack.com) for sponsoring the compatibil
|
|
384 |
## License
|
385 |
|
386 |
MIT © [Kamran Ahmed](https://twitter.com/kamranahmedse)
|
387 |
-
|
388 |
-
|
|
|
19 |
|
20 |
<br />
|
21 |
|
22 |
+
- **Simple**: is simple to use and has no external dependency at all
|
23 |
+
- **Highly customizable**: has a powerful API and can be used however you want
|
24 |
+
- **Highlight anything**: highlight any (literally any) element on page
|
25 |
+
- **Feature introductions**: create powerful feature introductions for your web applications
|
26 |
+
- **Focus shifters**: add focus shifters for users
|
27 |
+
- **User friendly**: Everything is controllable by keyboard
|
28 |
+
- **Consistent behavior**: usable across all browsers (including in-famous IE)
|
29 |
+
- **MIT Licensed**: free for personal and commercial use
|
30 |
|
31 |

|
32 |
|
|
|
46 |
yarn add driver.js
|
47 |
npm install driver.js
|
48 |
```
|
49 |
+
|
50 |
Or include it using CDN. If you want a specific version, put it as `[email protected]` in the name
|
51 |
+
|
52 |
```html
|
53 |
<script src="https://unpkg.com/driver.js/dist/driver.min.js"></script>
|
54 |
+
<link rel="stylesheet" href="https://unpkg.com/driver.js/dist/driver.min.css" />
|
55 |
```
|
56 |
|
57 |
Or grab the code from `dist` directory and include it directly.
|
58 |
|
59 |
```html
|
60 |
+
<link rel="stylesheet" href="/dist/driver.min.css" />
|
61 |
<script src="/dist/driver.min.js"></script>
|
62 |
```
|
63 |
|
|
|
68 |
If you are using some sort of module bundler, import the library and the CSS file
|
69 |
|
70 |
```javascript
|
71 |
+
import Driver from "driver.js";
|
72 |
+
import "driver.js/dist/driver.min.css";
|
73 |
```
|
74 |
+
|
75 |
otherwise use the `script` and `link` tags to import the JavaScript and CSS files.
|
76 |
|
77 |
Demos and many more usage examples can be found [in the docs page](http://kamranahmed.info/driver.js).
|
|
|
82 |
|
83 |
```javascript
|
84 |
const driver = new Driver();
|
85 |
+
driver.highlight("#create-post");
|
86 |
```
|
87 |
+
|
88 |
A real world usage example for this is: using it to dim the background and highlight the required element e.g. the way Facebook does it when creating a post.
|
89 |
|
90 |
### Highlight and Popover – [Demo](http://kamranahmed.info/driver.js#single-element-with-popover)
|
|
|
94 |
```javascript
|
95 |
const driver = new Driver();
|
96 |
driver.highlight({
|
97 |
+
element: "#some-element",
|
98 |
popover: {
|
99 |
+
title: "Title for the Popover",
|
100 |
+
description: "Description for it",
|
101 |
+
},
|
102 |
});
|
103 |
```
|
104 |
|
|
|
111 |
```javascript
|
112 |
const driver = new Driver();
|
113 |
driver.highlight({
|
114 |
+
element: "#some-element",
|
115 |
popover: {
|
116 |
+
title: "Title for the Popover",
|
117 |
+
description: "Description for it",
|
118 |
// position can be left, left-center, left-bottom, top,
|
119 |
// top-center, top-right, right, right-center, right-bottom,
|
120 |
// bottom, bottom-center, bottom-right, mid-center
|
121 |
+
position: "left",
|
122 |
+
},
|
123 |
});
|
124 |
```
|
125 |
|
|
|
128 |
```javascript
|
129 |
const driver = new Driver();
|
130 |
driver.highlight({
|
131 |
+
element: "#some-element",
|
132 |
popover: {
|
133 |
+
title: "Title for the Popover",
|
134 |
+
description: "Description for it",
|
135 |
+
position: "bottom",
|
136 |
// Will show it 20 pixels away from the actual position of popover
|
137 |
// You may also provide the negative values
|
138 |
offset: 20,
|
139 |
+
},
|
140 |
});
|
141 |
```
|
142 |
|
|
|
150 |
// Define the steps for introduction
|
151 |
driver.defineSteps([
|
152 |
{
|
153 |
+
element: "#first-element-introduction",
|
154 |
popover: {
|
155 |
+
className: "first-step-popover-class",
|
156 |
+
title: "Title on Popover",
|
157 |
+
description: "Body of the popover",
|
158 |
+
position: "left",
|
159 |
+
},
|
160 |
},
|
161 |
{
|
162 |
+
element: "#second-element-introduction",
|
163 |
popover: {
|
164 |
+
title: "Title on Popover",
|
165 |
+
description: "Body of the popover",
|
166 |
+
position: "top",
|
167 |
+
},
|
168 |
},
|
169 |
{
|
170 |
+
element: "#third-element-introduction",
|
171 |
popover: {
|
172 |
+
title: "Title on Popover",
|
173 |
+
description: "Body of the popover",
|
174 |
+
position: "right",
|
175 |
+
},
|
176 |
},
|
177 |
]);
|
178 |
|
179 |
// Start the introduction
|
180 |
driver.start();
|
181 |
```
|
182 |
+
|
183 |
You can also hide the buttons and control the introductions programmatically by using the API methods listed below.
|
184 |
|
185 |

|
|
|
194 |
// Define the steps for introduction
|
195 |
driver.defineSteps([
|
196 |
{
|
197 |
+
element: "#first-element-introduction",
|
198 |
popover: {
|
199 |
+
title: "Title on Popover",
|
200 |
+
description: "Body of the popover",
|
201 |
+
position: "left",
|
202 |
+
},
|
203 |
},
|
204 |
{
|
205 |
+
element: "#second-element-introduction",
|
206 |
popover: {
|
207 |
+
title: "Title on Popover",
|
208 |
+
description: "Body of the popover",
|
209 |
+
position: "top",
|
210 |
},
|
211 |
onNext: () => {
|
212 |
// Prevent moving to the next step
|
213 |
driver.preventMove();
|
214 |
+
|
215 |
// Perform some action or create the element to move to
|
216 |
// And then move to that element
|
217 |
setTimeout(() => {
|
218 |
driver.moveNext();
|
219 |
}, 4000);
|
220 |
+
},
|
221 |
},
|
222 |
{
|
223 |
+
element: "#third-element-introduction",
|
224 |
popover: {
|
225 |
+
title: "Title on Popover",
|
226 |
+
description: "Body of the popover",
|
227 |
+
position: "right",
|
228 |
+
},
|
229 |
},
|
230 |
]);
|
231 |
|
232 |
// Start the introduction
|
233 |
driver.start();
|
234 |
```
|
235 |
+
|
236 |
You can also hide the buttons and control the introductions programmatically by using the API methods listed below.
|
237 |
|
238 |

|
|
|
247 |
|
248 |
```javascript
|
249 |
const driver = new Driver({
|
250 |
+
className: "scoped-class", // className to wrap driver.js popover
|
251 |
+
animate: true, // Whether to animate or not
|
252 |
+
opacity: 0.75, // Background opacity (0 means only popovers and without overlay)
|
253 |
+
padding: 10, // Distance of element from around the edges
|
254 |
+
allowClose: true, // Whether the click on overlay should close or not
|
255 |
+
overlayClickNext: false, // Whether the click on overlay should move next
|
256 |
+
doneBtnText: "Done", // Text on the final button
|
257 |
+
closeBtnText: "Close", // Text on the close button for this step
|
258 |
+
stageBackground: "#ffffff", // Background color for the staged behind highlighted element
|
259 |
+
nextBtnText: "Next", // Next button text for this step
|
260 |
+
prevBtnText: "Previous", // Previous button text for this step
|
261 |
+
showButtons: false, // Do not show control buttons in footer
|
262 |
+
keyboardControl: true, // Allow controlling through keyboard (escape to close, arrow keys to move)
|
263 |
+
scrollIntoViewOptions: {}, // We use `scrollIntoView()` when possible, pass here the options for it if you want any
|
264 |
+
onHighlightStarted: Element => {}, // Called when element is about to be highlighted
|
265 |
+
onHighlighted: Element => {}, // Called when element is fully highlighted
|
266 |
+
onDeselected: Element => {}, // Called when element has been deselected
|
267 |
+
onReset: Element => {}, // Called when overlay is about to be cleared
|
268 |
+
onNext: Element => {}, // Called when moving to next step on any step
|
269 |
+
onPrevious: Element => {}, // Called when moving to previous step on any step
|
270 |
});
|
271 |
```
|
272 |
+
|
273 |
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
|
274 |
|
275 |
### Step Definition
|
|
|
278 |
|
279 |
```javascript
|
280 |
const stepDefinition = {
|
281 |
+
element: "#some-item", // Query selector string or Node to be highlighted
|
282 |
+
stageBackground: "#ffffff", // This will override the one set in driver
|
283 |
+
popover: {
|
284 |
+
// There will be no popover if empty or not given
|
285 |
+
className: "popover-class", // className to wrap this specific step popover in addition to the general className in Driver options
|
286 |
+
title: "Title", // Title on the popover
|
287 |
+
description: "Description", // Body of the popover
|
288 |
+
showButtons: false, // Do not show control buttons in footer
|
289 |
+
doneBtnText: "Done", // Text on the last button
|
290 |
+
closeBtnText: "Close", // Text on the close button
|
291 |
+
nextBtnText: "Next", // Next button text
|
292 |
+
prevBtnText: "Previous", // Previous button text
|
293 |
},
|
294 |
+
onNext: () => {}, // Called when moving to next step from current step
|
295 |
+
onPrevious: () => {}, // Called when moving to previous step from current step
|
296 |
};
|
297 |
```
|
298 |
|
|
|
308 |
```javascript
|
309 |
const driver = new Driver(driverOptions);
|
310 |
driver.defineSteps([
|
311 |
+
stepDefinition1,
|
312 |
+
stepDefinition2,
|
313 |
+
stepDefinition3,
|
314 |
+
stepDefinition4,
|
315 |
]);
|
316 |
```
|
317 |
|
|
|
324 |
|
325 |
// Checks if the driver is active or not
|
326 |
if (driver.isActivated) {
|
327 |
+
console.log("Driver is active");
|
328 |
}
|
329 |
|
330 |
// In case of the steps guide, you can call below methods
|
331 |
+
driver.defineSteps([stepDefinition1, stepDefinition2, stepDefinition3]);
|
332 |
+
driver.start((stepNumber = 0)); // Starts driving through the defined steps
|
333 |
+
driver.moveNext(); // Moves to next step in the steps list
|
334 |
+
driver.movePrevious(); // Moves to previous step in the steps list
|
335 |
+
driver.hasNextStep(); // Checks if there is next step to move to
|
336 |
+
driver.hasPreviousStep(); // Checks if there is previous step to move to
|
337 |
|
338 |
// Prevents the current move. Useful in `onNext` or `onPrevious` if you want to
|
339 |
// perform some asynchronous task and manually move to next step
|
340 |
driver.preventMove();
|
341 |
|
342 |
// Highlights the element using query selector or the step definition
|
343 |
+
driver.highlight(string | stepDefinition);
|
344 |
|
345 |
// Reposition the popover and highlighted element
|
346 |
driver.refresh();
|
|
|
352 |
// to clear immediately and not do the animations etc
|
353 |
// Could be useful when you, let's say, want to run
|
354 |
// a different instance of driver while one was running
|
355 |
+
driver.reset((clearImmediately = false));
|
356 |
|
357 |
// Checks if there is any highlighted element
|
358 |
+
if (driver.hasHighlightedElement()) {
|
359 |
+
console.log("There is an element highlighted");
|
360 |
}
|
361 |
|
362 |
// Gets the currently highlighted element on screen
|
|
|
367 |
const lastActiveElement = driver.getLastHighlightedElement();
|
368 |
|
369 |
activeElement.getCalculatedPosition(); // Gets screen co-ordinates of the active element
|
370 |
+
activeElement.hidePopover(); // Hide the popover
|
371 |
+
activeElement.showPopover(); // Show the popover
|
372 |
|
373 |
+
activeElement.getNode(); // Gets the DOM Element behind this element
|
374 |
```
|
375 |
|
376 |

|
|
|
392 |
## License
|
393 |
|
394 |
MIT © [Kamran Ahmed](https://twitter.com/kamranahmedse)
|
|
|
|