Add docs in readme
Browse files
readme.md
CHANGED
@@ -7,9 +7,6 @@
|
|
7 |
<a href="https://npmjs.org/package/driver.js">
|
8 |
<img src="https://img.shields.io/npm/v/driver.js.svg" alt="version" />
|
9 |
</a>
|
10 |
-
<a href="http://makeapullrequest.com">
|
11 |
-
<img src="https://img.shields.io/badge/contributions-welcome-green.svg" />
|
12 |
-
</a>
|
13 |
<a href="http://twitter.com/kamranahmedse">
|
14 |
<img src="https://img.shields.io/badge/author-kamranahmedse-blue.svg" />
|
15 |
</a>
|
@@ -68,8 +65,6 @@ driver.highlight('#create-post');
|
|
68 |
```
|
69 |
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.
|
70 |
|
71 |
-

|
72 |
-
|
73 |
### Highlight and Popover – [Demo](http://kamranahmed.info/driver#single-element-with-popover)
|
74 |
|
75 |
You can show additional details beside the highlighted element using the popover
|
@@ -87,8 +82,6 @@ driver.highlight({
|
|
87 |
|
88 |
Also, `title` and `description` can have HTML as well.
|
89 |
|
90 |
-

|
91 |
-
|
92 |
### Positioning the Popover – [Demo](http://kamranahmed.info/driver#single-element-with-popover-position)
|
93 |
|
94 |
By default, driver automatically finds the suitable position for the popover and displays it, you can override it using `position` property
|
@@ -105,8 +98,6 @@ driver.highlight({
|
|
105 |
});
|
106 |
```
|
107 |
|
108 |
-

|
109 |
-
|
110 |
### Creating Feature Introductions – [Demo](http://kamranahmed.info/driver)
|
111 |
|
112 |
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.
|
@@ -149,7 +140,7 @@ You can also hide the buttons and control the introductions programmatically by
|
|
149 |
|
150 |

|
151 |
|
152 |
-
|
153 |
|
154 |
Driver comes with several options that you can manipulate to make driver behave as you may like
|
155 |
|
@@ -159,12 +150,12 @@ Here are the options that Driver understands
|
|
159 |
|
160 |
```javascript
|
161 |
const driver = new Driver({
|
162 |
-
animate: true,
|
163 |
-
opacity: 0.75,
|
164 |
-
padding: 10,
|
165 |
onHighlightStarted: (Element) {}, // Called when element is about to be highlighted
|
166 |
-
onHighlighted: (Element) {},
|
167 |
-
onDeselected: (Element) {},
|
168 |
});
|
169 |
```
|
170 |
|
@@ -174,19 +165,38 @@ Here are the set of options that you can pass while defining steps `defineSteps`
|
|
174 |
|
175 |
```javascript
|
176 |
const stepDefinition = {
|
177 |
-
element: '#some-item',
|
178 |
-
popover: {
|
179 |
-
title: 'Title',
|
180 |
description: 'Description', // Body of the popover
|
181 |
-
showButtons: false,
|
182 |
-
doneBtnText: 'Done',
|
183 |
-
closeBtnText: 'Close',
|
184 |
-
nextBtnText: 'Next',
|
185 |
-
|
186 |
}
|
187 |
};
|
188 |
```
|
189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
### API Methods
|
191 |
|
192 |
Below are the set of methods that are available to you
|
@@ -194,22 +204,40 @@ Below are the set of methods that are available to you
|
|
194 |
```javascript
|
195 |
const driver = new Driver(driverOptions);
|
196 |
|
197 |
-
|
198 |
-
driver.
|
199 |
-
|
|
|
|
|
|
|
|
|
200 |
driver.start(stepNumber = 0); // Starts driving through the defined steps
|
201 |
-
driver.
|
202 |
-
driver.
|
203 |
-
driver.
|
204 |
-
driver.
|
205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
|
207 |
// Gets the currently highlighted element on screen
|
|
|
208 |
const activeElement = driver.getHighlightedElement();
|
|
|
|
|
209 |
const lastActiveElement = driver.getLastHighlightedElement();
|
|
|
210 |
activeElement.getScreenCoordinates(); // Gets screen co-ordinates of the active element
|
211 |
-
activeElement.hidePopover();
|
212 |
-
activeElement.showPopover();
|
213 |
|
214 |
activeElement.getNode(); // Gets the DOM Element behind this element
|
215 |
```
|
|
|
7 |
<a href="https://npmjs.org/package/driver.js">
|
8 |
<img src="https://img.shields.io/npm/v/driver.js.svg" alt="version" />
|
9 |
</a>
|
|
|
|
|
|
|
10 |
<a href="http://twitter.com/kamranahmedse">
|
11 |
<img src="https://img.shields.io/badge/author-kamranahmedse-blue.svg" />
|
12 |
</a>
|
|
|
65 |
```
|
66 |
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.
|
67 |
|
|
|
|
|
68 |
### Highlight and Popover – [Demo](http://kamranahmed.info/driver#single-element-with-popover)
|
69 |
|
70 |
You can show additional details beside the highlighted element using the popover
|
|
|
82 |
|
83 |
Also, `title` and `description` can have HTML as well.
|
84 |
|
|
|
|
|
85 |
### Positioning the Popover – [Demo](http://kamranahmed.info/driver#single-element-with-popover-position)
|
86 |
|
87 |
By default, driver automatically finds the suitable position for the popover and displays it, you can override it using `position` property
|
|
|
98 |
});
|
99 |
```
|
100 |
|
|
|
|
|
101 |
### Creating Feature Introductions – [Demo](http://kamranahmed.info/driver)
|
102 |
|
103 |
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.
|
|
|
140 |
|
141 |

