kamrify commited on
Commit
e5c37ad
·
1 Parent(s): cc0ef69

Make it controllable by arrow keys

Browse files
assets/scripts/src/constants.js CHANGED
@@ -4,6 +4,8 @@ export const OVERLAY_ANIMATE = true;
4
  export const OVERLAY_ZINDEX = '999999999';
5
 
6
  export const ESC_KEY_CODE = 27;
 
 
7
 
8
  export const ID_OVERLAY = 'sholo-canvas-overlay';
9
 
 
4
  export const OVERLAY_ZINDEX = '999999999';
5
 
6
  export const ESC_KEY_CODE = 27;
7
+ export const LEFT_KEY_CODE = 37;
8
+ export const RIGHT_KEY_CODE = 39;
9
 
10
  export const ID_OVERLAY = 'sholo-canvas-overlay';
11
 
assets/scripts/src/sholo.js CHANGED
@@ -7,10 +7,10 @@ import {
7
  CLASS_NEXT_STEP_BTN,
8
  CLASS_PREV_STEP_BTN,
9
  ESC_KEY_CODE,
10
- ID_POPOVER,
11
  OVERLAY_ANIMATE,
12
  OVERLAY_OPACITY,
13
- OVERLAY_PADDING,
14
  } from './constants';
15
 
16
  /**
@@ -121,6 +121,20 @@ export default class Sholo {
121
  }
122
  }
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  /**
125
  * Resets the steps if any and clears the overlay
126
  */
@@ -165,6 +179,10 @@ export default class Sholo {
165
  onKeyUp(event) {
166
  if (event.keyCode === ESC_KEY_CODE) {
167
  this.overlay.clear();
 
 
 
 
168
  }
169
  }
170
 
 
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 './constants';
15
 
16
  /**
 
121
  }
122
  }
123
 
124
+ /**
125
+ * @returns {boolean}
126
+ */
127
+ hasNextStep() {
128
+ return !!this.steps[this.currentStep + 1];
129
+ }
130
+
131
+ /**
132
+ * @returns {boolean}
133
+ */
134
+ hasPreviousStep() {
135
+ return !!this.steps[this.currentStep - 1];
136
+ }
137
+
138
  /**
139
  * Resets the steps if any and clears the overlay
140
  */
 
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()) {
185
+ this.movePrevious();
186
  }
187
  }
188