kamrify commited on
Commit
671fd9e
·
2 Parent(s): a52a695 db6f192

Merge branch 'master' of github.com:kamranahmedse/driver.js

Browse files
Files changed (1) hide show
  1. readme.md +223 -6
readme.md CHANGED
@@ -1,11 +1,11 @@
1
  <h1 align="center"><img src="./demo/images/driver.png" /><br> Driver.js</h1>
2
 
3
  <p align="center">
4
- <a href="https://creativecommons.org/licenses/by/4.0/">
5
- <img src="https://img.shields.io/badge/License-CC%20BY%204.0-lightgrey.svg" />
6
  </a>
7
- <a href="http://makeapullrequest.com">
8
- <img src="https://img.shields.io/badge/contributions-welcome-green.svg" />
9
  </a>
10
  <a href="http://twitter.com/kamranahmedse">
11
  <img src="https://img.shields.io/badge/author-kamranahmedse-blue.svg" />
@@ -23,7 +23,7 @@
23
  * **Light-weight**: ~4kb in size, vanilla JavaScript and no external dependency
24
  * **Highly customizable**: has a powerful API and can be used however you want
25
  * **Highlight anything**: highlight any (literally any) element on page
26
- * **Feature introductions**: create powerful feature introductions and onboarding strategies
27
  * **Focus shifters**: add focus shifters for users
28
  * **User friendly**: Everything is controllable by keyboard
29
  * **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
47
  ```html
48
  <link rel="stylesheet" href="/dist/driver.min.css">
49
  <script src="/dist/driver.min.js"></script>
50
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <h1 align="center"><img src="./demo/images/driver.png" /><br> Driver.js</h1>
2
 
3
  <p align="center">
4
+ <a href="https://github.com/kamranahmedse/driver.js/blob/master/license">
5
+ <img src="https://img.shields.io/github/license/kamranahmedse/driver.js.svg" />
6
  </a>
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" />
 
23
  * **Light-weight**: ~4kb in size, vanilla JavaScript and no external dependency
24
  * **Highly customizable**: has a powerful API and can be used however you want
25
  * **Highlight anything**: highlight any (literally any) element on page
26
+ * **Feature introductions**: create powerful feature introductions for your web applications
27
  * **Focus shifters**: add focus shifters for users
28
  * **User friendly**: Everything is controllable by keyboard
29
  * **Consistent behavior**: usable across all browsers (including in-famous IE)
 
47
  ```html
48
  <link rel="stylesheet" href="/dist/driver.min.css">
49
  <script src="/dist/driver.min.js"></script>
50
+ ```
51
+
52
+ ![](./demo/images/split.png)
53
+
54
+ ## Usage and Demo
55
+
56
+ Demos and many more usage examples can be found [through the docs page](http://kamranahmed.info/driver).
57
+
58
+ ### Highlighting Single Element – [Demo](http://kamranahmed.info/driver#single-element-no-popover)
59
+
60
+ If all you want is just highlight a single element, you can do that simply by passing the selector
61
+
62
+ ```javascript
63
+ const driver = new Driver();
64
+ driver.highlight('#create-post');
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
71
+
72
+ ```javascript
73
+ const driver = new Driver();
74
+ driver.highlight({
75
+ element: '#some-element',
76
+ popover: {
77
+ title: 'Title for the Popover',
78
+ description: 'Description for it',
79
+ }
80
+ });
81
+ ```
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
88
+
89
+ ```javascript
90
+ const driver = new Driver();
91
+ driver.highlight({
92
+ element: '#some-element',
93
+ popover: {
94
+ title: 'Title for the Popover',
95
+ description: 'Description for it',
96
+ position: 'left', // can be `top`, `left`, `right`, `bottom`
97
+ }
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.
104
+
105
+ ```javascript
106
+ const driver = new Driver();
107
+
108
+ // Define the steps for introduction
109
+ driver.defineSteps([
110
+ {
111
+ element: '#first-element-introduction',
112
+ popover: {
113
+ title: 'Title on Popover',
114
+ description: 'Body of the popover',
115
+ position: 'left'
116
+ }
117
+ },
118
+ {
119
+ element: '#second-element-introduction',
120
+ popover: {
121
+ title: 'Title on Popover',
122
+ description: 'Body of the popover',
123
+ position: 'top'
124
+ }
125
+ },
126
+ {
127
+ element: '#third-element-introduction',
128
+ popover: {
129
+ title: 'Title on Popover',
130
+ description: 'Body of the popover',
131
+ position: 'right'
132
+ }
133
+ },
134
+ ]);
135
+
136
+ // Start the introduction
137
+ driver.start();
138
+ ```
139
+ You can also hide the buttons and control the introductions programmatically by using the API methods listed below
140
+
141
+ ![](./demo/images/split.png)
142
+
143
+ ## API
144
+
145
+ Driver comes with several options that you can manipulate to make driver behave as you may like
146
+
147
+ ### Driver Definition
148
+
149
+ Here are the options that Driver understands
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
+
162
+ ### Step Definition
163
+
164
+ Here are the set of options that you can pass while defining steps `defineSteps` or the object that you pass to `highlight` method
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
203
+
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
+ ```
244
+
245
+ ![](./demo/images/split.png)
246
+
247
+ ## Todo
248
+
249
+ - [X] Single elment highlighting
250
+ - [X] Popovers on the highlighted elements
251
+ - [X] Add smooth transition on changing highlighted elements
252
+ - [X] Multi-step Journey Definitions
253
+ - [X] Make it controllable by keyboard
254
+ - [X] Bring highlighted element to viewport
255
+ - [ ] Add type definitions
256
+ - [ ] Create wrappers for Angular and React
257
+ - [ ] Write tests
258
+
259
+ ## Contributions
260
+
261
+ Feel free to submit pull requests, create issues or spread the word
262
+
263
+ ## License
264
+
265
+ MIT &copy; [Kamran Ahmed](https://twitter.com/kamranahmedse)
266
+
267
+