|
142 |
|
143 |
+
## API
|
144 |
|
145 |
Driver comes with several options that you can manipulate to make driver behave as you may like
|
146 |
|
|
|
150 |
|
151 |
```javascript
|
152 |
const driver = new Driver({
|
153 |
+
animate: true, // Animate while changing highlighted element
|
154 |
+
opacity: 0.75, // Background opacity (0 means only popovers and without overlay)
|
155 |
+
padding: 10, // Distance of element from around the edges
|
156 |
onHighlightStarted: (Element) {}, // Called when element is about to be highlighted
|
157 |
+
onHighlighted: (Element) {}, // Called when element is fully highlighted
|
158 |
+
onDeselected: (Element) {}, // Called when element has been deselected
|
159 |
});
|
160 |
```
|
161 |
|
|
|
165 |
|
166 |
```javascript
|
167 |
const stepDefinition = {
|
168 |
+
element: '#some-item', // Query selector for the item to be highlighted
|
169 |
+
popover: { // There will be no popover if empty or not given
|
170 |
+
title: 'Title', // Title on the popover
|
171 |
description: 'Description', // Body of the popover
|
172 |
+
showButtons: false, // Do not show control buttons in footer
|
173 |
+
doneBtnText: 'Done', // Text on the last button
|
174 |
+
closeBtnText: 'Close', // Text on the close button
|
175 |
+
nextBtnText: 'Next', // Next button text
|
176 |
+
prevBtnText: 'Previous', // Previous button text
|
177 |
}
|
178 |
};
|
179 |
```
|
180 |
|
181 |
+
For example, here is how it would look when highlighting a single element
|
182 |
+
|
183 |
+
```javascript
|
184 |
+
const driver = new Driver(driverOptions);
|
185 |
+
driver.highlight(stepDefinition);
|
186 |
+
```
|
187 |
+
|
188 |
+
And this is how it would look when creating a step by step guide
|
189 |
+
|
190 |
+
```javascript
|
191 |
+
const driver = new Driver(driverOptions);
|
192 |
+
driver.defineSteps([
|
193 |
+
stepDefinition1,
|
194 |
+
stepDefinition2,
|
195 |
+
stepDefinition3,
|
196 |
+
stepDefinition4,
|
197 |
+
]);
|
198 |
+
```
|
199 |
+
|
200 |
### API Methods
|
201 |
|
202 |
Below are the set of methods that are available to you
|
|
|
204 |
```javascript
|
205 |
const driver = new Driver(driverOptions);
|
206 |
|
207 |
+
// Checks if the driver is active or not
|
208 |
+
if (driver.isActivated) {
|
209 |
+
console.log('Driver is active');
|
210 |
+
}
|
211 |
+
|
212 |
+
// In case of the steps guide, you can call below methods
|
213 |
+
driver.defineSteps([ stepDefinition1, stepDefinition2, stepDefinition3 ]);
|
214 |
driver.start(stepNumber = 0); // Starts driving through the defined steps
|
215 |
+
driver.moveNext(); // Moves to next step in the steps list
|
216 |
+
driver.movePrevious(); // Moves to previous step in the steps list
|
217 |
+
driver.hasNextStep(); // Checks if there is next step to move to
|
218 |
+
driver.hasPreviousStep(); // Checks if there is previous step to move to
|
219 |
+
|
220 |
+
// Highlights the element using query selector or the step definition
|
221 |
+
driver.highlight(string|stepDefinition);
|
222 |
+
|
223 |
+
// Resets the overlay and clears the screen
|
224 |
+
driver.reset();
|
225 |
+
|
226 |
+
// Checks if there is any highlighted element
|
227 |
+
if(driver.hasHighlightedElement()) {
|
228 |
+
console.log('There is an element highlighted');
|
229 |
+
}
|
230 |
|
231 |
// Gets the currently highlighted element on screen
|
232 |
+
// It would be an instance of `/src/core/element.js`
|
233 |
const activeElement = driver.getHighlightedElement();
|
234 |
+
|
235 |
+
// Gets the last highlighted element, would be an instance of `/src/core/element.js`
|
236 |
const lastActiveElement = driver.getLastHighlightedElement();
|
237 |
+
|
238 |
activeElement.getScreenCoordinates(); // Gets screen co-ordinates of the active element
|
239 |
+
activeElement.hidePopover(); // Hide the popover
|
240 |
+
activeElement.showPopover(); // Show the popover
|
241 |
|
242 |
activeElement.getNode(); // Gets the DOM Element behind this element
|
243 |
```
|