kamrify commited on
Commit
140aae9
·
1 Parent(s): f7ed62c

Add documentation and update type definitions

Browse files
Files changed (5) hide show
  1. index.html +14 -5
  2. readme.md +9 -5
  3. src/core/overlay.js +1 -1
  4. src/index.js +13 -19
  5. types/index.d.ts +21 -1
index.html CHANGED
@@ -186,7 +186,8 @@ driver.highlight({
186
  <p class="top-20">
187
  If you use this option, for multi-step driver, it would close after you are done with the popover or you can close it programmatically. For single element popover, you need to close it properly, otherwise it won't be closed
188
  </p>
189
- <pre><code class="javascript">driver.reset()</code></div>
 
190
 
191
  <hr class="hr__fancy">
192
  <div id="third-element-introduction" class="section__example">
@@ -283,6 +284,7 @@ driver.highlight({
283
  onHighlightStarted: (Element) {}, // Called when element is about to be highlighted
284
  onHighlighted: (Element) {}, // Called when element is fully highlighted
285
  onDeselected: (Element) {}, // Called when element has been deselected
 
286
  });
287
  </code></pre>
288
  </div>
@@ -369,10 +371,17 @@ activeElement.getNode(); // Gets the DOM Element behind this element
369
  <script src="./dist/demo/driver-demo.js"></script>
370
 
371
  <script>
372
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
373
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
374
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
375
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
 
 
 
 
 
 
 
376
  ga('create', 'UA-58155965-1', 'auto');
377
  ga('send', 'pageview');
378
  </script>
 
186
  <p class="top-20">
187
  If you use this option, for multi-step driver, it would close after you are done with the popover or you can close it programmatically. For single element popover, you need to close it properly, otherwise it won't be closed
188
  </p>
189
+ <pre><code class="javascript">driver.reset()</code>
190
+ </div>
191
 
192
  <hr class="hr__fancy">
193
  <div id="third-element-introduction" class="section__example">
 
284
  onHighlightStarted: (Element) {}, // Called when element is about to be highlighted
285
  onHighlighted: (Element) {}, // Called when element is fully highlighted
286
  onDeselected: (Element) {}, // Called when element has been deselected
287
+ onReset: (Element) {}, // Called when overlay is about to be cleared
288
  });
289
  </code></pre>
290
  </div>
 
371
  <script src="./dist/demo/driver-demo.js"></script>
372
 
373
  <script>
374
+ (function (i, s, o, g, r, a, m) {
375
+ i['GoogleAnalyticsObject'] = r;
376
+ i[r] = i[r] || function () {
377
+ (i[r].q = i[r].q || []).push(arguments);
378
+ }, i[r].l = 1 * new Date();
379
+ a = s.createElement(o),
380
+ m = s.getElementsByTagName(o)[0];
381
+ a.async = 1;
382
+ a.src = g;
383
+ m.parentNode.insertBefore(a, m);
384
+ })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
385
  ga('create', 'UA-58155965-1', 'auto');
386
  ga('send', 'pageview');
387
  </script>
readme.md CHANGED
@@ -171,10 +171,12 @@ const driver = new Driver({
171
  showButtons: false, // Do not show control buttons in footer
172
  keyboardControl: true, // Allow controlling through keyboard (escape to close, arrow keys to move)
173
  scrollIntoViewOptions: {}, // We use `scrollIntoView()` when possible, pass here the options for it if you want any
174
- onHighlightStarted: (Element) {}, // Called when element is about to be highlighted
175
- onHighlighted: (Element) {}, // Called when element is fully highlighted
176
- onDeselected: (Element) {}, // Called when element has been deselected
177
- onReset: () {}, // Called when overlay is about to be cleared
 
 
178
  });
179
  ```
180
  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
@@ -195,7 +197,9 @@ const stepDefinition = {
195
  closeBtnText: 'Close', // Text on the close button
196
  nextBtnText: 'Next', // Next button text
197
     prevBtnText: 'Previous', // Previous button text
198
- }
 
 
199
  };
200
  ```
201
 
 
171
  showButtons: false, // Do not show control buttons in footer
172
  keyboardControl: true, // Allow controlling through keyboard (escape to close, arrow keys to move)
173
  scrollIntoViewOptions: {}, // We use `scrollIntoView()` when possible, pass here the options for it if you want any
174
+ onHighlightStarted: (Element) => {}, // Called when element is about to be highlighted
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
 
197
  closeBtnText: 'Close', // Text on the close button
198
  nextBtnText: 'Next', // Next button text
199
     prevBtnText: 'Previous', // Previous button text
200
+ },
201
+ onNext: () => {}, // Called when moving to next step from current step
202
+ onPrevious: () => {}, // Called when moving to next step from current step
203
  };
