kamrify commited on
Commit
b69e467
·
1 Parent(s): 1de5288

Fix - Conflicts when having multiple drivers on page

Browse files
Files changed (1) hide show
  1. src/index.js +25 -5
src/index.js CHANGED
@@ -7,10 +7,12 @@ import {
7
  CLASS_NEXT_STEP_BTN,
8
  CLASS_PREV_STEP_BTN,
9
  ESC_KEY_CODE,
10
- ID_POPOVER, LEFT_KEY_CODE,
 
11
  OVERLAY_ANIMATE,
12
  OVERLAY_OPACITY,
13
- OVERLAY_PADDING, RIGHT_KEY_CODE,
 
14
  } from './common/constants';
15
 
16
  /**
@@ -30,6 +32,7 @@ export default class Sholo {
30
  this.document = document;
31
  this.window = window;
32
 
 
33
  this.overlay = new Overlay(this.options, this.window, this.document);
34
 
35
  this.steps = []; // steps to be presented if any
@@ -62,7 +65,7 @@ export default class Sholo {
62
  * @param e
63
  */
64
  onClick(e) {
65
- if (!this.hasHighlightedElement()) {
66
  // Has no highlighted element so ignore the click
67
  return;
68
  }
@@ -75,7 +78,7 @@ export default class Sholo {
75
 
76
  // Remove the overlay If clicked outside the highlighted element
77
  if (!clickedHighlightedElement && !clickedPopover) {
78
- this.overlay.clear();
79
  return;
80
  }
81
 
@@ -140,6 +143,7 @@ export default class Sholo {
140
  */
141
  reset() {
142
  this.currentStep = 0;
 
143
  this.steps = [];
144
  this.overlay.clear();
145
  }
@@ -159,6 +163,10 @@ export default class Sholo {
159
  * that the highlighted part travels with the scroll
160
  */
161
  onScroll() {
 
 
 
 
162
  this.overlay.refresh(false);
163
  }
164
 
@@ -168,6 +176,10 @@ export default class Sholo {
168
  * the highlighted part travels with the width change of window
169
  */
170
  onResize() {
 
 
 
 
171
  // Refresh with animation
172
  this.overlay.refresh(true);
173
  }
@@ -177,8 +189,12 @@ export default class Sholo {
177
  * @param event
178
  */
179
  onKeyUp(event) {
 
 
 
 
180
  if (event.keyCode === ESC_KEY_CODE) {
181
- this.overlay.clear();
182
  } else if (event.keyCode === RIGHT_KEY_CODE && this.hasNextStep()) {
183
  this.moveNext();
184
  } else if (event.keyCode === LEFT_KEY_CODE && this.hasPreviousStep()) {
@@ -261,6 +277,8 @@ export default class Sholo {
261
  throw new Error('There are no steps defined to iterate');
262
  }
263
 
 
 
264
  this.currentStep = index;
265
  this.overlay.highlight(this.steps[index]);
266
  }
@@ -270,6 +288,8 @@ export default class Sholo {
270
  * @param {string|{element: string, popover: {}}} selector Query selector or a step definition
271
  */
272
  highlight(selector) {
 
 
273
  const element = this.prepareElementFromStep(selector);
274
  if (!element) {
275
  return;
 
7
  CLASS_NEXT_STEP_BTN,
8
  CLASS_PREV_STEP_BTN,
9
  ESC_KEY_CODE,
10
+ ID_POPOVER,
11
+ LEFT_KEY_CODE,
12
  OVERLAY_ANIMATE,
13
  OVERLAY_OPACITY,
14
+ OVERLAY_PADDING,
15
+ RIGHT_KEY_CODE,
16
  } from './common/constants';
17
 
18
  /**
 
32
  this.document = document;
33
  this.window = window;
34
 
35
+ this.isActivated = false;
36
  this.overlay = new Overlay(this.options, this.window, this.document);
37
 
38
  this.steps = []; // steps to be presented if any
 
65
  * @param e
66
  */
67
  onClick(e) {
68
+ if (!this.hasHighlightedElement() || !this.isActivated) {
69
  // Has no highlighted element so ignore the click
70
  return;
71
  }
 
78
 
79
  // Remove the overlay If clicked outside the highlighted element
80
  if (!clickedHighlightedElement && !clickedPopover) {
81
+ this.reset();
82
  return;
83
  }
84
 
 
143
  */
144
  reset() {
145
  this.currentStep = 0;
146
+ this.isActivated = false;
147
  this.steps = [];
148
  this.overlay.clear();
149
  }
 
163
  * that the highlighted part travels with the scroll
164
  */
165
  onScroll() {
166
+ if (!this.isActivated) {
167
+ return;
168
+ }
169
+
170
  this.overlay.refresh(false);
171
  }
172
 
 
176
  * the highlighted part travels with the width change of window
177
  */
178
  onResize() {
179
+ if (!this.isActivated) {
180
+ return;
181
+ }
182
+
183
  // Refresh with animation
184
  this.overlay.refresh(true);
185
  }
 
189
  * @param event
190
  */
191
  onKeyUp(event) {
192
+ if (!this.isActivated) {
193
+ return;
194
+ }
195
+
196
  if (event.keyCode === ESC_KEY_CODE) {
197
+ this.reset();
198
  } else if (event.keyCode === RIGHT_KEY_CODE && this.hasNextStep()) {
199
  this.moveNext();
200
  } else if (event.keyCode === LEFT_KEY_CODE && this.hasPreviousStep()) {
 
277
  throw new Error('There are no steps defined to iterate');
278
  }
279
 
280
+ this.isActivated = true;
281
+
282
  this.currentStep = index;
283
  this.overlay.highlight(this.steps[index]);
284
  }
 
288
  * @param {string|{element: string, popover: {}}} selector Query selector or a step definition
289
  */
290
  highlight(selector) {
291
+ this.isActivated = true;
292
+
293
  const element = this.prepareElementFromStep(selector);
294
  if (!element) {
295
  return;