kamrify commited on
Commit
a63a502
·
1 Parent(s): 97eb6a7

Move constants to separate file

Browse files
assets/scripts/src/constants.js ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export const OVERLAY_OPACITY = 0.75;
2
+ export const OVERLAY_PADDING = 10;
3
+ export const OVERLAY_ANIMATE = true;
4
+ export const OVERLAY_ZINDEX = '999999999';
5
+
6
+ export const ESC_KEYCODE = 27;
7
+
8
+ export const ID_POPOVER = 'sholo-popover-item';
9
+ export const ID_OVERLAY = 'sholo-canvas-overlay';
10
+
11
+ export const CLASS_POPOVER_TIP = 'sholo-popover-tip';
12
+ export const CLASS_NEXT_STEP_BTN = 'sholo-next-btn';
13
+ export const CLASS_PREV_STEP_BTN = 'sholo-prev-btn';
14
+ export const CLASS_CLOSE_BTN = 'sholo-close-btn';
assets/scripts/src/overlay.js CHANGED
@@ -1,4 +1,5 @@
1
  import Position from './position';
 
2
 
3
  /**
4
  * Responsible for overlay creation and manipulation i.e.
@@ -13,9 +14,9 @@ export default class Overlay {
13
  * @param document
14
  */
15
  constructor({
16
- opacity = 0.75,
17
- padding = 10,
18
- animate = true,
19
  }, window, document) {
20
  this.opacity = opacity; // Fixed opacity for the layover
21
  this.padding = padding; // Padding around the highlighted item
@@ -42,7 +43,7 @@ export default class Overlay {
42
  */
43
  resetOverlay() {
44
  // Check and remove the canvas if it already exists
45
- const canvasOverlay = this.document.getElementById('sholo-canvas-overlay');
46
  if (canvasOverlay && canvasOverlay.parentNode) {
47
  canvasOverlay.parentNode.removeChild(canvasOverlay);
48
  }
@@ -52,13 +53,13 @@ export default class Overlay {
52
  this.overlay = overlay;
53
  this.context = overlay.getContext('2d');
54
 
55
- this.overlay.id = 'sholo-canvas-overlay';
56
  this.overlay.style.pointerEvents = 'none';
57
  this.overlay.style.background = 'transparent';
58
  this.overlay.style.position = 'fixed';
59
  this.overlay.style.top = '0';
60
  this.overlay.style.left = '0';
61
- this.overlay.style.zIndex = '999999999';
62
  }
63
 
64
  /**
 
1
  import Position from './position';
2
+ import { ID_OVERLAY, OVERLAY_ANIMATE, OVERLAY_OPACITY, OVERLAY_PADDING, OVERLAY_ZINDEX } from './constants';
3
 
4
  /**
5
  * Responsible for overlay creation and manipulation i.e.
 
14
  * @param document
15
  */
16
  constructor({
17
+ opacity = OVERLAY_OPACITY,
18
+ padding = OVERLAY_PADDING,
19
+ animate = OVERLAY_ANIMATE,
20
  }, window, document) {
21
  this.opacity = opacity; // Fixed opacity for the layover
22
  this.padding = padding; // Padding around the highlighted item
 
43
  */
44
  resetOverlay() {
45
  // Check and remove the canvas if it already exists
46
+ const canvasOverlay = this.document.getElementById(ID_OVERLAY);
47
  if (canvasOverlay && canvasOverlay.parentNode) {
48
  canvasOverlay.parentNode.removeChild(canvasOverlay);
49
  }
 
53
  this.overlay = overlay;
54
  this.context = overlay.getContext('2d');
55
 
56
+ this.overlay.id = ID_OVERLAY;
57
  this.overlay.style.pointerEvents = 'none';
58
  this.overlay.style.background = 'transparent';
59
  this.overlay.style.position = 'fixed';
60
  this.overlay.style.top = '0';
61
  this.overlay.style.left = '0';
62
+ this.overlay.style.zIndex = OVERLAY_ZINDEX;
63
  }
64
 
65
  /**
assets/scripts/src/popover.js CHANGED
@@ -1,8 +1,9 @@
 
 
 
1
  /**
2
  * Popover that is displayed on top of the highlighted element
3
  */
4
- import Element from './element';
5
-
6
  export default class Popover extends Element {
7
  constructor(options = {
8
  padding: 10,
@@ -18,7 +19,7 @@ export default class Popover extends Element {
18
 
19
  getPopover() {
20
  // @todo: Create if not there
21
- const popover = this.document.getElementById('sholo-popover-item');
22
  popover.style.position = 'absolute';
23
 
24
  return popover;
@@ -41,14 +42,14 @@ export default class Popover extends Element {
41
 
42
  // Remove the positional classes from tip
43
  this.node
44
- .querySelector('.sholo-popover-tip')
45
- .className = 'sholo-popover-tip';
46
  }
47
 
48
  show(position) {
49
  this.reset();
50
 
51
- const popoverTip = this.node.querySelector('.sholo-popover-tip');
52
 
53
  const pageHeight = this.getFullPageSize().height;
54
  const popoverHeight = this.getHeight();
 
1
+ import Element from './element';
2
+ import { CLASS_POPOVER_TIP, ID_POPOVER } from './constants';
3
+
4
  /**
5
  * Popover that is displayed on top of the highlighted element
6
  */
 
 
7
  export default class Popover extends Element {
8
  constructor(options = {
9
  padding: 10,
 
19
 
20
  getPopover() {
21
  // @todo: Create if not there
22
+ const popover = this.document.getElementById(ID_POPOVER);
23
  popover.style.position = 'absolute';
24
 
25
  return popover;
 
42
 
43
  // Remove the positional classes from tip
44
  this.node
45
+ .querySelector(`.${CLASS_POPOVER_TIP}`)
46
+ .className = CLASS_POPOVER_TIP;
47
  }
48
 
49
  show(position) {
50
  this.reset();
51
 
52
+ const popoverTip = this.node.querySelector(`.${CLASS_POPOVER_TIP}`);
53
 
54
  const pageHeight = this.getFullPageSize().height;
55
  const popoverHeight = this.getHeight();
assets/scripts/src/sholo.js CHANGED
@@ -2,6 +2,7 @@ import Overlay from './overlay';
2
  import Element from './element';
3
  import './polyfill';
4
  import Popover from './popover';
 
5
 
6
  /**
7
  * Plugin class that drives the plugin
@@ -58,7 +59,7 @@ export default class Sholo {
58
  }
59
 
60
  const highlightedElement = this.overlay.getHighlightedElement();
61
- const popover = this.document.getElementById('sholo-popover-item');
62
 
63
  const clickedHighlightedElement = highlightedElement.node.contains(e.target);
64
  const clickedPopover = popover && popover.contains(e.target);
@@ -69,9 +70,9 @@ export default class Sholo {
69
  return;
70
  }
71
 
72
- const nextClicked = e.target.classList.contains('sholo-next-btn');
73
- const prevClicked = e.target.classList.contains('sholo-prev-btn');
74
- const closeClicked = e.target.classList.contains('sholo-close-btn');
75
 
76
  if (closeClicked) {
77
  this.reset();
@@ -152,7 +153,7 @@ export default class Sholo {
152
  * @param event
153
  */
154
  onKeyUp(event) {
155
- if (event.keyCode === 27) {
156
  this.overlay.clear();
157
  }
158
  }
 
2
  import Element from './element';
3
  import './polyfill';
4
  import Popover from './popover';
5
+ import { CLASS_CLOSE_BTN, CLASS_NEXT_STEP_BTN, CLASS_PREV_STEP_BTN, ESC_KEYCODE, ID_POPOVER } from './constants';
6
 
7
  /**
8
  * Plugin class that drives the plugin
 
59
  }
60
 
61
  const highlightedElement = this.overlay.getHighlightedElement();
62
+ const popover = this.document.getElementById(ID_POPOVER);
63
 
64
  const clickedHighlightedElement = highlightedElement.node.contains(e.target);
65
  const clickedPopover = popover && popover.contains(e.target);
 
70
  return;
71
  }
72
 
73
+ const nextClicked = e.target.classList.contains(CLASS_NEXT_STEP_BTN);
74
+ const prevClicked = e.target.classList.contains(CLASS_PREV_STEP_BTN);
75
+ const closeClicked = e.target.classList.contains(CLASS_CLOSE_BTN);
76
 
77
  if (closeClicked) {
78
  this.reset();
 
153
  * @param event
154
  */
155
  onKeyUp(event) {
156
+ if (event.keyCode === ESC_KEYCODE) {
157
  this.overlay.clear();
158
  }
159
  }