204
  ```
205
 
src/core/overlay.js CHANGED
@@ -140,7 +140,7 @@ export default class Overlay {
140
  clear(immediate = false) {
141
  // Callback for when overlay is about to be reset
142
  if (this.options.onReset) {
143
- this.options.onReset();
144
  }
145
 
146
  // Deselect the highlighted element if any
 
140
  clear(immediate = false) {
141
  // Callback for when overlay is about to be reset
142
  if (this.options.onReset) {
143
+ this.options.onReset(this.highlightedElement);
144
  }
145
 
146
  // Deselect the highlighted element if any
src/index.js CHANGED
@@ -30,25 +30,19 @@ export default class Driver {
30
  constructor(options = {}) {
31
  this.options = {
32
  animate: SHOULD_ANIMATE_OVERLAY, // Whether to animate or not
33
- opacity: OVERLAY_OPACITY, // Overlay opacity
34
- padding: OVERLAY_PADDING, // Spacing around the element from the overlay
35
- scrollIntoViewOptions: null, // Options to be passed to `scrollIntoView`
36
- allowClose: SHOULD_OUTSIDE_CLICK_CLOSE, // Whether to close overlay on click outside the element
37
- keyboardControl: ALLOW_KEYBOARD_CONTROL, // Whether to allow controlling through keyboard or not
38
- overlayClickNext: SHOULD_OUTSIDE_CLICK_NEXT, // Whether to move next on click outside the element
39
- stageBackground: '#ffffff', // Background color for the stage
40
- onHighlightStarted: () => { // When element is about to be highlighted
41
- },
42
- onHighlighted: () => { // When element has been highlighted
43
- },
44
- onDeselected: () => { // When the element has been deselected
45
- },
46
- onReset: () => { // When overlay is about to be cleared
47
- },
48
- onNext: () => { // When next button is clicked
49
- },
50
- onPrevious: () => { // When previous button is clicked
51
- },
52
  ...options,
53
  };
54
 
 
30
  constructor(options = {}) {
31
  this.options = {
32
  animate: SHOULD_ANIMATE_OVERLAY, // Whether to animate or not
33
+ opacity: OVERLAY_OPACITY, // Overlay opacity
34
+ padding: OVERLAY_PADDING, // Spacing around the element from the overlay
35
+ scrollIntoViewOptions: null, // Options to be passed to `scrollIntoView`
36
+ allowClose: SHOULD_OUTSIDE_CLICK_CLOSE, // Whether to close overlay on click outside the element
37
+ keyboardControl: ALLOW_KEYBOARD_CONTROL, // Whether to allow controlling through keyboard or not
38
+ overlayClickNext: SHOULD_OUTSIDE_CLICK_NEXT, // Whether to move next on click outside the element
39
+ stageBackground: '#ffffff', // Background color for the stage
40
+ onHighlightStarted: () => null, // When element is about to be highlighted
41
+ onHighlighted: () => null, // When element has been highlighted
42
+ onDeselected: () => null, // When the element has been deselected
43
+ onReset: () => null, // When overlay is about to be cleared
44
+ onNext: () => null, // When next button is clicked
45
+ onPrevious: () => null, // When previous button is clicked
 
 
 
 
 
 
46
  ...options,
47
  };
48
 
types/index.d.ts CHANGED
@@ -150,6 +150,16 @@ declare module 'driver.js' {
150
  * Options representing popover for this step
151
  */
152
  popover?: Driver.PopoverOptions;
 
 
 
 
 
 
 
 
 
 
153
  }
154
 
155
  class Element {
@@ -717,7 +727,17 @@ declare module 'driver.js' {
717
  /**
718
  * Is called when the overlay is about to reset
719
  */
720
- onReset?: () => void,
 
 
 
 
 
 
 
 
 
 
721
  }
722
 
723
  interface ElementOptions extends Driver.DriverOptions {
 
150
  * Options representing popover for this step
151
  */
152
  popover?: Driver.PopoverOptions;
153
+
154
+ /**
155
+ * Is called when the next element is about to be highlighted
156
+ */
157
+ onNext?: () => void,
158
+
159
+ /**
160
+ * Is called when the previous element is about to be highlighted
161
+ */
162
+ onPrevious?: () => void,
163
  }
164
 
165
  class Element {
 
727
  /**
728
  * Is called when the overlay is about to reset
729
  */
730
+ onReset?: (element: Driver.Element) => void,
731
+
732
+ /**
733
+ * Is called when the next element is about to be highlighted
734
+ */
735
+ onNext?: () => void,
736
+
737
+ /**
738
+ * Is called when the previous element is about to be highlighted
739
+ */
740
+ onPrevious?: () => void,
741
  }
742
 
743
  interface ElementOptions extends Driver.DriverOptions {